TypeScript
fix(web): changing a project's model no longer keeps the old model's options (#16581)
yaacovcorcosf298bd4f9c51
diff --git a/apps/web/src/components/settings/scopedSettings.test.ts b/apps/web/src/components/settings/scopedSettings.test.tsindex 416eaaa82cc..3bad4e94a6f 100644--- a/apps/web/src/components/settings/scopedSettings.test.ts+++ b/apps/web/src/components/settings/scopedSettings.test.ts@@ -764,3 +764,59 @@ it("routes legacy model preference keys exclusively to the selected environment"},]);});++describe("model selection patches at project scope", () => {+ const codex = ProviderInstanceId.make("codex");+ const claude = ProviderInstanceId.make("claudeAgent");+ const saved = {+ instanceId: codex,+ model: "gpt-5.6",+ options: [{ id: "reasoningEffort", value: "high" }],+ };+ const customized = environment("Server", {+ settings: {+ projectSettingsOverrides: {+ [projectId]: {+ defaultModelSelection: saved,+ sourceControlWriterModelSelection: saved,+ reviewGuideModelSelection: saved,+ textGenerationModelSelection: saved,+ },+ },+ },+ });++ it("replaces old options when changing model selections", () => {+ const plan = planScopedSettingsPatch(checkout, [customized], {+ defaultModelSelection: { instanceId: claude, model: "claude-opus-4-8" },+ sourceControlWriterModelSelection: { instanceId: codex, model: "gpt-5.6-mini" },+ reviewGuideModelSelection: { instanceId: codex, model: "gpt-5.6-mini" },+ textGenerationModelSelection: { instanceId: claude, model: "claude-sonnet-4-6" },+ });+ expect(plan.serverWrites[0]?.patch.projectSettingsOverrides?.[projectId]).toEqual({+ defaultModelSelection: { instanceId: claude, model: "claude-opus-4-8" },+ sourceControlWriterModelSelection: { instanceId: codex, model: "gpt-5.6-mini" },+ reviewGuideModelSelection: { instanceId: codex, model: "gpt-5.6-mini" },+ textGenerationModelSelection: { instanceId: claude, model: "claude-sonnet-4-6" },+ });+ });++ it("completes partial text-generation selections without retaining old options", () => {+ const modelPlan = planScopedSettingsPatch(checkout, [customized], {+ textGenerationModelSelection: { model: "gpt-5.6-mini" },+ });+ expect(+ modelPlan.serverWrites[0]?.patch.projectSettingsOverrides?.[projectId]+ ?.textGenerationModelSelection,+ ).toEqual({ instanceId: codex, model: "gpt-5.6-mini" });++ const options = [{ id: "reasoningEffort", value: "low" }];+ const optionsPlan = planScopedSettingsPatch(checkout, [customized], {+ textGenerationModelSelection: { options },+ });+ expect(+ optionsPlan.serverWrites[0]?.patch.projectSettingsOverrides?.[projectId]+ ?.textGenerationModelSelection,+ ).toEqual({ ...saved, options });+ });+});diff --git a/apps/web/src/components/settings/scopedSettings.ts b/apps/web/src/components/settings/scopedSettings.tsindex f86a74b5e21..982a9e5c5c6 100644--- a/apps/web/src/components/settings/scopedSettings.ts+++ b/apps/web/src/components/settings/scopedSettings.ts@@ -227,7 +227,7 @@ export function planScopedSettingsPatch(// so complete the patch from the target's effective value.const effective = resolveProjectSettings(settings, projectId).settings;const next: Record<string, unknown> = { ...current };- for (const [key, value] of Object.entries(serverPatch)) {+ for (const [key, value] of Object.entries<unknown>(serverPatch)) {if (key === "worktreeCleanup" && serverPatch.worktreeCleanup?.mode === "custom") {next[key] = {mode: "custom",@@ -247,7 +247,20 @@ export function planScopedSettingsPatch(delete next[key];continue;}- const base = effective[key as keyof ServerSettings];+ const base: unknown = effective[key as keyof ServerSettings];+ // A new model must not inherit the previous model's options.+ if (+ isPlainObject(value) &&+ isPlainObject(base) &&+ (key === "defaultModelSelection" ||+ key === "sourceControlWriterModelSelection" ||+ key === "reviewGuideModelSelection" ||+ key === "textGenerationModelSelection") &&+ (value.instanceId !== undefined || value.model !== undefined)+ ) {+ next[key] = { instanceId: base.instanceId, model: base.model, ...value };+ continue;+ }next[key] =isPlainObject(value) && isPlainObject(base) ? { ...base, ...value } : value;}