fix(gateway): /status command always shows 0 tokens

SessionEntry.total_tokens was initialized to 0 in the constructor but
never updated during the session lifecycle. The agent tracks cumulative
tokens on agent.session_total_tokens, but that value was never written
back to the session store.

Changes:
- session.py: update_session() accepts optional total_tokens parameter
- run.py: pipe agent.session_total_tokens through result dict into
  update_session() after each agent run (both success and error paths)
- test_status_command.py: updated assertion for new call signature
This commit is contained in:
rustyorb 2026-04-16 11:12:11 -04:00
parent 722331a57d
commit fda6d1f762
3 changed files with 10 additions and 0 deletions

View file

@ -150,6 +150,7 @@ async def test_handle_message_persists_agent_token_counts(monkeypatch):
runner.session_store.update_session.assert_called_once_with(
session_entry.session_key,
last_prompt_tokens=80,
total_tokens=0,
)