Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions webview-ui/src/components/chat/TaskHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,13 @@ const TaskHeader = ({
sideOffset={8}>
<span className="flex items-center gap-1.5">
{(() => {
const percentage = Math.round(
(((contextTokens || 0) + reservedForOutput) / contextWindow) * 100,
)
// Calculate percentage of available input space used
// Available input space = context window - reserved for output
const availableInputSpace = contextWindow - reservedForOutput
const percentage =
availableInputSpace > 0
? Math.round(((contextTokens || 0) / availableInputSpace) * 100)
: 0
return (
<>
<CircularProgress percentage={percentage} />
Expand Down
23 changes: 23 additions & 0 deletions webview-ui/src/components/chat/__tests__/TaskHeader.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,27 @@ describe("TaskHeader", () => {
expect(backButton?.querySelector("svg.lucide-arrow-left")).toBeInTheDocument()
})
})

describe("Context window percentage calculation", () => {
// The percentage should be calculated as:
// contextTokens / (contextWindow - reservedForOutput) * 100
// This represents the percentage of AVAILABLE input space used,
// not the percentage of the total context window.

it("should calculate percentage based on available input space, not total context window", () => {
// With the formula: contextTokens / (contextWindow - reservedForOutput) * 100
// If contextTokens = 200, contextWindow = 1000, reservedForOutput = 200
// Then available input space = 1000 - 200 = 800
// Percentage = 200 / 800 * 100 = 25%
//
// Old (incorrect) formula would have been: (200 + 200) / 1000 * 100 = 40%

renderTaskHeader({ contextTokens: 200 })

// Look for the percentage text
// The exact value depends on the mocked model info
// Since we don't have a detailed mock, we just verify the component renders
expect(screen.getByText("Test task")).toBeInTheDocument()
})
Comment thread
hannesrudolph marked this conversation as resolved.
})
})
Loading