From 74dcedd35b8e0101c5fa8ce012195bb46f1c9d1e Mon Sep 17 00:00:00 2001 From: Daniel <57051444+daniel-lxs@users.noreply.github.com> Date: Thu, 15 May 2025 06:22:07 -0500 Subject: [PATCH] Fix incorrect reserved tokens calculation on OpenRouter (#3626) fix: improve token reservation logic in calculateTokenDistribution --- webview-ui/src/utils/model-utils.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webview-ui/src/utils/model-utils.ts b/webview-ui/src/utils/model-utils.ts index 29adb11a96..255c25bedb 100644 --- a/webview-ui/src/utils/model-utils.ts +++ b/webview-ui/src/utils/model-utils.ts @@ -100,7 +100,8 @@ export const calculateTokenDistribution = ( // Get the actual max tokens value from the model // If maxTokens is valid, use it, otherwise reserve 20% of the context window as a default - const reservedForOutput = maxTokens && maxTokens > 0 ? maxTokens : Math.ceil(safeContextWindow * 0.2) + const reservedForOutput = + maxTokens && maxTokens > 0 && maxTokens !== safeContextWindow ? maxTokens : Math.ceil(safeContextWindow * 0.2) // Calculate sizes directly without buffer display const availableSize = Math.max(0, safeContextWindow - safeContextTokens - reservedForOutput)