From 39fb5a87c2e0e98086ab68ae818b31c30e824a0d Mon Sep 17 00:00:00 2001 From: Roo Code Date: Wed, 28 Jan 2026 03:48:14 +0000 Subject: [PATCH] fix: include reserved output tokens in task header percentage calculation --- webview-ui/src/components/chat/TaskHeader.tsx | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/webview-ui/src/components/chat/TaskHeader.tsx b/webview-ui/src/components/chat/TaskHeader.tsx index 3ced8740260..8948302ce17 100644 --- a/webview-ui/src/components/chat/TaskHeader.tsx +++ b/webview-ui/src/components/chat/TaskHeader.tsx @@ -104,6 +104,20 @@ const TaskHeader = ({ const textRef = useRef(null) const contextWindow = model?.contextWindow || 1 + // Calculate maxTokens (reserved for output) once for reuse in percentage and tooltip + const maxTokens = useMemo( + () => + model + ? getModelMaxOutputTokens({ + modelId, + model, + settings: apiConfiguration, + }) + : 0, + [model, modelId, apiConfiguration], + ) + const reservedForOutput = maxTokens || 0 + // Detect if this task had any browser session activity so we can show a grey globe when inactive const browserSessionStartIndex = useMemo(() => { const msgs = clineMessages || [] @@ -226,14 +240,6 @@ const TaskHeader = ({
{ - const maxTokens = model - ? getModelMaxOutputTokens({ - modelId, - model, - settings: apiConfiguration, - }) - : 0 - const reservedForOutput = maxTokens || 0 const availableSpace = contextWindow - (contextTokens || 0) - reservedForOutput return ( @@ -276,7 +282,9 @@ const TaskHeader = ({ sideOffset={8}> {(() => { - const percentage = Math.round(((contextTokens || 0) / contextWindow) * 100) + const percentage = Math.round( + (((contextTokens || 0) + reservedForOutput) / contextWindow) * 100, + ) return ( <> @@ -397,15 +405,7 @@ const TaskHeader = ({ {condenseButton}