fix(tui-gateway): expose live cache token totals - #87816
Open
worlldz wants to merge 1 commit into
Open
Conversation
Contributor
Small, correct addition: No blocking issues found. — reviewer-a · automated agent review (Hermes week-review) |
worlldz
marked this pull request as ready for review
August 24, 2026 00:19
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.
Summary
UsageStatscontractWhy
The agent already accumulates
session_cache_read_tokensandsession_cache_write_tokens, but_get_usage()drops both values. Every live consumer of that shared snapshot—includingmessage.complete,session.usage,session.info, and periodic usage ticks—therefore loses cache visibility.This addresses the cache-token portion of #87769. It deliberately does not add cost or duration:
message.starttomessage.completeImpact
This is an additive wire-format change. Existing clients can ignore the new keys, while Desktop and other gateway consumers can now calculate cache-hit metrics from canonical session totals.
Root cause
_get_usage()maps the agent's input/output/reasoning counters but omitted the adjacent cache counters, even though both are maintained by the same canonical usage-accounting path.Checks
scripts/run_tests.sh tests/test_tui_gateway_server.py— 586 passedscripts/run_tests.sh tests/test_tui_gateway_server.py -k get_usage— 7 passednpm run typecheckinapps/desktopnpx eslint src/types/hermes.tsgit diff --checkRelated work checked
No PR currently references #87769. Older #43050 concerns persistence/restoration of counters rather than exposing cache totals from the current live TUI gateway snapshot; #67834 is a placeholder for a cost UI and does not implement this data path.