fix(ui): include cache tokens in ctx% badge and cache-hit-rate#68557
fix(ui): include cache tokens in ctx% badge and cache-hit-rate#68557Ante042 wants to merge 2 commits intoopenclaw:mainfrom
Conversation
The context percentage badge in grouped render and the cache-hit-rate metric in the usage overview were both ignoring cache tokens, so any session using Anthropic prompt caching (where most of the prompt lives in cacheRead/cacheWrite rather than input) rendered a misleading ~0% context usage and an inflated cache-hit-rate. Fixes: * ui/src/ui/chat/grouped-render.ts: sum input + cacheRead + cacheWrite when computing contextPercent, so the badge reflects the real share of the context window occupied by the prompt. * ui/src/ui/views/usage-render-overview.ts: include cacheWrite in the cache-hit-rate denominator. The current formula double-counts cache writes toward hit rate by omitting them from the base. * ui/src/i18n/locales/en.ts: update the cacheHint tooltip to match the corrected formula.
Greptile SummaryThis PR fixes two related math bugs: the ctx% context-window badge was dividing only
Confidence Score: 4/5Safe to merge after running pnpm ui:i18n:sync and committing the regenerated locale files. All logic changes are correct. The only gap is the missing i18n sync step mandated by ui/CLAUDE.md — non-English locale tooltips will show the old formula until regenerated. This is a process step that should be completed before landing per project rules. ui/src/i18n/locales/en.ts — missing pnpm ui:i18n:sync to regenerate the 12 non-English locale bundles. Prompt To Fix All With AIThis is a comment left during a code review.
Path: ui/src/i18n/locales/en.ts
Line: 514
Comment:
**Missing `pnpm ui:i18n:sync` run**
`ui/CLAUDE.md` specifies that after editing `en.ts`, the pipeline step `pnpm ui:i18n:sync` must be run and the regenerated locale bundles committed. The 12 non-English locale files (`de.ts`, `es.ts`, `fr.ts`, etc.) still contain the old `cacheHint` formula. The tooltip mismatch is cosmetic, but the process rule is explicit — regenerate and commit before landing.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(ui): include cache tokens in ctx% ba..." | Re-trigger Greptile |
| avgSession: "avg session", | ||
| cacheHitRate: "Cache Hit Rate", | ||
| cacheHint: "Cache hit rate = cache read / (input + cache read). Higher is better.", | ||
| cacheHint: "Cache hit rate = cache read / (input + cache read + cache write). Higher is better.", |
There was a problem hiding this comment.
ui/CLAUDE.md specifies that after editing en.ts, the pipeline step pnpm ui:i18n:sync must be run and the regenerated locale bundles committed. The 12 non-English locale files (de.ts, es.ts, fr.ts, etc.) still contain the old cacheHint formula. The tooltip mismatch is cosmetic, but the process rule is explicit — regenerate and commit before landing.
Prompt To Fix With AI
This is a comment left during a code review.
Path: ui/src/i18n/locales/en.ts
Line: 514
Comment:
**Missing `pnpm ui:i18n:sync` run**
`ui/CLAUDE.md` specifies that after editing `en.ts`, the pipeline step `pnpm ui:i18n:sync` must be run and the regenerated locale bundles committed. The 12 non-English locale files (`de.ts`, `es.ts`, `fr.ts`, etc.) still contain the old `cacheHint` formula. The tooltip mismatch is cosmetic, but the process rule is explicit — regenerate and commit before landing.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3c88628bcf
ℹ️ 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".
| avgSession: "avg session", | ||
| cacheHitRate: "Cache Hit Rate", | ||
| cacheHint: "Cache hit rate = cache read / (input + cache read). Higher is better.", | ||
| cacheHint: "Cache hit rate = cache read / (input + cache read + cache write). Higher is better.", |
There was a problem hiding this comment.
Regenerate locale bundles after changing cache-hit hint
This update changes only ui/src/i18n/locales/en.ts, but the cache-hit-rate math was also changed in UI logic, so non-English users will now see a stale tooltip that still describes the old denominator while the displayed metric uses input + cacheRead + cacheWrite. ui/AGENTS.md explicitly requires running pnpm ui:i18n:sync and committing regenerated locale bundles after English string changes, so skipping that step leaves localized help text inconsistent with runtime behavior.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c35787a200
ℹ️ 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".
| avgSession: "avg session", | ||
| cacheHitRate: "Cache Hit Rate", | ||
| cacheHint: "Cache hit rate = cache read / (input + cache read). Higher is better.", | ||
| cacheHint: "Cache hit rate = cache read / (input + cache read + cache write). Higher is better.", |
There was a problem hiding this comment.
Sync localized cache-hit hint to the new denominator
Updating the English usage.overview.cacheHint formula without updating translated locale bundles leaves non-English users with a misleading tooltip while the metric now uses a different denominator. Fresh evidence in this commit is that .i18n/*.meta.json source hashes were bumped, but locale entries such as ui/src/i18n/locales/de.ts and ui/src/i18n/locales/zh-CN.ts still describe cache read / (input + cache read), so the UI explanation is now inconsistent for those locales.
Useful? React with 👍 / 👎.
|
Closing this as duplicate or superseded after Codex automated review. PR #68557 is superseded by merged PR #71462. Current main contains the requested Control UI runtime fixes and regression coverage for both cache-token-aware ctx% and cache-hit-rate math. The latest release tag predates the Usage overview denominator fix, so there is no shipped release to cite yet. Best possible solution: Close #68557 as superseded by merged PR #71462 and keep the current main implementation/tests. Track the remaining non-English cacheHitRate tooltip drift separately if maintainers want localized tooltip parity. What I checked:
So I’m closing this here and keeping the remaining discussion on the canonical linked item. Codex Review notes: model gpt-5.5, reasoning high; reviewed against d54d2d6b9b8a; fix evidence: commit 4282c591775b. |
Summary
Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause (if applicable)
Both call sites were written when Anthropic prompt caching wasn't a first-class concept and only the `input` counter mattered. Once caching landed, the bulk of the prompt tokens shifted into `cacheRead`/`cacheWrite` but the two math expressions weren't updated:
Evidence
Human Verification (required)
Review Conversations
Compatibility / Migration
Risks and Mitigations