fix(session-sync): add type guard for estimated_cost_usd to prevent NOT NULL errors (#314)

Fixes remaining NOT NULL constraint failures after PR #312.

Problem:
- Even with COALESCE in SQL, some sessions still fail with NOT NULL error
- Hermes may return undefined/null/NaN values that pass through COALESCE

Solution:
- Add explicit type guard: `typeof value === 'number'`
- Only use the value if it's a valid number, otherwise default to 0
- This ensures we never pass undefined/null/NaN to the database

Related to issue #308
This commit is contained in:
ekko
2026-04-29 21:25:58 +08:00
committed by GitHub
parent f74cdd1256
commit 037c2881d8
@@ -215,6 +215,10 @@ function syncProfileSessions(profile: string): {
}
// Update session with Hermes data
const estimatedCost = typeof hermesSession.estimated_cost_usd === 'number'
? hermesSession.estimated_cost_usd
: 0
updateSession(newSessionId, {
started_at: hermesSession.started_at,
ended_at: hermesSession.ended_at,
@@ -224,7 +228,7 @@ function syncProfileSessions(profile: string): {
cache_read_tokens: hermesSession.cache_read_tokens,
cache_write_tokens: hermesSession.cache_write_tokens,
reasoning_tokens: hermesSession.reasoning_tokens,
estimated_cost_usd: hermesSession.estimated_cost_usd || 0,
estimated_cost_usd: estimatedCost,
last_active: hermesSession.started_at, // Use started_at as fallback since last_active doesn't exist in Hermes state.db
preview,
})