Skip to content

Commit 037b4cb

Browse files
committed
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. Made-with: Cursor
1 parent 15fd110 commit 037b4cb

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

ui/src/ui/views/chat.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,34 @@ describe("chat view", () => {
312312
expect(container.textContent).not.toContain("757.3k / 200k");
313313
});
314314

315+
it("hides the context notice when totalTokens is missing even if inputTokens is high", () => {
316+
const container = document.createElement("div");
317+
render(
318+
renderChat(
319+
createProps({
320+
sessions: {
321+
ts: 0,
322+
path: "",
323+
count: 1,
324+
defaults: { modelProvider: "openai", model: "gpt-5", contextTokens: 200_000 },
325+
sessions: [
326+
{
327+
key: "main",
328+
kind: "direct",
329+
updatedAt: null,
330+
inputTokens: 500_000,
331+
contextTokens: 200_000,
332+
},
333+
],
334+
},
335+
}),
336+
),
337+
container,
338+
);
339+
340+
expect(container.textContent).not.toContain("context used");
341+
});
342+
315343
it("uses the assistant avatar URL for the welcome state when the identity avatar is only initials", () => {
316344
const container = document.createElement("div");
317345
render(

ui/src/ui/views/chat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ function renderContextNotice(
255255
session: GatewaySessionRow | undefined,
256256
defaultContextTokens: number | null,
257257
) {
258-
const used = session?.totalTokens ?? session?.inputTokens ?? 0;
258+
const used = session?.totalTokens ?? 0;
259259
const limit = session?.contextTokens ?? defaultContextTokens ?? 0;
260260
if (!used || !limit) {
261261
return nothing;

0 commit comments

Comments
 (0)