Skip to content

fix(ui): include cache tokens in contextPercent calculation#70530

Closed
vmanuelort-sys wants to merge 1 commit into
openclaw:mainfrom
vmanuelort-sys:fix/context-percent-cache-tokens
Closed

fix(ui): include cache tokens in contextPercent calculation#70530
vmanuelort-sys wants to merge 1 commit into
openclaw:mainfrom
vmanuelort-sys:fix/context-percent-cache-tokens

Conversation

@vmanuelort-sys

Copy link
Copy Markdown

Summary

extractGroupMeta in ui/src/ui/chat/grouped-render.ts computed contextPercent from fresh input tokens only, ignoring cacheRead + cacheWrite. With Anthropic prompt caching, most of the context window arrives as cached tokens, so input is routinely in the single digits while cached tokens make up the real load — the UI renders "0% ctx" even on near-full sessions.

Fix

Use input + cacheRead + cacheWrite as the numerator. Matches the intent of the ctx % indicator (how full the context window is), and the values are already aggregated in the same function.

const totalInput = input + cacheRead + cacheWrite;
const contextPercent =
  contextWindow && totalInput > 0
    ? Math.min(Math.round((totalInput / contextWindow) * 100), 100)
    : null;

Evidence

Live session (agent:main:main, 2026-04-23):

  • inputTokens: 3
  • cacheWrite: 93,056
  • contextTokens: 200,000
  • Before: renders 0%
  • After: renders 47%

Gates

  • pnpm check:changed (typecheck core + core-test, lint, import-cycles, webhook/pairing guards, 171 ui tests)
  • pnpm build
  • Committed via scripts/committer

@greptile-apps

greptile-apps Bot commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes contextPercent in extractGroupMeta to include cacheRead and cacheWrite tokens alongside fresh input tokens, so the "ctx %" indicator accurately reflects context window usage when Anthropic prompt caching is active. The change is minimal and correct.

Confidence Score: 5/5

Safe to merge — single-line arithmetic fix with no side effects.

No logic, syntax, or security issues. The fix correctly accounts for all token categories in the context percentage calculation, and the zero-guard is preserved.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(ui): include cache tokens in context..." | Re-trigger Greptile

@prtags

prtags Bot commented Apr 23, 2026

Copy link
Copy Markdown

Related work from PRtags group liked-piglet-oe6w

Title: Control UI context percent ignores cached prompt tokens

Number Title
#70530* fix(ui): include cache tokens in contextPercent calculation
#70532 fix(ui): include cached tokens in context usage
#70592 fix(ui): include cacheRead in contextPercent calculation

* This PR

@steipete steipete added duplicate This issue or pull request already exists close:duplicate Closed as duplicate dedupe:child Duplicate issue/PR child in dedupe cluster labels Apr 23, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for the fix. This is now covered by the landed #70532 / commit 6415e35.

#70532 fixes the same Control UI footer context-percent bug in ui/src/ui/chat/grouped-render.ts, using input + cacheRead + cacheWrite and adding regression coverage for both cached prompt tokens and output-token exclusion. Closing this PR as a duplicate.

@steipete steipete closed this Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui close:duplicate Closed as duplicate dedupe:child Duplicate issue/PR child in dedupe cluster duplicate This issue or pull request already exists size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants