Skip to content

web UI: fix context notice using accumulated inputTokens instead of p…#51721

Merged
BunsDev merged 1 commit intomainfrom
fix/context-notice-token-fallback
Mar 21, 2026
Merged

web UI: fix context notice using accumulated inputTokens instead of p…#51721
BunsDev merged 1 commit intomainfrom
fix/context-notice-token-fallback

Conversation

@BunsDev
Copy link
Copy Markdown
Member

@BunsDev BunsDev commented Mar 21, 2026

web UI: fix context notice using accumulated inputTokens instead of prompt snapshot

The context-usage banner in the web UI fell back to inputTokens when totalTokens was missing. inputTokens is accumulated across all API calls in a run (tool-use loops, compaction retries), so it overstates actual context window utilization -- e.g. showing "100% context used 757.3k / 200k" when the real prompt snapshot is only 46k/200k (23%).

Drop the inputTokens fallback so the banner only fires when a genuine prompt snapshot (totalTokens) is available.

Summary

  • Problem: The web UI context-usage banner fell back to inputTokens (accumulated across all API calls in a run) when totalTokens (prompt snapshot) was missing, showing false alarms like "100% context used 757.3k / 200k".
  • Why it matters: Users see a scary red "context full" warning when the actual context window is only 23% used, creating confusion and unnecessary session resets.
  • What changed: Removed the inputTokens fallback in renderContextNotice so the banner only fires when a genuine totalTokens prompt snapshot is available. Added a test covering the missing-totalTokens edge case.
  • What did NOT change (scope boundary): The status card text (Context: 46k/200k (23%)) was already correct and is untouched. Token accumulation, session storage, and per-message context % in grouped-render are unchanged.

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

  • Related #(none identified)

User-visible / Behavior Changes

  • The amber/red "X% context used" banner in the web UI no longer appears when totalTokens is unavailable, instead of falsely reporting accumulated inputTokens as context utilization.
  • When totalTokens is present and genuinely high (>=85% of context window), the banner continues to display correctly.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Bun / Node 22+
  • Model/provider: minimax-portal/MiniMax-M2.5 (any provider reproduces)
  • Integration/channel: Web UI (control-ui)
  • Relevant config: default context window 200k

Steps

  1. Start a session with a model that has a 200k context window.
  2. Run several tool-use loops so inputTokens accumulates well past 200k (e.g. 757k).
  3. Observe the context notice banner at the bottom of the chat view.

Expected

  • Banner hidden (or showing accurate context % based on prompt snapshot).

Actual (before fix)

  • Banner shows "100% context used 757.3k / 200k" even though real context utilization is 23%.

Evidence

  • Failing test/log before + passing after
    • Existing test "hides the context notice when only cumulative inputTokens exceed the limit" already encoded the correct expectation and passes with the fix.
    • New test "hides the context notice when totalTokens is missing even if inputTokens is high" covers the undefined-totalTokens edge case.
  • Screenshot/recording
    • User-provided screenshot showing the mismatch between status card (23%) and banner (100%).

Human Verification (required)

  • Verified scenarios: All 29 chat view tests pass (28 existing + 1 new). Format and lint clean on touched files.
  • Edge cases checked: totalTokens undefined with high inputTokens; totalTokens present and above 85% threshold; totalTokens present but below threshold.
  • What you did not verify: Live web UI end-to-end with a real session (test-only verification). Pre-existing src/tts/tts.ts format failure on main unrelated to this change.

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.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: Revert the one-line change in ui/src/ui/views/chat.ts line 258 to restore ?? session?.inputTokens.
  • Files/config to restore: ui/src/ui/views/chat.ts
  • Known bad symptoms reviewers should watch for: Context notice never appearing even when context is genuinely near capacity (would require totalTokens to be permanently missing for active sessions — unlikely given session-usage persistence).

Risks and Mitigations

  • Risk: If totalTokens is frequently undefined for active sessions, users lose the context-full warning entirely.
    • Mitigation: totalTokens is populated by deriveSessionTotalTokens on every reply with lastCallUsage or promptTokens. It is only missing on cold/stale sessions where context utilization is unknown anyway — showing nothing is more correct than showing a false alarm.

…rompt snapshot

The context-usage banner in the web UI fell back to inputTokens when
totalTokens was missing. inputTokens is accumulated across all API
calls in a run (tool-use loops, compaction retries), so it overstates
actual context window utilization -- e.g. showing "100% context used
757.3k / 200k" when the real prompt snapshot is only 46k/200k (23%).

Drop the inputTokens fallback so the banner only fires when a genuine
prompt snapshot (totalTokens) is available.

Made-with: Cursor
@openclaw-barnacle openclaw-barnacle bot added app: web-ui App: web-ui size: XS maintainer Maintainer-authored PR labels Mar 21, 2026
@BunsDev BunsDev self-assigned this Mar 21, 2026
@BunsDev BunsDev marked this pull request as ready for review March 21, 2026 16:16
@BunsDev BunsDev merged commit 7c520cc into main Mar 21, 2026
36 of 42 checks passed
@BunsDev BunsDev deleted the fix/context-notice-token-fallback branch March 21, 2026 16:16
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 21, 2026

Greptile Summary

This PR fixes a false-positive "context used" warning in the web UI chat view. The one-line change in renderContextNotice removes the inputTokens fallback so the banner only activates when a genuine totalTokens prompt snapshot is available, preventing alarming messages like "100% context used 757.3k / 200k" when actual context utilization is only ~23%.

  • The root cause was that inputTokens accumulates across all API calls in a run (tool-use loops, retries), making it an unreliable proxy for context window utilization.
  • The fix is minimal and surgical: removing ?? session?.inputTokens from the used assignment in renderContextNotice.
  • An existing test ("hides the context notice when only cumulative inputTokens exceed the limit") already covered the case where totalTokens is low alongside a high inputTokens; the new test covers the complementary edge case where totalTokens is entirely absent.
  • The happy-path case (genuine totalTokens ≥ 85%) is verified by the "uses totalTokens for the context notice detail when current usage is high" test and is unaffected.

Confidence Score: 5/5

  • Safe to merge — minimal, targeted fix with full test coverage and no side-effects on the happy path.
  • The change is a single-line removal of an incorrect fallback. The logic is clearly correct: inputTokens is cumulative across an entire run and should never be used as a proxy for context window utilization. The fix is well-tested (existing + new test), backward-compatible, and only affects sessions where totalTokens is absent (where showing nothing is strictly more accurate than a false alarm).
  • No files require special attention.

Last reviewed commit: "web UI: fix context ..."

MaheshBhushan pushed a commit to MaheshBhushan/openclaw that referenced this pull request Mar 21, 2026
…rompt snapshot (openclaw#51721)

The context-usage banner in the web UI fell back to inputTokens when
totalTokens was missing. inputTokens is accumulated across all API
calls in a run (tool-use loops, compaction retries), so it overstates
actual context window utilization -- e.g. showing "100% context used
757.3k / 200k" when the real prompt snapshot is only 46k/200k (23%).

Drop the inputTokens fallback so the banner only fires when a genuine
prompt snapshot (totalTokens) is available.

Made-with: Cursor
mrosmarin added a commit to mrosmarin/openclaw that referenced this pull request Mar 21, 2026
* main: (516 commits)
  fix: use content hash for memory flush dedup instead of compactionCount (openclaw#30115) (openclaw#34222)
  fix(tts): add matrix to VOICE_BUBBLE_CHANNELS (openclaw#37080)
  feat(memory): pluggable system prompt section for memory plugins (openclaw#40126)
  fix: detect nvm services from installed command (openclaw#51146)
  fix: handle Linux nvm CA env before startup (openclaw#51146) (thanks @GodsBoy)
  refactor: route Telegram runtime through plugin sdk (openclaw#51772)
  refactor: route iMessage runtime through plugin sdk (openclaw#51770)
  refactor: route Slack runtime through plugin sdk (openclaw#51766)
  refactor(doctor): extract provider and shared config helpers (openclaw#51753)
  Fix Discord `/codex_resume` picker expiration (openclaw#51260)
  fix(ci): remove duplicate embedding default export
  fix(ci): restore embedding defaults and plugin boundaries
  fix: compaction safeguard summary budget (openclaw#27727)
  web UI: fix context notice using accumulated inputTokens instead of prompt snapshot (openclaw#51721)
  fix(status): skip cold-start status probes
  refactor(doctor): extract telegram provider warnings (openclaw#51704)
  fix(telegram): default fresh setups to mention-gated groups
  docs(changelog): note telegram doctor first-run guidance
  fix(doctor): add telegram first-run guidance
  fix(doctor): suppress telegram fresh-install group warning
  ...
JohnJAS pushed a commit to JohnJAS/openclaw that referenced this pull request Mar 22, 2026
…rompt snapshot (openclaw#51721)

The context-usage banner in the web UI fell back to inputTokens when
totalTokens was missing. inputTokens is accumulated across all API
calls in a run (tool-use loops, compaction retries), so it overstates
actual context window utilization -- e.g. showing "100% context used
757.3k / 200k" when the real prompt snapshot is only 46k/200k (23%).

Drop the inputTokens fallback so the banner only fires when a genuine
prompt snapshot (totalTokens) is available.

Made-with: Cursor
pholpaphankorn pushed a commit to pholpaphankorn/openclaw that referenced this pull request Mar 22, 2026
…rompt snapshot (openclaw#51721)

The context-usage banner in the web UI fell back to inputTokens when
totalTokens was missing. inputTokens is accumulated across all API
calls in a run (tool-use loops, compaction retries), so it overstates
actual context window utilization -- e.g. showing "100% context used
757.3k / 200k" when the real prompt snapshot is only 46k/200k (23%).

Drop the inputTokens fallback so the banner only fires when a genuine
prompt snapshot (totalTokens) is available.

Made-with: Cursor
frankekn pushed a commit to artwalker/openclaw that referenced this pull request Mar 23, 2026
…rompt snapshot (openclaw#51721)

The context-usage banner in the web UI fell back to inputTokens when
totalTokens was missing. inputTokens is accumulated across all API
calls in a run (tool-use loops, compaction retries), so it overstates
actual context window utilization -- e.g. showing "100% context used
757.3k / 200k" when the real prompt snapshot is only 46k/200k (23%).

Drop the inputTokens fallback so the banner only fires when a genuine
prompt snapshot (totalTokens) is available.

Made-with: Cursor
furaul pushed a commit to furaul/openclaw that referenced this pull request Mar 24, 2026
…rompt snapshot (openclaw#51721)

The context-usage banner in the web UI fell back to inputTokens when
totalTokens was missing. inputTokens is accumulated across all API
calls in a run (tool-use loops, compaction retries), so it overstates
actual context window utilization -- e.g. showing "100% context used
757.3k / 200k" when the real prompt snapshot is only 46k/200k (23%).

Drop the inputTokens fallback so the banner only fires when a genuine
prompt snapshot (totalTokens) is available.

Made-with: Cursor
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 25, 2026
…rompt snapshot (openclaw#51721)

The context-usage banner in the web UI fell back to inputTokens when
totalTokens was missing. inputTokens is accumulated across all API
calls in a run (tool-use loops, compaction retries), so it overstates
actual context window utilization -- e.g. showing "100% context used
757.3k / 200k" when the real prompt snapshot is only 46k/200k (23%).

Drop the inputTokens fallback so the banner only fires when a genuine
prompt snapshot (totalTokens) is available.

Made-with: Cursor
(cherry picked from commit 7c520cc)
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 25, 2026
…rompt snapshot (openclaw#51721)

The context-usage banner in the web UI fell back to inputTokens when
totalTokens was missing. inputTokens is accumulated across all API
calls in a run (tool-use loops, compaction retries), so it overstates
actual context window utilization -- e.g. showing "100% context used
757.3k / 200k" when the real prompt snapshot is only 46k/200k (23%).

Drop the inputTokens fallback so the banner only fires when a genuine
prompt snapshot (totalTokens) is available.

Made-with: Cursor
(cherry picked from commit 7c520cc)
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 maintainer Maintainer-authored PR size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant