Skip to content

Commit a44842f

Browse files
fix: include reserved output tokens in task header percentage calculation (#11034)
Co-authored-by: Roo Code <[email protected]>
1 parent c6d0306 commit a44842f

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

webview-ui/src/components/chat/TaskHeader.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ const TaskHeader = ({
104104
const textRef = useRef<HTMLDivElement>(null)
105105
const contextWindow = model?.contextWindow || 1
106106

107+
// Calculate maxTokens (reserved for output) once for reuse in percentage and tooltip
108+
const maxTokens = useMemo(
109+
() =>
110+
model
111+
? getModelMaxOutputTokens({
112+
modelId,
113+
model,
114+
settings: apiConfiguration,
115+
})
116+
: 0,
117+
[model, modelId, apiConfiguration],
118+
)
119+
const reservedForOutput = maxTokens || 0
120+
107121
// Detect if this task had any browser session activity so we can show a grey globe when inactive
108122
const browserSessionStartIndex = useMemo(() => {
109123
const msgs = clineMessages || []
@@ -226,14 +240,6 @@ const TaskHeader = ({
226240
<div className="flex items-center gap-2">
227241
<StandardTooltip
228242
content={(() => {
229-
const maxTokens = model
230-
? getModelMaxOutputTokens({
231-
modelId,
232-
model,
233-
settings: apiConfiguration,
234-
})
235-
: 0
236-
const reservedForOutput = maxTokens || 0
237243
const availableSpace = contextWindow - (contextTokens || 0) - reservedForOutput
238244

239245
return (
@@ -276,7 +282,9 @@ const TaskHeader = ({
276282
sideOffset={8}>
277283
<span className="flex items-center gap-1.5">
278284
{(() => {
279-
const percentage = Math.round(((contextTokens || 0) / contextWindow) * 100)
285+
const percentage = Math.round(
286+
(((contextTokens || 0) + reservedForOutput) / contextWindow) * 100,
287+
)
280288
return (
281289
<>
282290
<CircularProgress percentage={percentage} />
@@ -397,15 +405,7 @@ const TaskHeader = ({
397405
<ContextWindowProgress
398406
contextWindow={contextWindow}
399407
contextTokens={contextTokens || 0}
400-
maxTokens={
401-
model
402-
? getModelMaxOutputTokens({
403-
modelId,
404-
model,
405-
settings: apiConfiguration,
406-
})
407-
: undefined
408-
}
408+
maxTokens={maxTokens || undefined}
409409
/>
410410
{condenseButton}
411411
</div>

0 commit comments

Comments
 (0)