Skip to content

fix(ui): add context-notice component and refresh token stats after every chat turn, solve #45230, #45034, #45192, #45794#45282

Closed
haoruilee wants to merge 16 commits intoopenclaw:mainfrom
haoruilee:cursor/issues-45230-45034-root-cause-9f24
Closed

fix(ui): add context-notice component and refresh token stats after every chat turn, solve #45230, #45034, #45192, #45794#45282
haoruilee wants to merge 16 commits intoopenclaw:mainfrom
haoruilee:cursor/issues-45230-45034-root-cause-9f24

Conversation

@haoruilee
Copy link
Copy Markdown
Contributor

@haoruilee haoruilee commented Mar 13, 2026

Summary

  • Problem 1 (Control UI: Context warning blocks screen on refresh with incorrect values #45230): On page refresh the Control UI showed a full-screen context warning with impossible values (550.4k / 204.8k, usage > window). Two root causes: (a) the component used inputTokens (cumulative all-time input, can far exceed the context window) instead of totalTokens (current turn's context window usage); (b) the CSS for .context-notice was missing entirely, so the unstyled <div> expanded to fill the screen.
  • Problem 2 (Control UI: Token stats not showing in real-time chat #45034): Token stats in the chat tab never updated in real-time after a message. loadSessions() was only called after a terminal chat event when the run ID was in refreshSessionsAfterChat — which only happened for /new/reset commands, never for normal turns.
  • What changed: (1) Added renderContextNotice to ui/src/ui/views/chat.ts using totalTokens as used, with an inline SVG warning icon; (2) added .context-notice CSS block to ui/src/styles/chat/layout.css as a non-blocking inline banner with progressive amber→red coloring; (3) changed handleTerminalChatEvent in ui/src/ui/app-gateway.ts to unconditionally call loadSessions() after every final chat event.
  • What did NOT change: No gateway logic, no session storage, no token accounting, no model/provider code touched.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • UI / DX

Linked Issue/PR

User-visible / Behavior Changes

  • The chat tab now shows a compact amber→red inline warning banner when the active session's context usage is ≥85% of the context window. The notice shows X% context used and used / limit token counts.
  • Token stats (totalTokens, contextTokens) in the session data are now refreshed after every completed chat turn, so the context notice appears and updates in real-time without a page reload.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No — sessions.list was already called post-chat for /new commands; it is now called for all final events (same endpoint, same parameters)
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: Linux (WSL2 repro environment)
  • Runtime/container: Node 22
  • Model/provider: any

Steps

  1. Open the Control UI chat tab with a long-running session (>85% context)
  2. Send a normal message (not /new)
  3. After the reply: the context banner should appear immediately
  4. Refresh the page: banner should show correct values (not usage > window)

Expected

  • Context notice appears as an inline compact banner after each reply
  • Values show totalTokens / contextTokens where totalTokens <= contextTokens

Actual (before fix)

Evidence

  • All 812 test files pass (pnpm test)
  • pnpm check passes (oxlint + format)

Human Verification (required)

  • Verified scenarios: lint passes, all tests pass, TypeScript types checked
  • Edge cases checked: session with no totalTokens/contextTokens → notice returns nothing (no render); ratio < 0.85 → nothing; ratio > 1.0 → clamped to 100%
  • Thanks @martinfrancois checked the fix
  • What you did not verify: only tested related issue

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 commit 9d6599072
  • Files/config to restore: ui/src/ui/views/chat.ts, ui/src/ui/app-gateway.ts, ui/src/styles/chat/layout.css
  • Known bad symptoms: extra sessions.list call after each chat turn (very cheap read, no side effects)

Risks and Mitigations

  • Risk: loadSessions() now fires after every final chat event instead of only after /new. This adds one lightweight gateway request per turn.
    • Mitigation: loadSessions already has a guard (if (state.sessionsLoading) return) to prevent concurrent calls. The request is cheap (just reads the in-memory session store).

* Providers: add built-in AIPing provider support

* Docs: clarify AIPing router-param usage

* Onboard: add AIPing routing presets

* Docs: add AIPing API key portal link

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
@haoruilee haoruilee changed the title fix(ui): add context-notice component and refresh token stats after every chat turn, solve #45230 and #45034 fix(ui): add context-notice component and refresh token stats after every chat turn, solve #45230, #45034, #45192 Mar 13, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 13, 2026

Greptile Summary

This PR fixes two related bugs in the Control UI chat tab: (1) the context-usage notice displayed impossible values (usage > window) on page refresh because it was using cumulative inputTokens instead of per-turn totalTokens, and (2) token stats never updated in real-time after normal chat turns because loadSessions() was only called for /new/reset commands.

Changes:

  • app-gateway.ts: handleTerminalChatEvent now calls loadSessions() after every state === "final" event unconditionally, instead of only when the run ID was registered in refreshSessionsAfterChat. The set cleanup logic is preserved for /new-style runs.
  • chat.ts: Added renderContextNotice using totalTokens (current-turn context window usage) and contextTokens (the model's max window) with a progressive amber→red color lerp at 85–95%+ usage. Helper formatTokensCompact added for readable token display.
  • layout.css: Added the missing .context-notice CSS block using CSS custom properties and position: relative so the banner is an inline, non-overlaying element.

All edge cases are handled correctly: undefined session, zero limit, ratio > 1.0 (clamped to 100%), and ratio < 0.85 (returns nothing). The extra loadSessions() call per turn is a cheap read-only gateway request with an existing guard against concurrent calls.

Confidence Score: 4/5

  • This PR is safe to merge — it fixes two UI-only bugs with minimal scope and no changes to gateway logic, session storage, or token accounting.
  • The changes are well-scoped and address clearly documented root causes. Edge cases (null session, zero limit, ratio > 1.0) are all handled. The additional loadSessions() call per final chat turn is a cheap read-only call protected by an existing concurrency guard. The score is 4 rather than 5 primarily because the context notice has not been verified in a live browser render (acknowledged in the PR), and the extra loadSessions() call adds a small amount of per-turn network traffic that wasn't there before.
  • No files require special attention, though a quick smoke-test of the context notice banner in a real browser with a near-full context session would be prudent before merging.

Last reviewed commit: 67051c7

@cursor cursor Bot force-pushed the cursor/issues-45230-45034-root-cause-9f24 branch from 67051c7 to 82a9321 Compare March 13, 2026 16:41
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 82a932114b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ui/src/ui/app-gateway.ts
@cursor cursor Bot force-pushed the cursor/issues-45230-45034-root-cause-9f24 branch 2 times, most recently from 352291e to 7a526cb Compare March 14, 2026 05:57
… headers and adding Bearer auth (#4)

* fix(minimax): honor authHeader=true by injecting Bearer auth for anthropic-compatible endpoints

* fix(minimax): suppress anthropic-beta headers to restore token-by-token streaming

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
@martinfrancois
Copy link
Copy Markdown
Contributor

martinfrancois commented Mar 14, 2026

I also have the same issue (#45230) with 2026.3.13 and can confirm this does fix the issue.

@cursor cursor Bot force-pushed the cursor/issues-45230-45034-root-cause-9f24 branch 2 times, most recently from 768305a to cc5258b Compare March 14, 2026 15:43
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cc5258b115

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ui/src/ui/views/chat.ts Outdated
@cursor cursor Bot force-pushed the cursor/issues-45230-45034-root-cause-9f24 branch 2 times, most recently from 744eaf3 to 263dbff Compare March 15, 2026 03:06
@haoruilee haoruilee changed the title fix(ui): add context-notice component and refresh token stats after every chat turn, solve #45230, #45034, #45192 fix(ui): add context-notice component and refresh token stats after every chat turn, solve #45230, #45034, #45192, #45794 Mar 15, 2026
@haoruilee
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@cursor cursor Bot force-pushed the cursor/issues-45230-45034-root-cause-9f24 branch from 263dbff to df1a366 Compare March 15, 2026 15:22
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df1a366596

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ui/src/ui/app-gateway.ts Outdated
Comment thread ui/src/ui/views/chat.ts Outdated
@cursor cursor Bot force-pushed the cursor/issues-45230-45034-root-cause-9f24 branch from df1a366 to 87ef55a Compare March 15, 2026 15:54
@cursor cursor Bot force-pushed the cursor/issues-45230-45034-root-cause-9f24 branch from 48c7c34 to ca4b4ba Compare March 16, 2026 02:58
@cursor cursor Bot force-pushed the cursor/issues-45230-45034-root-cause-9f24 branch from ca4b4ba to 6a94643 Compare March 16, 2026 03:09
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c6fc1195b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ui/src/ui/views/chat.ts Outdated
Comment thread ui/src/ui/app-gateway.ts Outdated
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M and removed size: S labels Mar 19, 2026
@cursor cursor Bot requested a review from a team as a code owner March 19, 2026 17:14
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation commands Command implementations agents Agent runtime and tooling size: XL and removed size: M labels Mar 19, 2026
…or/issues-45230-45034-root-cause-9f24

Resolve conflicts: use model-auth-env re-exports; keep pinned-session in
sessions list; merge GatewaySessionRow fields; combine context-notice logic
and browser tests with upstream theme-var coverage.

Co-authored-by: 0x4C33 <haoruilee@users.noreply.github.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: adde5c17b4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

};
}

export async function resolveImplicitProviders(params: {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Badge Remove duplicate resolveImplicitProviders declaration

This commit adds a second exported resolveImplicitProviders implementation while one already exists later in the same module, so the file now has duplicate exported function declarations. In ESM this is a duplicate identifier error at module load time, which prevents this provider-config module from importing and breaks commands that rely on model/provider resolution.

Useful? React with 👍 / 👎.

| "qwen-portal"
| "xai-api-key"
| "mistral-api-key"
| "aiping-api-key"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Wire new aiping-api-key choice to an auth handler

Adding "aiping-api-key" to built-in auth choices exposes a new onboarding path, but there is no corresponding runtime handler for that choice in the auth-choice flow (API-provider handling remains limited, and no bundled provider auth choice for AIPing is present). As a result, openclaw onboard --auth-choice aiping-api-key falls through without applying credentials/default model, so the newly advertised flow is non-functional.

Useful? React with 👍 / 👎.

@BunsDev
Copy link
Copy Markdown
Member

BunsDev commented Apr 25, 2026

Closing as superseded by #71297 for the Control UI chat context-warning/session-refresh portion. #71297 resolves the current version of the same stale context notice failure with a smaller scoped patch: live session metadata is applied immediately from gateway events, overlapping session reloads are coalesced, stale totals are hidden, the context notice layout is covered by current styles, and the compact recommendation CTA is included.

This PR also contains broad unrelated provider/config/test churn, so it should not remain the canonical path for the Control UI chat fix. Any still-needed non-UI changes should be split into separate PRs.

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

Labels

agents Agent runtime and tooling app: web-ui App: web-ui commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime size: XL

Projects

None yet

4 participants