fix(web): include cache token buckets in analytics - #26274
Conversation
178cfd9 to
aabb951
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused cache-accounting fix. The premise is confirmed on current main: /api/analytics/usage omits cache_write_tokens at hermes_cli/web_server.py:13943-13979, and /api/analytics/models omits it from model totals at hermes_cli/web_server.py:14017-14148.
Problems
web/src/pages/ModelsPage.tsx:100includesreasoningin the TokenBar denominator. The PR's card total atweb/src/pages/ModelsPage.tsx:382usestotal_tokens, while the canonical definition atagent/usage_pricing.py:40-46is input + cache read + cache write + output, explicitly excluding reasoning. The bar therefore double-counts reasoning relative to the displayed total.
Suggested changes
- Keep the TokenBar's proportional total to input + output + cache read + cache write. Show reasoning as non-additive metadata, or otherwise make its relationship to output explicit. Add a regression case with nonzero reasoning tokens.
Automated hermes-sweeper review.
| reasoning: number; | ||
| }) { | ||
| const total = input + output + cacheRead + reasoning; | ||
| const total = input + output + cacheRead + cacheWrite + reasoning; |
There was a problem hiding this comment.
CanonicalUsage.total_tokens is prompt plus output (agent/usage_pricing.py:40-46), so reasoning is intentionally not additive. Including it here makes the stacked bar disagree with the entry.total_tokens card at line 382 and double-counts reasoning. Keep this denominator to input + output + cache read + cache write; show reasoning without adding it as another total segment.
|
@teknium1 the reasoning-token proportional-bar blocker is fixed on current head
Verification:
The PR body has been refreshed with the semantic contract, exact SHA, baseline lint status, and current evidence. |
Summary
Fix dashboard analytics token accounting so the Token Usage views include all persisted token buckets, not just input/output.
This updates
/api/analytics/usageand/api/analytics/modelsto aggregate and return:cache_read_tokenscache_write_tokensreasoning_tokenstotal_tokens= input + output + cache read + cache writeThe Analytics and Models pages now display/sort using the corrected totals, including cache tokens. Reasoning tokens remain exposed separately and are not double-counted into
total_tokens.Related context: #23270 and #25400 cover adjacent token visibility gaps, but this PR is specifically about persisted dashboard analytics undercounting cache buckets.
Changes
total_tokens, not only input/output.Semantic contract
CanonicalUsage.total_tokensis authoritative: input + cache read + cache write + output. The API totals, sorting key, card total/fallback, and proportional token-bar denominator route through that same four-bucket contract.reasoning_tokensis separately reported metadata and does not consume stacked-bar width.Verification
Current reviewed head:
a71bd8bf79384b46aeb1d1737a52c1b66d1aef41240instead of canonical200when reasoning was nonzero.npm --workspace web test— 34 passed.npm --workspace web run typecheck— passed.npm --workspace web run build— passed.python -m pytest -q tests/hermes_cli/test_web_server.py -k 'analytics_usage_accounts_for_cache_token_buckets or analytics_models_accounts_for_cache_token_buckets or models_analytics'— 3 passed, 356 deselected.git diff --cached --checkand added-line secret/danger scan — clean.ModelsPageeffect at line 1185. No new lint finding was introduced.No public API or schema compatibility change is introduced by the review remediation; it only corrects the Models proportional visual and labels reasoning as separately reported.