feat(usage): show the cached subset beside every token total - #4421
Conversation
A cached request's total is mostly cache. A 58,000-token prompt that is 57,000 cache read and 1,000 fresh was printed as a bare 58,000 on every surface except the logs table row, so it read as a different, smaller request than the row directly beside it. formatTokensWithCache renders the total with its cached companion — 5.8만 c5.7만, 58K c57K — reusing the marker the logs.tokens.cacheRead label already documents as "cache read (c)", so no new i18n key is needed. A provider that reports no cache is untouched, and a turn served entirely from cache still shows the marker, since that is the row worth seeing. No backend change: /api/logs forwards the whole usage object and /api/usage already emits cache on summary, models and providers. The loss was purely client-side, in the row types and the aggregators, so the fix widens UsageModel, UsageProvider, UsageSummary30d, the CLI CostRow, and summarizeFilteredLogs to keep the fields that were already arriving. The log detail panel is deliberately left alone: it already has separate cache read and cache write cells, and stacking the companion onto its total would duplicate them.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
✅ Deterministic PR hygiene checks passed. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (10)
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe change adds cache-aware token formatting to GUI logs, usage tables, dashboards, and CLI usage reports. It adds optional cache token fields to usage models and validates cached and uncached display cases. ChangesCache-aware token reporting
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Feature Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant Logs
participant summarizeFilteredLogs
participant cacheSplit
participant formatTokensWithCache
participant ConversationTotals
Logs->>summarizeFilteredLogs: summarize filtered entries
summarizeFilteredLogs->>cacheSplit: read cache-read tokens
cacheSplit-->>summarizeFilteredLogs: cachedInputTokens
ConversationTotals->>formatTokensWithCache: format total and cachedInputTokens
formatTokensWithCache-->>ConversationTotals: cache-aware token text
Merge Risk: ⚪ Minimal · up to Cache-aware token displays preserve the required data flow and formatting behavior across the reviewed GUI and CLI paths. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 8 files. (2 skipped: 2 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
리뷰 · 우선순위 58 / 80이 PR은 사용량 화면에서 토큰 숫자만 덩그러니 보이던 자리를, 캐시로 읽힌 부분까지 같이 보여 주게 고칩니다. 지금 고치는 방식은 백엔드를 건드리지 않습니다. types.ts/config.ts 대규모 분리 캠페인과 겹치지 않는 클라이언트 표시 수정이라 닫고 리베이스하라는 대상은 아닙니다. 중복 PR도 아닙니다. Devin ACP 제거(#4415) 이후 캐시·사용량 가시성을 다듬는 작은 후속 작업으로 읽힙니다. gui/src/pages/Logs.tsx - gui/src/pages/Usage.tsx (daybar / heatmap) - PR 제목·본문은 “토큰 총량 옆마다”라고 말하지만, 같은 Usage 페이지의 daybar 카운트·툴팁과 heatmap 툴팁은 여전히 gui/src/components/provider-workspace (ProviderUsage / ProviderOverview) - 프로바이더 워크스페이스 토큰 숫자도 아직 캐시 동반 표시가 없습니다. 이번 diff 범위 밖이지만, 운영자가 Usage 표와 PWS를 같이 보면 다시 숫자가 다르게 읽힐 수 있습니다. gui formatTokensWithCache / countWithCache - devlog/_plan/.../cached-token-companion.jpg - 계획 폴더에 스크린샷을 넣는 증거용으로 보이며 용량도 작습니다. 다만 제품 경로가 아니라 plan 자산이라, 머지 후 plan 정리 때 남길지 메인테이너의 판단이 필요한 지점
너의 추천 이 댓글은 grok-bot이 작성했습니다 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 635725a9cf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| export function formatTokensWithCache(total: number, cached: number | undefined, locale: string): string { | ||
| const base = formatTokens(total, locale); | ||
| if (cached === undefined || !Number.isFinite(cached) || cached <= 0) return base; | ||
| return `${base} c${formatTokens(cached, locale)}`; |
There was a problem hiding this comment.
Document the new cache-companion notation
When cached usage is present, the dashboard and Usage tables now display compact values such as 58K c57K, but docs-site/src/content/docs/guides/web-dashboard.md still describes only a token total and the CLI observability reference does not explain that c is a non-additive cache-read subset. Users encountering the notation outside the Logs detail view therefore have no documented way to interpret it; update the English documentation and keep the translated pages consistent.
AGENTS.md reference: AGENTS.md:L380-L381
Useful? React with 👍 / 👎.
…#4424) * Revert "feat(usage): show the cached subset beside every token total" This reverts 7b3c4e9. The reported defect was Devin-only and had nothing to do with the display layer. The logs table has always rendered a total with its cached value; Devin rows showed a bare total because the cloud-direct adapter decoded GetChatMessageResponse field 28 (response_dimension_groups, the rows the IDE draws) instead of field 7 (ModelUsageStats), so cache read and cache write never reached the log row in the first place. #4419 fixes that at the source, which is the whole fix. Changing the Usage page, the dashboard tile and the CLI tables rewrote surfaces that were already correct for every other provider, so the revert restores them. * docs(devlog): capture the restored logs rendering with Devin cache present Evidence for the revert: the logs table layout is exactly what it was before #4421, and the Devin CLI rows now carry their cached line because #4419 reads the usage field that actually holds it.
Summary
A cached request's total is mostly cache. A 58,000-token prompt that is 57,000 cache read and 1,000 fresh was printed as a bare
5.8만everywhere except the logs table row, so it read as a different, smaller request than the row directly beside it.formatTokensWithCacherenders the total with its cached companion —5.8만 c5.7만,58K c57K— reusing the marker thelogs.tokens.cacheReadlabel already documents as "cache read (c)", so no new i18n key is required. A provider that reports no cache is untouched. A turn served entirely from cache still shows the marker, because that is the row most worth seeing and suppressing it would blank exactly the case this exists for.No backend change was needed.
/api/logsforwards the whole usage object and/api/usagealready emits cache on summary, models and providers. The loss was entirely client-side: the row types dropped the fields and the aggregators summed only totals. This widensUsageModel,UsageProvider,UsageSummary30d, the CLI'sCostRow, andsummarizeFilteredLogsto keep what was already arriving.Surfaces converted: the Logs conversation-totals banner, the Usage per-model and per-provider token columns, the dashboard 30-day tile, and the CLI
ocx usageprovider/model/account rows. The log detail panel is deliberately left alone — it already has separate cache read and cache write cells, so stacking the companion on its total would duplicate them.Captured from a build of this branch served by a throwaway proxy on its own port and its own
OPENCODEX_HOME, seeded with synthetic usage rows, so the running service was untouched. Anthropic Claude shows41.7만 c33.1만, Devin CLI10만 c9.7만, and xAI Grok — which reported no cache — stays a bare9.9만.Verification
bun test tests/gui/gui-format-tokens-cache.test.ts tests/cli/cli-usage-report.test.ts tests/test-layout.test.ts tests/test-layout-tooling.test.ts— green. The new test file is registered inscripts/test-layout/layout.jsonandtests/fixtures/test-layout-expected.json.bun x tsc --noEmit— clean.bun run lint:gui— clean.bun run test: NOT RUN locally by request; remote CI on this head is the evidence.Checklist
Summary by CodeRabbit
New Features
Tests