Skip to content

fix(tui-gateway): expose live cache token totals - #87816

Open
worlldz wants to merge 1 commit into
NousResearch:mainfrom
worlldz:agent/fix-live-usage-cache-totals
Open

fix(tui-gateway): expose live cache token totals#87816
worlldz wants to merge 1 commit into
NousResearch:mainfrom
worlldz:agent/fix-live-usage-cache-totals

Conversation

@worlldz

@worlldz worlldz commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • expose the agent's existing session cache-read and cache-write counters through the shared TUI gateway usage snapshot
  • add the corresponding optional fields to the Desktop UsageStats contract
  • cover the gateway mapping with a regression test

Why

The agent already accumulates session_cache_read_tokens and session_cache_write_tokens, but _get_usage() drops both values. Every live consumer of that shared snapshot—including message.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:

  • user-facing provider cost estimates were previously removed as a product-policy decision and should not be reintroduced incidentally
  • Desktop already measures turn duration from message.start to message.complete

Impact

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 passed
  • scripts/run_tests.sh tests/test_tui_gateway_server.py -k get_usage — 7 passed
  • npm run typecheck in apps/desktop
  • npx eslint src/types/hermes.ts
  • git diff --check

Related 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.

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/tui Terminal UI (ui-tui/ + tui_gateway/) comp/desktop Electron desktop app (apps/desktop/*) area/usage-cost Token accounting, usage reporting, billing, cost tracking labels Aug 16, 2026
@Enough1122

Copy link
Copy Markdown
Contributor

AI code review — automated review; please use your judgment.

Small, correct addition: _get_usage now surfaces cache_read_tokens/cache_write_tokens through the same g() fallback helper as the neighboring counters, the TS UsageStats type gains both as optional fields (so older agents without the attributes simply omit them), and a focused test pins the mapping on a bare agent namespace.

No blocking issues found.

— reviewer-a · automated agent review (Hermes week-review)

@worlldz
worlldz marked this pull request as ready for review August 24, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/usage-cost Token accounting, usage reporting, billing, cost tracking comp/desktop Electron desktop app (apps/desktop/*) comp/tui Terminal UI (ui-tui/ + tui_gateway/) P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants