From a39ded0b1a0e589046db204030bf171d94fb1ce7 Mon Sep 17 00:00:00 2001 From: Tam Nhu Tran Date: Tue, 7 Apr 2026 16:56:07 -0400 Subject: [PATCH] fix(cliproxy): preserve saved codex model selections - stop the Codex free-plan compatibility guard from rewriting codex.settings.json - keep saved dashboard selections intact and rely on runtime fallback when needed - update reconcile coverage to lock the non-mutating behavior in place --- src/cliproxy/codex-plan-compatibility.ts | 10 +++------- .../codex-plan-compatibility-reconcile.test.ts | 12 ++++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/cliproxy/codex-plan-compatibility.ts b/src/cliproxy/codex-plan-compatibility.ts index ab524926..de81aaac 100644 --- a/src/cliproxy/codex-plan-compatibility.ts +++ b/src/cliproxy/codex-plan-compatibility.ts @@ -3,7 +3,6 @@ import { getProviderCatalog } from './model-catalog'; import { fetchCodexQuota } from './quota-fetcher-codex'; import { getCachedQuota, setCachedQuota } from './quota-response-cache'; import type { CodexQuotaResult } from './quota-types'; -import { updateSettingsModel } from './services/variant-settings'; import { info, warn } from '../utils/ui'; export type CodexPlanType = CodexQuotaResult['planType']; @@ -146,7 +145,7 @@ export async function reconcileCodexModelForActivePlan( }, deps: CodexPlanCompatibilityDeps = {} ): Promise { - const { settingsPath, currentModel, verbose } = options; + const { currentModel, verbose } = options; if (!currentModel) return; const fallbackModel = getFreePlanFallbackCodexModel(currentModel); @@ -175,13 +174,10 @@ export async function reconcileCodexModelForActivePlan( } if (quota.planType === 'free') { - updateSettingsModel(settingsPath, fallbackModel, 'codex', { - rewriteHaikuModel: (haikuModel) => getFreePlanFallbackCodexModel(haikuModel) ?? haikuModel, - }); console.error( formatInfo( - `Codex free plan detected. Switched unsupported model "${normalizeCodexModelId(currentModel)}" ` + - `to "${fallbackModel}".` + `Codex free plan detected. Keeping saved model "${normalizeCodexModelId(currentModel)}" in settings; ` + + `runtime requests will fall back to "${fallbackModel}" when needed.` ) ); return; diff --git a/tests/unit/cliproxy/codex-plan-compatibility-reconcile.test.ts b/tests/unit/cliproxy/codex-plan-compatibility-reconcile.test.ts index b58148e2..934c7d13 100644 --- a/tests/unit/cliproxy/codex-plan-compatibility-reconcile.test.ts +++ b/tests/unit/cliproxy/codex-plan-compatibility-reconcile.test.ts @@ -45,7 +45,7 @@ async function importCompatibilityModule(cacheTag: string) { const identity = (message: string) => message; describe('codex plan compatibility reconcile', () => { - it('repairs stale paid-only Codex settings for free-plan accounts before launch', async () => { + it('keeps saved Codex settings intact and warns about runtime fallback for free-plan accounts', async () => { const { tmpDir, settingsPath } = createCodexSettingsFixture('gpt-5.3-codex-spark'); const errorSpy = spyOn(console, 'error').mockImplementation(() => {}); @@ -76,12 +76,12 @@ describe('codex plan compatibility reconcile', () => { const repaired = JSON.parse(fs.readFileSync(settingsPath, 'utf-8')) as { env: Record; }; - expect(repaired.env.ANTHROPIC_MODEL).toBe('gpt-5-codex'); - expect(repaired.env.ANTHROPIC_DEFAULT_OPUS_MODEL).toBe('gpt-5-codex'); - expect(repaired.env.ANTHROPIC_DEFAULT_SONNET_MODEL).toBe('gpt-5-codex'); - expect(repaired.env.ANTHROPIC_DEFAULT_HAIKU_MODEL).toBe('gpt-5-codex-mini'); + expect(repaired.env.ANTHROPIC_MODEL).toBe('gpt-5.3-codex'); + expect(repaired.env.ANTHROPIC_DEFAULT_OPUS_MODEL).toBe('gpt-5.3-codex'); + expect(repaired.env.ANTHROPIC_DEFAULT_SONNET_MODEL).toBe('gpt-5.3-codex'); + expect(repaired.env.ANTHROPIC_DEFAULT_HAIKU_MODEL).toBe('gpt-5.3-codex-spark'); expect(errorSpy).toHaveBeenCalledWith( - 'Codex free plan detected. Switched unsupported model "gpt-5.3-codex" to "gpt-5-codex".' + 'Codex free plan detected. Keeping saved model "gpt-5.3-codex" in settings; runtime requests will fall back to "gpt-5-codex" when needed.' ); } finally { fs.rmSync(tmpDir, { recursive: true, force: true });