web UI: fix context notice using accumulated inputTokens instead of prompt snapshot (#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
This commit is contained in:
Val Alexander
2026-03-21 11:16:32 -05:00
committed by GitHub
parent 15fd11032d
commit 7c520cc0ea
2 changed files with 29 additions and 1 deletions

View File

@@ -312,6 +312,34 @@ describe("chat view", () => {
expect(container.textContent).not.toContain("757.3k / 200k");
});
it("hides the context notice when totalTokens is missing even if inputTokens is high", () => {
const container = document.createElement("div");
render(
renderChat(
createProps({
sessions: {
ts: 0,
path: "",
count: 1,
defaults: { modelProvider: "openai", model: "gpt-5", contextTokens: 200_000 },
sessions: [
{
key: "main",
kind: "direct",
updatedAt: null,
inputTokens: 500_000,
contextTokens: 200_000,
},
],
},
}),
),
container,
);
expect(container.textContent).not.toContain("context used");
});
it("uses the assistant avatar URL for the welcome state when the identity avatar is only initials", () => {
const container = document.createElement("div");
render(

View File

@@ -255,7 +255,7 @@ function renderContextNotice(
session: GatewaySessionRow | undefined,
defaultContextTokens: number | null,
) {
const used = session?.totalTokens ?? session?.inputTokens ?? 0;
const used = session?.totalTokens ?? 0;
const limit = session?.contextTokens ?? defaultContextTokens ?? 0;
if (!used || !limit) {
return nothing;