From 5f8d23c60bae72cde1f281a24312813211c39140 Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Thu, 8 Jan 2026 15:48:39 -0500 Subject: [PATCH] fix(cliproxy): add NaN/Infinity and empty string validation - Add Number.isFinite() check to reject NaN/Infinity budgets - Add explicit empty string handling before level validation --- src/cliproxy/thinking-validator.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/cliproxy/thinking-validator.ts b/src/cliproxy/thinking-validator.ts index 747cd497..9414eae5 100644 --- a/src/cliproxy/thinking-validator.ts +++ b/src/cliproxy/thinking-validator.ts @@ -105,6 +105,15 @@ export function validateThinking( ): ThinkingValidationResult { const thinking = getModelThinkingSupport(provider, modelId); + // Handle empty string explicitly + if (typeof value === 'string' && value.trim() === '') { + return { + valid: false, + value: 'off', + warning: 'Empty thinking value not allowed. Using "off".', + }; + } + // Handle off/none/disabled values if (typeof value === 'string') { const normalizedValue = value.toLowerCase().trim(); @@ -198,6 +207,15 @@ function validateBudgetThinking( budget = value; } + // Reject NaN/Infinity budgets + if (!Number.isFinite(budget)) { + return { + valid: false, + value: min || THINKING_BUDGET_DEFAULT_MIN, + warning: `Budget must be a finite number. Using minimum ${min || THINKING_BUDGET_DEFAULT_MIN}.`, + }; + } + // Reject negative budgets if (budget < THINKING_BUDGET_MIN) { return {