-
Notifications
You must be signed in to change notification settings - Fork 22.8k
fix(gateway): /status command always shows 0 tokens #11088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4068,6 +4068,7 @@ async def _handle_message_with_agent(self, event, source, _quick_key: str): | |
| self.session_store.update_session( | ||
| session_entry.session_key, | ||
| last_prompt_tokens=agent_result.get("last_prompt_tokens", 0), | ||
| total_tokens=agent_result.get("session_total_tokens", 0), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Critical: wrong key name. |
||
| ) | ||
|
|
||
| # Auto voice reply: send TTS audio before the text response | ||
|
|
@@ -8712,11 +8713,14 @@ def _approval_notify_sync(approval_data: dict) -> None: | |
| _last_prompt_toks = 0 | ||
| _input_toks = 0 | ||
| _output_toks = 0 | ||
| _session_total_toks = 0 | ||
| _agent = agent_holder[0] | ||
| if _agent and hasattr(_agent, "context_compressor"): | ||
| _last_prompt_toks = getattr(_agent.context_compressor, "last_prompt_tokens", 0) | ||
| _input_toks = getattr(_agent, "session_prompt_tokens", 0) | ||
| _output_toks = getattr(_agent, "session_completion_tokens", 0) | ||
| if _agent: | ||
| _session_total_toks = getattr(_agent, "session_total_tokens", 0) or 0 | ||
| _resolved_model = getattr(_agent, "model", None) if _agent else None | ||
|
|
||
| if not final_response: | ||
|
|
@@ -8732,6 +8736,7 @@ def _approval_notify_sync(approval_data: dict) -> None: | |
| "last_prompt_tokens": _last_prompt_toks, | ||
| "input_tokens": _input_toks, | ||
| "output_tokens": _output_toks, | ||
| "session_total_tokens": _session_total_toks, | ||
| "model": _resolved_model, | ||
| } | ||
|
|
||
|
|
@@ -8821,6 +8826,7 @@ def _approval_notify_sync(approval_data: dict) -> None: | |
| "last_prompt_tokens": _last_prompt_toks, | ||
| "input_tokens": _input_toks, | ||
| "output_tokens": _output_toks, | ||
| "session_total_tokens": _session_total_toks, | ||
| "model": _resolved_model, | ||
| "session_id": effective_session_id, | ||
| "response_previewed": result.get("response_previewed", False), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
| ) | ||
|
Comment on lines
150
to
154
|
||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agent_result.get("session_total_tokens", 0)will write0into the session store whenever the key is missing (e.g., proxy-mode results and early error returns that don't includesession_total_tokens). That can clobber a previously accumulatedSessionEntry.total_tokensand reintroduce the “Tokens: 0” issue after any non-token-reporting run. Prefer passingNonewhen the key is absent (or conditionally include the kwarg only when present) soupdate_session()leaves the stored value unchanged.