Repository navigation
fix(hermes): keep post-finalization session growth on the observation day - #1121
Conversation
… day Hermes rows are lifetime totals stamped at started_at. After a day is sealed, later growth was dropped. A sidecar ledger records last-seen totals per (profile, sessionId) and emits weight-0 observation-time deltas so sealed days stay put while today's growth still lands. Closes #916
Later observations with costBasis calculated were emitted as measured. Derive the estimate marker from the stored basis so LiteLLM-priced growth stays estimated, persist it through the session cache, and lock the path with a discover/parse/ledger fresh+warm regression.
|
Reviewed (DeepSeek draft; every finding re-verified against the diff by maintainer — two of the draft's findings were contradicted by the actual code and are NOT included here). Verified positives first: cost-increase-with-flat-tokens does emit an observation ( Two items to resolve:
|
state.db restore is out of contract and will overcount. Recovery starts from the warm-cache seed; historically dropped growth stays dropped.
|
Resolving both open questions (owner ruling): 1. Restores are out of contract. If 2. No cache bump on this PR — withdrawn, with the correct reasoning on record. A bump would not recover historical growth onto observation days: those intermediate snapshots never existed. It would re-emit current lifetime at With the doc line from (1), this is merge-ready from the review side. |
Owner ruling: state.db restored from backup without wiping the ledger re-credits regrowth. Wipe both stores or accept the overcount. A high-water-mark guard is rejected because it would eat 150→0→40 resets.
Summary
Hermes
state.dbrows are lifetime totals stamped atstarted_at. After CodeBurn seals day D, later growth on the same session was still keyed to that sealed day and dropped. This adds a sidecar ledger (hermes-session-ledger.v1.jsonunderCODEBURN_CACHE_DIR) that records last-seen lifetime totals per(profile, sessionId)and emits observation-time deltas.started_at, behavioral (weight 1), key unchanged (hermes:${profile}:${sessionId}).supplementaryAccounting: true(weight 0), key…:obs:n.> 0discovery filter): no observation, last-seen 0. 0 → 40 is one+40weight-0 observation.$0is recorded. Ledger publish is atomic; failure is retryable and holds the daily watermark.CACHE_VERSIONbump, no Hermes parse-version bump, no sealed-day rewrite, no last-activity re-anchor.Proof fixture: day D stays 100 input / $0.10 / 1 call / 1 session; the next observation records only +50 / +$0.05 with 0 calls and 0 sessions; lifetime is 150 / $0.15 while calls and turns stay 1.
Direction from ozymandiashh (2026-08-09 unpushed implementation notes).
Test plan
parseAllSessions+ensureCacheHydrated+aggregateProjectsIntoDayssessionIdindefaultandprofiles/coder— two cursors, no cross-profile deltadiscoverFromDb→ parser → ledger (not ledger-only)$0actual is recordednowlastComputedDatedoes not advancehermes:default:<id>tests/providers/hermes.test.ts+ day-aggregator + daily-cache degraded completenessCloses #916