Files
Hermes-ui/packages/server
ekko 3e6c96a896 fix(session-sync): handle missing estimated_cost_usd column in old Hermes state.db (#312)
* fix(session-sync): handle missing estimated_cost_usd column in old Hermes state.db

Fixes #308 - "NOT NULL constraint failed: sessions.estimated_cost_usd"

Problem:
- Old versions of Hermes state.db don't have the estimated_cost_usd column
- Session sync would fail when trying to query this column
- New sessions also failed to sync because the error blocked the entire sync process

Solution:
- Dynamically detect if estimated_cost_usd column exists using PRAGMA table_info
- For old DBs (no column): return 0 as hardcoded default value
- For new DBs (has column): use COALESCE(estimated_cost_usd, 0) to handle NULL values
- This ensures backward compatibility with both old and new Hermes installations

Changes:
- Add PRAGMA table_info check before building SELECT query
- Conditionally include estimated_cost_usd column based on schema detection
- Ensures session sync works for both old and new Hermes state.db versions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: correct type annotation for PRAGMA table_info result

- Change from Array<{ name: string }>[] to Array<{ name: string }>
- Fixes TypeScript compilation error
- PRAGMA table_info returns an array of objects, not an array of arrays

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-29 21:03:51 +08:00
..