Skip to content

Commit 9b98bd0

Browse files
fix(shared): new chats use the global default when the project default model is hidden (pingdotgg#23615)
1 parent 93c1023 commit 9b98bd0

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎packages/shared/src/projectSettings.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,32 @@ describe("resolveProjectSettings", () => {
119119
expect(resolved.sources.defaultModelSelection).toBe("environment");
120120
});
121121

122+
// regression: #17556 a hidden project default silently became the catalog's first model
123+
it.each([
124+
["hidden", ["gpt-5.6-terra", "gpt-5.6-sol"], [], "gpt-6.1-sol", "environment"],
125+
["visible", ["gpt-5.6-terra"], [], "gpt-5.6-sol", "project"],
126+
["custom", ["gpt-5.6-sol"], ["gpt-5.6-sol"], "gpt-5.6-sol", "project"],
127+
] as const)(
128+
"resolves a %s project default model against the environment default",
129+
(_visibility, hiddenModels, customModels, expectedModel, expectedSource) => {
130+
const codex = ProviderInstanceId.make("codex");
131+
const settings = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
132+
defaultModelSelection: createModelSelection(codex, "gpt-6.1-sol"),
133+
providerInstances: {
134+
[codex]: { driver: ProviderDriverKind.make("codex"), config: { customModels } },
135+
},
136+
providerModelPreferences: { [codex]: { hiddenModels, modelOrder: [] } },
137+
projectSettingsOverrides: {
138+
[projectId]: { defaultModelSelection: createModelSelection(codex, "gpt-5.6-sol") },
139+
},
140+
});
141+
const resolved = resolveProjectSettings(settings, projectId);
142+
expect(resolved.settings.defaultModelSelection?.model).toBe(expectedModel);
143+
expect(resolved.sources.defaultModelSelection).toBe(expectedSource);
144+
expect(resolved.overrides.defaultModelSelection?.model).toBe("gpt-5.6-sol");
145+
},
146+
);
147+
122148
it("moves text generation off an instance the project turned off", () => {
123149
const codex = ProviderInstanceId.make("codex");
124150
const settings = {

‎packages/shared/src/projectSettings.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
type ThreadEnvMode,
1515
type WorktreeCleanupRules,
1616
} from "@t3tools/contracts";
17+
import { readCustomModelEntries } from "./model.ts";
1718
import { normalizeProjectPathForComparison } from "./path.ts";
1819
import { fallbackTextGenerationModelSelection } from "./serverSettings.ts";
1920

@@ -148,6 +149,21 @@ function resolveProjectOverrides(
148149
) {
149150
continue;
150151
}
152+
// Clients resolve a hidden model to the catalog's first visible one, so a
153+
// hidden project default would silently pick a model nobody chose.
154+
// Custom models stay visible even when listed as hidden, as in the clients.
155+
if (key === "defaultModelSelection" && value !== null) {
156+
const { instanceId, model } = value as ModelSelection;
157+
const config = settings.providerInstances[instanceId]?.config as
158+
| { customModels?: unknown }
159+
| undefined;
160+
if (
161+
settings.providerModelPreferences?.[instanceId]?.hiddenModels.includes(model) &&
162+
!readCustomModelEntries(config?.customModels).some((entry) => entry.slug === model)
163+
) {
164+
continue;
165+
}
166+
}
151167
effective[key] = value;
152168
sources[key] = "project";
153169
}

0 commit comments

Comments
 (0)