From 5b9f3fb2e97ee8b9e8cd5b22731ceec1341b2079 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Mar 2026 23:17:38 +0000 Subject: [PATCH] fix: fall back to target provider's default model on provider switch When switching providers (e.g., Codex -> Claude) without explicitly specifying a model, the thread's existing model slug (a Codex slug like 'gpt-5-codex') was passed to the new provider's adapter. The Claude SDK does not understand Codex model names, causing failures. Now, when a provider is explicitly requested and differs from the current provider, the code falls back to DEFAULT_MODEL_BY_PROVIDER for the target provider instead of carrying over the thread's existing model. Co-authored-by: Julius Marminge --- .../orchestration/Layers/ProviderCommandReactor.test.ts | 2 +- .../src/orchestration/Layers/ProviderCommandReactor.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts b/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts index 2a0a3586d..d104c4d39 100644 --- a/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts +++ b/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts @@ -416,7 +416,7 @@ describe("ProviderCommandReactor", () => { expect(harness.startSession.mock.calls[0]?.[1]).toMatchObject({ provider: "claudeAgent", cwd: "/tmp/provider-project", - model: "gpt-5-codex", + model: "claude-sonnet-4-6", runtimeMode: "approval-required", }); diff --git a/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts b/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts index 76258f303..d6c931092 100644 --- a/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts +++ b/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts @@ -1,6 +1,7 @@ import { type ChatAttachment, CommandId, + DEFAULT_MODEL_BY_PROVIDER, EventId, type OrchestrationEvent, type ProviderModelOptions, @@ -211,7 +212,11 @@ const make = Effect.gen(function* () { ? thread.session.providerName : undefined; const preferredProvider: ProviderKind | undefined = options?.provider ?? currentProvider; - const desiredModel = options?.model ?? thread.model; + const providerIsChanging = + options?.provider !== undefined && options.provider !== currentProvider; + const desiredModel = + options?.model ?? + (providerIsChanging ? DEFAULT_MODEL_BY_PROVIDER[options.provider!] : thread.model); const effectiveCwd = resolveThreadWorkspaceCwd({ thread, projects: readModel.projects,