fix(agent): rehydrate session accumulators from SQLite on restart (#67762) - #67796
Open
JonthanaHanh wants to merge 1 commit into
Open
fix(agent): rehydrate session accumulators from SQLite on restart (#67762)#67796JonthanaHanh wants to merge 1 commit into
JonthanaHanh wants to merge 1 commit into
Conversation
When the gateway restarts mid-session, init_agent() resets all session accumulators (cost, tokens, API call count) to zero. The persisted data in SQLite is correct, but nothing copies it back into the agent state. After resetting accumulators, read the existing session row from SQLite (if present) and restore the persisted totals. No-op for new sessions. Fixes NousResearch#67762
Collaborator
Contributor
|
Thanks for targeting the live-accounting reset; current main still resets these fields at Problems
Suggested changes
The reset hunk is still present on current main, but the accounting source and counter mapping need rework. This is an automated hermes-sweeper review. |
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.
Problem
When the gateway restarts mid-session,
init_agent()resets all session accumulators (session_estimated_cost_usd, token counts,session_api_calls) to zero. The persisted data in SQLite (sessions.estimated_cost_usd,session_model_usagerows) is correct, but nothing copies it back into the agent's in-memory state.This means:
/insightsdashboard shows the correct total, but the agent's runtime state liesVerified against
main(commit26480e6c5).Reproduction
agent.session_estimated_cost_usd-- shows $0.0 (or only post-restart cost).sessions.estimated_cost_usdin~/.hermes/state.db-- correctly shows the full total.Fix
After the accumulator reset block in
agent/agent_init.py, read the existing session row from SQLite (if present) and restore the persisted totals:session_estimated_cost_usdsession_cost_status/session_cost_sourcesession_api_callsFor new sessions,
get_session()returnsNoneand the block is a no-op. DB errors are caught and swallowed (fail-open).Files Changed
agent/agent_init.py-- add rehydration block after accumulator resetFixes #67762