openclaw - ✅(Solved) Fix Control UI shows incorrect context percentage (always 100% after compaction) [2 pull requests, 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#51060Fetched 2026-04-08 01:04:47
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×3commented ×1

Root Cause

In control-ui/assets/index-UvgeZ3yV.js:

// Line ~645
let l = t && n > 0 ? Math.min(Math.round(n / t * 100), 100) : null;

// n = Sum of ALL input tokens across session (cumulative)
// t = Context window limit (200k)

The calculation uses cumulative input tokens instead of current context tokens after compaction.

When cumulative tokens exceed the context limit, it caps at 100%, making the metric meaningless.

Fix Action

Fixed

PR fix notes

PR #51231: fix(ui): update context percentage and token count after compaction

Description (problem / solution / changelog)

Summary

  • Fix context percentage and token count not refreshing in the UI after session compaction
  • Ensure session list and chat view reflect updated values when context is compacted

Change Type

  • Bug fix

Linked Issue

  • Closes #51060
  • Closes #50795
  • Closes #50726

Changed files

  • src/agents/tools/sessions-helpers.ts (modified, +1/-0)
  • src/agents/tools/sessions-list-tool.ts (modified, +1/-0)
  • src/auto-reply/reply/session-updates.ts (modified, +3/-2)
  • ui/src/ui/chat/slash-command-executor.ts (modified, +1/-1)
  • ui/src/ui/views/chat.ts (modified, +3/-1)

PR #49917: fix(ui): context % uses full token footprint instead of uncached input only

Description (problem / solution / changelog)

Problem

The control dashboard footer shows 0-1% context usage when /status\ reports 21% for the same session.

Dashboard footer: \↑3 ↓505 R26.1k W309 0% ctx
/status: \Context: 26k/128k (21%)\

Root Cause

\extractGroupMeta\ in \grouped-render.ts\ computes \contextPercent\ by dividing only the uncached input tokens (\input) by the context window. For a session with 26k total tokens where only 309 were uncached (new), this produces \309 / 128000 = 0%\ instead of the correct \26000 / 128000 ≈ 21%.

The backend already computes this correctly via \derivePromptTokens\ (\input + cacheRead + cacheWrite), but three UI surfaces weren't using the same formula.

Fix

*\grouped-render.ts* (footer % ctx):

  • Compute \contextTotal = input + cacheRead + cacheWrite\ and use that as the numerator, matching \derivePromptTokens\ in \src/agents/usage.ts.

*\chat.ts* (
enderContextNotice, the 85%+ warning bar):

  • Use \ otalTokens\ (which is already \input + cacheRead + cacheWrite\ per \session-store.ts) instead of \inputTokens.

*\slash-command-executor.ts* (/usage\ command):

  • Use \ otalTokens\ for the context percentage instead of \inputTokens.

Repro

  1. Open a session with prompt caching active (most Anthropic/OpenAI models)
  2. Send a few messages to build context
  3. Compare footer % ctx\ with /status\ output
  4. Footer shows near-0%, /status\ shows the correct percentage

Observed with \github-copilot/claude-opus-4.6\ on OpenClaw 2026.3.13.

Fixes #49824

Changed files

  • ui/src/ui/chat/grouped-render.ts (modified, +6/-1)
  • ui/src/ui/chat/slash-command-executor.ts (modified, +5/-1)
  • ui/src/ui/views/chat.ts (modified, +4/-1)

Code Example

// Line ~645
let l = t && n > 0 ? Math.min(Math.round(n / t * 100), 100) : null;

// n = Sum of ALL input tokens across session (cumulative)
// t = Context window limit (200k)

---

// From auth-profiles-DDVivXkv.js line 117996
const totalsLine = session.totalTokens != null 
  ? `Session tokens (cached): ${formatInt(session.totalTokens)} total / ctx=${session.contextTokens ?? "?"}` 
  : `Session tokens (cached): unknown / ctx=${session.contextTokens ?? "?"}`;
RAW_BUFFERClick to expand / collapse

Bug Description

The Control UI message metadata shows incorrect context percentage after LCM compaction.

Current Behavior

Control UI displays: ↑293.3k ↓1.7k 100% ctx glm-5:cloud /status command shows: Context 53k/200k (27%)

Expected Behavior

Both should show the current context usage, not cumulative tokens.

Root Cause

In control-ui/assets/index-UvgeZ3yV.js:

// Line ~645
let l = t && n > 0 ? Math.min(Math.round(n / t * 100), 100) : null;

// n = Sum of ALL input tokens across session (cumulative)
// t = Context window limit (200k)

The calculation uses cumulative input tokens instead of current context tokens after compaction.

When cumulative tokens exceed the context limit, it caps at 100%, making the metric meaningless.

Correct Calculation

Should use session.totalTokens (post-compaction) instead of cumulative input, similar to how /status calculates it:

// From auth-profiles-DDVivXkv.js line 117996
const totalsLine = session.totalTokens != null 
  ? `Session tokens (cached): ${formatInt(session.totalTokens)} total / ctx=${session.contextTokens ?? "?"}` 
  : `Session tokens (cached): unknown / ctx=${session.contextTokens ?? "?"}`;

Impact

  • Users see misleading "100% ctx" when context is actually healthy post-compaction
  • Defeats the purpose of LCM (Lossless Context Management) transparency

Environment

  • OpenClaw version: 2026.3.13
  • Model: ollama/glm-5:cloud (200k context window)
  • LCM compaction: active

extent analysis

Fix Plan

To fix the incorrect context percentage display, update the calculation in control-ui/assets/index-UvgeZ3yV.js to use session.totalTokens instead of cumulative input tokens.

Steps:

  • Update the calculation to use session.totalTokens:
let l = t && session.totalTokens > 0 ? Math.min(Math.round(session.totalTokens / t * 100), 100) : null;
  • Ensure session.totalTokens is accessible in the calculation scope.
  • Verify that session.totalTokens reflects the post-compaction token count.

Example Code:

// Assuming session is an object with totalTokens property
const contextLimit = 200000; // 200k context window
const currentContextPercentage = session.totalTokens
  ? Math.min(Math.round(session.totalTokens / contextLimit * 100), 100)
  : null;

Verification

After applying the fix, verify that the Control UI message metadata displays the correct context percentage by:

  • Checking the /status command output for consistency with the Control UI display.
  • Performing LCM compaction and observing that the context percentage updates correctly.

Extra Tips

  • Ensure that session.totalTokens is updated correctly after LCM compaction.
  • Review other parts of the code that may be using cumulative input tokens instead of post-compaction token counts.

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

openclaw - ✅(Solved) Fix Control UI shows incorrect context percentage (always 100% after compaction) [2 pull requests, 1 comments, 2 participants]