fix(gateway): /status reads token totals from SessionDB (regression of #1465) - #18207
Closed
teknium1 wants to merge 3 commits into
Closed
fix(gateway): /status reads token totals from SessionDB (regression of #1465)#18207teknium1 wants to merge 3 commits into
teknium1 wants to merge 3 commits into
Conversation
/status was reading session_entry.total_tokens which is never kept in sync after the token persistence refactor (commit 20441cf). Real token usage lives in SessionDB (SQLite). Read from SessionDB via the new get_session_token_totals() helper and fall back to session_entry.total_tokens when SessionDB is unavailable. Fixes #5960.
…DB totals test The test added in the salvage was calling a nonexistent set_token_counts() method. The real API is update_token_counts with absolute=True for direct writes. All 215 targeted tests pass.
Contributor
Author
|
Superseded by #17158 (@JezzaHehn), which landed as 7abc9ce on main while this salvage PR was being prepared. Same Camp A architecture (read from SQLite at display time, don't mirror into SessionStore). Closing with no harm done — the bug is fixed on main. |
Collaborator
Collaborator
|
Likely duplicate of #18206 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make
/statusread token totals from SQLite (the authoritative storerun_agent.pyalready writes per API call), soTokens:stops showing stale zeros after #1465 regressed.Salvaged from #5989 by @Tranquil-Flow. Closes #5960. Supersedes competing PRs #5989 #11088 #13820 #17158 (partial), #12565 (totals portion; the callback_generation snapshot bug in #12565 is a real but separate fix).
Architecture note
Two camps in the open PRs: (A) read from SQLite at display time, (B) mirror totals into SessionStore on every turn. (A) wins —
run_agent.pyalready writes to SQLite per API call (see L11502), SessionStore'stotal_tokensis vestigial (no production reader). Teaching/statusto read the authoritative store means no drift, no double bookkeeping, and naturally covers CLI/cron/delegated sessions too.Changes
hermes_state.py: addSessionDB.get_session_token_totals(session_id)returning{input, output, cache_read, cache_write, reasoning, total}orNone.gateway/run.py:_handle_status_commandprefers the SQLite totals, falls back tosession_entry.total_tokenson missing row or exception./statusprefers-SQLite and fallback-on-missing-row tests.set_token_counts(nonexistent) forupdate_token_counts(absolute=True)in one test.Validation
/statusmid-sessionsession_entry)session_entry.total_tokens(fallback)Targeted tests:
tests/gateway/test_status_command.py+tests/test_hermes_state.py— 215/215 passing.E2E verified with real SessionDB + real SQLite + real
_handle_status_command: two simulated API-callupdate_token_countsdeltas (150k in, 5k out, 1.7M cache-read, 150 cache-write, 1.5k reasoning) round-trip correctly viaget_session_token_totals, and/statusreports the cumulative 1,856,650 instead of the stalesession_entry.total_tokens=999.Credit