openclaw - 💡(How to fix) Fix Status bar ctx% shows 0% when context is mostly cached [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#70972Fetched 2026-04-24 10:37:18
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Timeline (top)
commented ×1mentioned ×1subscribed ×1

Root Cause

Bug: The per-message status bar in Control UI shows 0% ctx even when the actual context window usage is ~10% (100k/1M), because the calculation only counts non-cached input tokens and ignores cache-read tokens.

Code Example

// n = sum of usage.input (non-cached new tokens only)
// i = sum of usage.cacheRead (cached tokens)
// t = contextWindow (e.g. 1000000)
let l = t && n > 0 ? Math.min(Math.round(n / t * 100), 100) : null;

---

let total = n + i; // input + cacheRead
let l = t && total > 0 ? Math.min(Math.round(total / t * 100), 100) : null;
RAW_BUFFERClick to expand / collapse

Bug: The per-message status bar in Control UI shows 0% ctx even when the actual context window usage is ~10% (100k/1M), because the calculation only counts non-cached input tokens and ignores cache-read tokens.

Expected: ctx% should reflect the true context window occupancy, including cached tokens.

Root cause: In control-ui/assets/index-*.js, function EC():

// n = sum of usage.input (non-cached new tokens only)
// i = sum of usage.cacheRead (cached tokens)
// t = contextWindow (e.g. 1000000)
let l = t && n > 0 ? Math.min(Math.round(n / t * 100), 100) : null;

The formula uses only n (non-cached input), but the actual context window usage is n + i (input + cacheRead). When prompt caching is active (88%+ cache hit rate is common), n is tiny (e.g. 3 tokens for user message) while i is large (e.g. 98k), resulting in 0% displayed vs ~10% actual.

Reproduction:

  1. Start a session with a large system prompt and bootstrap files (typical setup uses ~100k context)
  2. After a few turns, cache hit rate reaches 80-100%
  3. Status bar shows 0% ctx while session_status correctly reports 10% ctx

Fix suggestion: Change the formula to include cache-read tokens:

let total = n + i; // input + cacheRead
let l = t && total > 0 ? Math.min(Math.round(total / t * 100), 100) : null;

Or alternatively, use the last turn's input + cacheRead instead of cumulative sum, since ctx% conceptually represents current context window fill level, not cumulative consumption.

extent analysis

TL;DR

Update the context window usage calculation to include both non-cached input tokens and cache-read tokens.

Guidance

  • Identify the current calculation formula in control-ui/assets/index-*.js and verify it only accounts for non-cached input tokens.
  • Modify the formula to sum both n (non-cached input tokens) and i (cache-read tokens) to get the total context window usage.
  • Consider using the last turn's input + cacheRead instead of the cumulative sum for a more accurate representation of the current context window fill level.
  • Test the updated formula with different cache hit rates to ensure the displayed context window usage percentage accurately reflects the actual usage.

Example

let total = n + i; // input + cacheRead
let l = t && total > 0 ? Math.min(Math.round(total / t * 100), 100) : null;

Notes

The provided fix suggestion assumes that the n and i variables are correctly calculated and represent the non-cached input tokens and cache-read tokens, respectively.

Recommendation

Apply the workaround by updating the calculation formula to include both non-cached input tokens and cache-read tokens, as this will provide a more accurate representation of the context window usage.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING