Bug Description
/status can still show Tokens: 0 even when the current gateway session has substantial token usage recorded in SQLite.
This appears to be a regression of the symptom fixed in #1465 / PR #1476, but with a changed root cause.
Steps to Reproduce
- Run Hermes through the gateway (Telegram in my case).
- Have a longer conversation so the session clearly accumulates token usage.
- Send
/status.
- Inspect the same session in both persistence layers.
Expected Behavior
/status should report the real token usage for the current session.
Actual Behavior
/status reports Tokens: 0 even though the same session has non-zero token usage in state.db.
Evidence
In my reproduction, the same session ID had:
sessions.json / SessionEntry.total_tokens = 0
state.db token fields populated with large non-zero values
Example from one affected session:
- session_id:
20260407_170736_30bcaff2
sessions.json total_tokens = 0
state.db input_tokens = 171876
state.db output_tokens = 7295
state.db cache_read_tokens = 1517184
state.db reasoning_tokens = 2648
Regression History
Issue #1465 was fixed by PR #1476 (fix(gateway): make /status report live state and tokens).
That fix explicitly threaded input_tokens / output_tokens from gateway/run.py into session_store.update_session(...), and added regression coverage in tests/gateway/test_status_command.py.
A later refactor appears to have reintroduced the visible bug:
- commit
20441cf2 (fix(insights): persist token usage for non-CLI sessions)
gateway/run.py stopped passing token counts into session_store.update_session(...)
gateway/session.py::update_session() was reduced to only updating lightweight metadata like last_prompt_tokens
- the previous regression test assertion was also weakened so it no longer verifies token propagation into
SessionStore
Root Cause Analysis
Current behavior looks like this:
- real token usage is persisted directly into SQLite /
state.db
/status still reads session_entry.total_tokens
session_entry.total_tokens comes from SessionStore / sessions.json
- that field is no longer kept in sync with the real token counts
So the symptom is a regression, but the root cause has changed:
Affected Component
Gateway
Messaging Platform (if gateway-related)
Telegram
Operating System
Ubuntu 24.04 Server
Python Version
3.13.5
Hermes Version
0.7.0
Relevant Files
gateway/run.py
gateway/session.py
tests/gateway/test_status_command.py
Proposed Fix (optional)
One of these needs to happen consistently:
- Make
/status read token usage from SessionDB / SQLite instead of SessionStore.total_tokens, or
- Restore synchronization so
SessionStore.total_tokens is updated from the authoritative token counts again.
Either way, the regression test should assert the source used by /status, so this does not drift again.
Are you willing to submit a PR for this?
Bug Description
/statuscan still showTokens: 0even when the current gateway session has substantial token usage recorded in SQLite.This appears to be a regression of the symptom fixed in #1465 / PR #1476, but with a changed root cause.
Steps to Reproduce
/status.Expected Behavior
/statusshould report the real token usage for the current session.Actual Behavior
/statusreportsTokens: 0even though the same session has non-zero token usage instate.db.Evidence
In my reproduction, the same session ID had:
sessions.json/SessionEntry.total_tokens=0state.dbtoken fields populated with large non-zero valuesExample from one affected session:
20260407_170736_30bcaff2sessions.json total_tokens = 0state.db input_tokens = 171876state.db output_tokens = 7295state.db cache_read_tokens = 1517184state.db reasoning_tokens = 2648Regression History
Issue #1465 was fixed by PR #1476 (
fix(gateway): make /status report live state and tokens).That fix explicitly threaded
input_tokens/output_tokensfromgateway/run.pyintosession_store.update_session(...), and added regression coverage intests/gateway/test_status_command.py.A later refactor appears to have reintroduced the visible bug:
20441cf2(fix(insights): persist token usage for non-CLI sessions)gateway/run.pystopped passing token counts intosession_store.update_session(...)gateway/session.py::update_session()was reduced to only updating lightweight metadata likelast_prompt_tokensSessionStoreRoot Cause Analysis
Current behavior looks like this:
state.db/statusstill readssession_entry.total_tokenssession_entry.total_tokenscomes fromSessionStore/sessions.jsonSo the symptom is a regression, but the root cause has changed:
SessionStore/statusstill depends on staleSessionStoretoken totalsAffected Component
Gateway
Messaging Platform (if gateway-related)
Telegram
Operating System
Ubuntu 24.04 Server
Python Version
3.13.5
Hermes Version
0.7.0
Relevant Files
gateway/run.pygateway/session.pytests/gateway/test_status_command.pyProposed Fix (optional)
One of these needs to happen consistently:
/statusread token usage fromSessionDB/ SQLite instead ofSessionStore.total_tokens, orSessionStore.total_tokensis updated from the authoritative token counts again.Either way, the regression test should assert the source used by
/status, so this does not drift again.Are you willing to submit a PR for this?