From 037c2881d88e2b52f2b66d5ae55cc703f02e4475 Mon Sep 17 00:00:00 2001 From: ekko <152005280+EKKOLearnAI@users.noreply.github.com> Date: Wed, 29 Apr 2026 21:25:58 +0800 Subject: [PATCH] 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 --- packages/server/src/services/hermes/session-sync.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/server/src/services/hermes/session-sync.ts b/packages/server/src/services/hermes/session-sync.ts index e3f8315..f262cbe 100644 --- a/packages/server/src/services/hermes/session-sync.ts +++ b/packages/server/src/services/hermes/session-sync.ts @@ -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, })