Skip to content

Commit f298bd4

Browse files
yaacovcorcosclaudejuliusmarminge
authored
fix(web): changing a project's model no longer keeps the old model's options (pingdotgg#16581)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent 6567ffd commit f298bd4

2 files changed

Lines changed: 71 additions & 2 deletions

File tree

‎apps/web/src/components/settings/scopedSettings.test.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,3 +764,59 @@ it("routes legacy model preference keys exclusively to the selected environment"
764764
},
765765
]);
766766
});
767+
768+
describe("model selection patches at project scope", () => {
769+
const codex = ProviderInstanceId.make("codex");
770+
const claude = ProviderInstanceId.make("claudeAgent");
771+
const saved = {
772+
instanceId: codex,
773+
model: "gpt-5.6",
774+
options: [{ id: "reasoningEffort", value: "high" }],
775+
};
776+
const customized = environment("Server", {
777+
settings: {
778+
projectSettingsOverrides: {
779+
[projectId]: {
780+
defaultModelSelection: saved,
781+
sourceControlWriterModelSelection: saved,
782+
reviewGuideModelSelection: saved,
783+
textGenerationModelSelection: saved,
784+
},
785+
},
786+
},
787+
});
788+
789+
it("replaces old options when changing model selections", () => {
790+
const plan = planScopedSettingsPatch(checkout, [customized], {
791+
defaultModelSelection: { instanceId: claude, model: "claude-opus-4-8" },
792+
sourceControlWriterModelSelection: { instanceId: codex, model: "gpt-5.6-mini" },
793+
reviewGuideModelSelection: { instanceId: codex, model: "gpt-5.6-mini" },
794+
textGenerationModelSelection: { instanceId: claude, model: "claude-sonnet-4-6" },
795+
});
796+
expect(plan.serverWrites[0]?.patch.projectSettingsOverrides?.[projectId]).toEqual({
797+
defaultModelSelection: { instanceId: claude, model: "claude-opus-4-8" },
798+
sourceControlWriterModelSelection: { instanceId: codex, model: "gpt-5.6-mini" },
799+
reviewGuideModelSelection: { instanceId: codex, model: "gpt-5.6-mini" },
800+
textGenerationModelSelection: { instanceId: claude, model: "claude-sonnet-4-6" },
801+
});
802+
});
803+
804+
it("completes partial text-generation selections without retaining old options", () => {
805+
const modelPlan = planScopedSettingsPatch(checkout, [customized], {
806+
textGenerationModelSelection: { model: "gpt-5.6-mini" },
807+
});
808+
expect(
809+
modelPlan.serverWrites[0]?.patch.projectSettingsOverrides?.[projectId]
810+
?.textGenerationModelSelection,
811+
).toEqual({ instanceId: codex, model: "gpt-5.6-mini" });
812+
813+
const options = [{ id: "reasoningEffort", value: "low" }];
814+
const optionsPlan = planScopedSettingsPatch(checkout, [customized], {
815+
textGenerationModelSelection: { options },
816+
});
817+
expect(
818+
optionsPlan.serverWrites[0]?.patch.projectSettingsOverrides?.[projectId]
819+
?.textGenerationModelSelection,
820+
).toEqual({ ...saved, options });
821+
});
822+
});

‎apps/web/src/components/settings/scopedSettings.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export function planScopedSettingsPatch(
227227
// so complete the patch from the target's effective value.
228228
const effective = resolveProjectSettings(settings, projectId).settings;
229229
const next: Record<string, unknown> = { ...current };
230-
for (const [key, value] of Object.entries(serverPatch)) {
230+
for (const [key, value] of Object.entries<unknown>(serverPatch)) {
231231
if (key === "worktreeCleanup" && serverPatch.worktreeCleanup?.mode === "custom") {
232232
next[key] = {
233233
mode: "custom",
@@ -247,7 +247,20 @@ export function planScopedSettingsPatch(
247247
delete next[key];
248248
continue;
249249
}
250-
const base = effective[key as keyof ServerSettings];
250+
const base: unknown = effective[key as keyof ServerSettings];
251+
// A new model must not inherit the previous model's options.
252+
if (
253+
isPlainObject(value) &&
254+
isPlainObject(base) &&
255+
(key === "defaultModelSelection" ||
256+
key === "sourceControlWriterModelSelection" ||
257+
key === "reviewGuideModelSelection" ||
258+
key === "textGenerationModelSelection") &&
259+
(value.instanceId !== undefined || value.model !== undefined)
260+
) {
261+
next[key] = { instanceId: base.instanceId, model: base.model, ...value };
262+
continue;
263+
}
251264
next[key] =
252265
isPlainObject(value) && isPlainObject(base) ? { ...base, ...value } : value;
253266
}

0 commit comments

Comments
 (0)