openclaw - ✅(Solved) Fix [Bug]: [WebChat/Control-UI] Context calculation is inaccurate - shows 100% before actual limit reached, while TUI works correctly [1 pull requests, 2 comments, 3 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#51507Fetched 2026-04-08 01:10:16
View on GitHub
Comments
2
Participants
3
Timeline
6
Reactions
0
Timeline (top)
commented ×2labeled ×2cross-referenced ×1referenced ×1

The webchat (also known as control UI) shows incorrect context usage percentage. It displays "100% context used"
when the actual context is far from the limit, making it impossible to continue the conversation. Meanwhile, the TUI
(terminal UI) correctly calculates and displays the context usage, allowing normal continuation.

Root Cause

The webchat (also known as control UI) shows incorrect context usage percentage. It displays "100% context used"
when the actual context is far from the limit, making it impossible to continue the conversation. Meanwhile, the TUI
(terminal UI) correctly calculates and displays the context usage, allowing normal continuation.

Fix Action

Fixed

PR fix notes

PR #51536: fix(webchat): use totalTokens for context utilization display

Description (problem / solution / changelog)

Fixes #51507

The context warning banner and /status command were reading session.inputTokens to compute context fill %, but inputTokens accumulates input tokens across ALL API sub-calls in a run (tool-use loops, retries, compaction). With models like MiniMax-M2.5 that chain many sub-calls, this number far exceeds the actual context size, causing premature 100% warnings and a blocked chat input.

The correct field is session.totalTokens, which the backend already derives from lastCallUsage (the final API call only) — the true prompt-size snapshot. This is the same value the TUI uses, which explains why TUI showed accurate context while WebChat did not.

Changes:

  • ui/views/chat.ts: renderContextNotice uses totalTokens (not inputTokens)
  • ui/chat/slash-command-executor.ts: /status Context % uses totalTokens
  • ui/views/chat.browser.test.ts: update fixture to totalTokens so the existing context notice test continues to pass

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem:
  • Why it matters:
  • What changed:
  • What did NOT change (scope boundary):

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #
  • Related #

User-visible / Behavior Changes

List user-visible changes (including defaults/config).
If none, write None.

Security Impact (required)

  • New permissions/capabilities? (Yes/No)
  • Secrets/tokens handling changed? (Yes/No)
  • New/changed network calls? (Yes/No)
  • Command/tool execution surface changed? (Yes/No)
  • Data access scope changed? (Yes/No)
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS:
  • Runtime/container:
  • Model/provider:
  • Integration/channel (if any):
  • Relevant config (redacted):

Steps

Expected

Actual

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios:
  • Edge cases checked:
  • What you did not verify:

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes/No)
  • Config/env changes? (Yes/No)
  • Migration needed? (Yes/No)
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly:
  • Files/config to restore:
  • Known bad symptoms reviewers should watch for:

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk:
    • Mitigation:

Changed files

  • ui/src/ui/chat/slash-command-executor.node.test.ts (modified, +3/-1)
  • ui/src/ui/chat/slash-command-executor.ts (modified, +5/-1)
  • ui/src/ui/views/chat.browser.test.ts (modified, +4/-1)

Code Example

<img width="803" height="188" alt="Image" src="https://github.com/user-attachments/assets/8d153a7e-20b2-4d09-9029-9028d95eab0e" />

<img width="831" height="280" alt="Image" src="https://github.com/user-attachments/assets/14ee7331-cde5-4b6b-8087-511cc08198f8" />
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Summary

The webchat (also known as control UI) shows incorrect context usage percentage. It displays "100% context used"
when the actual context is far from the limit, making it impossible to continue the conversation. Meanwhile, the TUI
(terminal UI) correctly calculates and displays the context usage, allowing normal continuation.

Steps to reproduce

  1. Start a conversation via webchat/control UI
  2. After several message exchanges (not reaching actual limit)
  3. The UI shows "100% context used" or similar indication
  4. Unable to send more messages even though actual context is not exhausted

Expected behavior

  • Context usage should be accurately calculated and displayed
  • Should be able to continue chatting until actual context limit is reached

Actual behavior

  • WebChat/Control-UI shows 100% context used prematurely
  • TUI shows accurate context usage and works normally
  • This suggests the context calculation logic differs between the two interfaces

OpenClaw version

2026.3.13

Operating system

macOS 15.7.2

Install method

npm global

Model

MiniMax-M2.5

Provider / routing chain

openclaw -> minimax

Additional provider/model setup details

No response

Logs, screenshots, and evidence

<img width="803" height="188" alt="Image" src="https://github.com/user-attachments/assets/8d153a7e-20b2-4d09-9029-9028d95eab0e" />

<img width="831" height="280" alt="Image" src="https://github.com/user-attachments/assets/14ee7331-cde5-4b6b-8087-511cc08198f8" />

Impact and severity

No response

Additional information

No response

extent analysis

Fix Plan

To resolve the incorrect context usage percentage issue in the webchat/control UI, we need to synchronize the context calculation logic between the webchat and TUI.

Here are the steps:

  • Review the context calculation logic in both interfaces to identify discrepancies.
  • Update the webchat/control UI to use the same context calculation logic as the TUI.
  • Verify that the context usage percentage is accurately calculated and displayed in the webchat/control UI.

Example code snippet to synchronize context calculation logic:

// Calculate context usage percentage
function calculateContextUsage(context) {
  const contextLimit = 1000; // assuming 1000 as the context limit
  const contextUsed = context.length;
  const contextUsagePercentage = (contextUsed / contextLimit) * 100;
  return contextUsagePercentage;
}

// Update webchat/control UI to use the same context calculation logic as TUI
function updateContextUsageUI(context) {
  const contextUsagePercentage = calculateContextUsage(context);
  // Update the UI to display the accurate context usage percentage
  document.getElementById('context-usage').innerHTML = `Context usage: ${contextUsagePercentage}%`;
}

Verification

To verify that the fix worked:

  • Start a conversation via webchat/control UI.
  • Exchange several messages without reaching the actual context limit.
  • Check that the webchat/control UI accurately displays the context usage percentage.
  • Verify that you can continue chatting until the actual context limit is reached.

Extra Tips

  • Ensure that the context calculation logic is correctly implemented and tested in both interfaces.
  • Consider adding automated tests to prevent similar regressions in the future.
  • Review the code regularly to ensure that the context calculation logic remains consistent across all interfaces.

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…

FAQ

Expected behavior

  • Context usage should be accurately calculated and displayed
  • Should be able to continue chatting until actual context limit is reached

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 [Bug]: [WebChat/Control-UI] Context calculation is inaccurate - shows 100% before actual limit reached, while TUI works correctly [1 pull requests, 2 comments, 3 participants]