fix(hermes): don't trust a $0 estimated cost — calculate from tokens - #1213
Conversation
Hermes writes estimated_cost_usd = 0.0 (not NULL) when cost_status is 'unknown' (no pricing data) or 'included' (flat subscription, e.g. Codex plan). resolveHermesCost treated any non-null estimate as a recorded amount, so every subscription-backed Hermes session reported $0.00 with real token counts underneath. Only trust positive estimates now; $0 falls through to the token-based calculateCost. An explicit $0 actual_cost_usd (a real invoice amount) still wins, and genuinely free models still land on $0 since litellm prices them at 0.
|
The |
…re-cost The cost rule changed, so sessions whose state.db fingerprint has not moved must be re-parsed or they keep serving the stale placeholder zero.
|
Reviewed in depth and merging. The fix is right, and the objection that a literal zero might be a genuine free-model zero does not hold in practice: free, local and flat-rate models calculate to zero anyway, API-equivalent pricing for subscription turns is the same convention every other provider uses, and docs/providers/hermes.md has said since the provider landed that only a positive recorded cost is trusted. Your new fixture test is genuine red/green (fails on main with expected 0 to be greater than 0). One thing patched on top: PROVIDER_PARSE_VERSIONS.hermes in src/session-cache.ts was not bumped, so sessions whose state.db fingerprint has not changed would have kept serving the cached zero; bumped it so they re-cost. tsc clean, hermes and session-cache suites green. |
Problem
Every Hermes session on a flat subscription (Codex plan, z.ai, Kimi) reports $0.00 in CodeBurn despite real token usage.
Root cause: Hermes writes
estimated_cost_usd = 0.0— not NULL — when itscost_statusis'unknown'(no pricing data) or'included'(flat subscription, per Hermes'susage_pricing.py: "subscription-included; no provider invoice for usage").resolveHermesCosttreats any non-null estimate as a recorded amount, so the placeholder $0 wins over the token-based calculation forever.I verified against a live
~/.hermes/state.db: 17 sessions with full token counts, allestimated_cost_usd = 0.0withcost_status'included'/'unknown'andcost_source = 'none'— no measurement happened.Fix
Only trust positive recorded estimates; $0 falls through to
calculateCost. Deliberately not keyed offcost_status: the> 0check also covers DBs from before the column existed, and matches the columns CodeBurn already reads.Semantics preserved:
actual_cost_usdnon-null still wins — including explicit $0 (a real invoice amount is fact)The ledger's cost-delta path makes existing sessions self-heal: on the next scan, calculated cost > lastSeen $0 emits a cost-only correction observation.
Tests
tests/hermes-cost-fallback.test.ts: zero-estimate → calculated, positive estimate → trusted, zero actual → $0