Skip to content

Commit f390f1a

Browse files
yaacovcorcosclaude
andcommitted
fix(web): changing a project's model no longer keeps the old model's options
At project scope, a model selection patch was merged into the previous selection, so switching a project's default, text generation, or writer model kept the old model's options (for example its reasoning effort). A selection that names its instance or model now replaces the saved options, as the server already does for environment settings. As on the server, an instance or model the patch leaves out is kept from the saved selection. Options-only patches are still completed from the saved selection. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 9bd1d80 commit f390f1a

2 files changed

Lines changed: 109 additions & 1 deletion

File tree

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

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {
22
DEFAULT_SERVER_SETTINGS,
33
EnvironmentId,
44
ProjectId,
5+
ProviderInstanceId,
6+
type ProjectSettingsOverrides,
57
type ServerSettings,
68
} from "@t3tools/contracts";
79
import { describe, expect, it, vi } from "vite-plus/test";
@@ -18,6 +20,7 @@ import {
1820
resolveScopedSettingsTargets,
1921
scopedSettingsAreMixed,
2022
scopedSettingsSource,
23+
type ScopedSettingsPatch,
2124
selectScopedSettingsEnvironments,
2225
} from "./scopedSettings";
2326
import { resolveSettingsScope } from "./settingsScope";
@@ -620,3 +623,85 @@ describe("partial object patches at project scope", () => {
620623
});
621624
});
622625
});
626+
627+
describe("model selection patches at project scope", () => {
628+
const environmentId = EnvironmentId.make("laptop");
629+
const projectId = ProjectId.make("fleet");
630+
const codex = ProviderInstanceId.make("codex");
631+
const claude = ProviderInstanceId.make("claudeAgent");
632+
const planWith = (override: ProjectSettingsOverrides, patch: ScopedSettingsPatch) =>
633+
planScopedSettingsPatch(
634+
{
635+
kind: "project",
636+
group: {} as never,
637+
environmentId: null,
638+
label: "fleet",
639+
members: [{ id: projectId, environmentId } as never],
640+
environmentIds: [environmentId],
641+
},
642+
[
643+
{
644+
environmentId,
645+
label: "Laptop",
646+
connection: { phase: "connected" },
647+
serverConfig: {
648+
settings: {
649+
...DEFAULT_SERVER_SETTINGS,
650+
projectSettingsOverrides: { [projectId]: override },
651+
},
652+
environment: { capabilities: { projectSettingsOverrides: true } },
653+
},
654+
},
655+
],
656+
patch,
657+
).serverWrites[0]?.patch.projectSettingsOverrides?.[projectId];
658+
659+
it("drops the previous model's options when the model changes", () => {
660+
const entry = planWith(
661+
{
662+
defaultModelSelection: {
663+
instanceId: codex,
664+
model: "gpt-5.6",
665+
options: [{ id: "reasoningEffort", value: "xhigh" }],
666+
},
667+
},
668+
{ defaultModelSelection: { instanceId: claude, model: "claude-opus-4-8" } },
669+
);
670+
expect(entry?.defaultModelSelection).toEqual({ instanceId: claude, model: "claude-opus-4-8" });
671+
});
672+
673+
it("keeps the saved instance when a patch names only the model", () => {
674+
const entry = planWith(
675+
{
676+
textGenerationModelSelection: {
677+
instanceId: codex,
678+
model: "gpt-5.6",
679+
options: [{ id: "reasoningEffort", value: "high" }],
680+
},
681+
},
682+
{ textGenerationModelSelection: { model: "gpt-5.6-mini" } },
683+
);
684+
expect(entry?.textGenerationModelSelection).toEqual({
685+
instanceId: codex,
686+
model: "gpt-5.6-mini",
687+
});
688+
});
689+
690+
it("still completes an options-only patch from the saved selection", () => {
691+
const entry = planWith(
692+
{
693+
textGenerationModelSelection: {
694+
instanceId: codex,
695+
model: "gpt-5.6",
696+
options: [{ id: "reasoningEffort", value: "high" }],
697+
},
698+
},
699+
{ textGenerationModelSelection: { options: [{ id: "reasoningEffort", value: "low" }] } },
700+
);
701+
expect(entry?.textGenerationModelSelection).toEqual({
702+
instanceId: codex,
703+
model: "gpt-5.6",
704+
options: [{ id: "reasoningEffort", value: "low" }],
705+
});
706+
});
707+
});

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ function isPlainObject(value: unknown): value is Record<string, unknown> {
4848
return typeof value === "object" && value !== null && !Array.isArray(value);
4949
}
5050

51+
const MODEL_SELECTION_KEYS = new Set<string>([
52+
"defaultModelSelection",
53+
"sourceControlWriterModelSelection",
54+
"textGenerationModelSelection",
55+
] satisfies ProjectScopedServerSettingKey[]);
56+
57+
/** Like the server, a selection naming its instance or model replaces the whole value. */
58+
function isModelSelectionReplacement(key: string, value: unknown): boolean {
59+
return (
60+
MODEL_SELECTION_KEYS.has(key) &&
61+
isPlainObject(value) &&
62+
(value.instanceId !== undefined || value.model !== undefined)
63+
);
64+
}
65+
5166
/** The representative supplies display values, never the set of write targets. */
5267
export function selectScopedSettingsEnvironments<T extends ScopedSettingsEnvironment>(
5368
scope: ResolvedSettingsScope,
@@ -258,7 +273,15 @@ export function planScopedSettingsPatch(
258273
delete next[key];
259274
continue;
260275
}
261-
const base = effective[key as keyof ServerSettings];
276+
const base: unknown = effective[key as keyof ServerSettings];
277+
// Merging would carry the previous model's options to the new one.
278+
// Like the server, a partial selection keeps the saved instance or model.
279+
if (isModelSelectionReplacement(key, value)) {
280+
next[key] = isPlainObject(base)
281+
? { instanceId: base.instanceId, model: base.model, ...(value as object) }
282+
: value;
283+
continue;
284+
}
262285
next[key] =
263286
isPlainObject(value) && isPlainObject(base) ? { ...base, ...value } : value;
264287
}

0 commit comments

Comments
 (0)