From e914fe977895c7d036e6cd81f48d833ac29bb9f7 Mon Sep 17 00:00:00 2001 From: Tam Nhu Tran Date: Thu, 12 Feb 2026 13:34:17 +0700 Subject: [PATCH] fix(cliproxy): fix thinking off regression and composite error handling - P1: Thinking "off" now fully disables all tier thinking When thinkingValue === 'off' AND no per-tier config, return early Preserves behavior for "off" with per-tier config (skips main, processes tiers) Fixes regression where tier defaults were applied despite explicit off setting - P2: Handle composite-create thrown errors in POST route Wrap createCompositeVariant() in try/catch Returns 400 instead of generic 500 when function throws (e.g., legacy mode) --- src/cliproxy/config/thinking-config.ts | 19 ++++++++++++++----- src/web-server/routes/variant-routes.ts | 8 +++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/cliproxy/config/thinking-config.ts b/src/cliproxy/config/thinking-config.ts index 36d8a382..cda3a7ee 100644 --- a/src/cliproxy/config/thinking-config.ts +++ b/src/cliproxy/config/thinking-config.ts @@ -152,11 +152,20 @@ export function applyThinkingConfig( } thinkingValue = validation.value; - // Track whether to apply to main model (skip if validation says off) - const applyToMainModel = thinkingValue !== 'off'; - - // Apply thinking suffix to main model (only if not off) - if (applyToMainModel && result.ANTHROPIC_MODEL) { + // P1 FIX: If validation says 'off' AND no per-tier thinking config, skip ALL processing + // This distinguishes between: + // 1. "off" with no per-tier config → no thinking anywhere + // 2. "off" with per-tier config → skip main model, process tiers with their own values + if (thinkingValue === 'off') { + const hasPerTierThinking = + compositeTierThinking && + Object.values(compositeTierThinking).some((v) => v !== undefined && v !== 'off'); + if (!hasPerTierThinking) { + return result; // No thinking to apply anywhere + } + // Otherwise, continue to process tiers with their own config (skip main model) + } else if (result.ANTHROPIC_MODEL) { + // Apply thinking suffix to main model (only if not off) result.ANTHROPIC_MODEL = applyThinkingSuffix(result.ANTHROPIC_MODEL, thinkingValue); } diff --git a/src/web-server/routes/variant-routes.ts b/src/web-server/routes/variant-routes.ts index 4221d5ea..209e0dac 100644 --- a/src/web-server/routes/variant-routes.ts +++ b/src/web-server/routes/variant-routes.ts @@ -138,7 +138,13 @@ router.post('/', (req: Request, res: Response): void => { return; } - const result = createCompositeVariant({ name, defaultTier: default_tier, tiers }); + let result; + try { + result = createCompositeVariant({ name, defaultTier: default_tier, tiers }); + } catch (error) { + res.status(400).json({ error: (error as Error).message }); + return; + } if (!result.success) { res.status(409).json({ error: result.error });