Skip to content

Commit bc448b8

Browse files
fix(web): composer fallback keeps the effort of a model saved under an alias (pingdotgg#27859)
Co-authored-by: maria-rcks <[email protected]>
1 parent a62452a commit bc448b8

3 files changed

Lines changed: 165 additions & 11 deletions

File tree

‎apps/web/src/composerDraftStore.ts‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ import type {
5353
import { waitForDraftHeroTransition } from "./components/chat/draftHeroTransition";
5454
import { getLocalStorageItem } from "./hooks/useLocalStorage";
5555
import { readThreadPreviewState } from "./previewStateStore";
56-
import { resolveAppModelSelection, resolveAppModelSelectionForInstance } from "./modelSelection";
56+
import {
57+
readInstanceCustomModels,
58+
resolveAppModelSelection,
59+
resolveAppModelSelectionForInstance,
60+
} from "./modelSelection";
5761
import {
5862
DEFAULT_INTERACTION_MODE,
5963
DEFAULT_RUNTIME_MODE,
@@ -1188,6 +1192,7 @@ function withFallbackInstanceOptions(input: {
11881192
readonly selectedProvider: ProviderDriverKind;
11891193
readonly selectedInstanceId?: ProviderInstanceId | null | undefined;
11901194
readonly requestedInstanceId?: ProviderInstanceId | null | undefined;
1195+
readonly settings: UnifiedSettings;
11911196
}): ProviderOptionSelectionsByProvider | null {
11921197
const { modelOptions, selectedInstanceId, requestedInstanceId } = input;
11931198
if (
@@ -1200,16 +1205,26 @@ function withFallbackInstanceOptions(input: {
12001205
return modelOptions;
12011206
}
12021207
const requestedOptions = modelOptions[requestedInstanceId];
1203-
const requestedDriver = input.providers.find(
1208+
const requestedProvider = input.providers.find(
12041209
(provider) => provider.instanceId === requestedInstanceId,
1205-
)?.driver;
1206-
// The model of the selection the options came from, which can differ from the shown model's source.
1210+
);
12071211
const requestedModel = input.optionSelections?.[requestedInstanceId]?.model;
1208-
if (
1209-
!requestedOptions ||
1210-
requestedDriver !== input.selectedProvider ||
1211-
requestedModel !== input.selectedModel
1212-
) {
1212+
// Static aliases are shared across instances; exact custom slugs and catalog aliases are not.
1213+
const modelIdentity = (instanceId: ProviderInstanceId, model: string | undefined) => {
1214+
const isCustom =
1215+
input.providers
1216+
.find((provider) => provider.instanceId === instanceId)
1217+
?.models.some((entry) => entry.slug === model && entry.isCustom) ||
1218+
readInstanceCustomModels(input.settings, instanceId, input.selectedProvider).some(
1219+
(entry) => entry.slug === model,
1220+
);
1221+
return isCustom ? model : normalizeModelSlug(model, input.selectedProvider);
1222+
};
1223+
const sameModel =
1224+
requestedModel === input.selectedModel ||
1225+
modelIdentity(requestedInstanceId, requestedModel) ===
1226+
modelIdentity(selectedInstanceId, input.selectedModel);
1227+
if (!requestedOptions || requestedProvider?.driver !== input.selectedProvider || !sameModel) {
12131228
return modelOptions;
12141229
}
12151230
return { ...modelOptions, [selectedInstanceId]: requestedOptions };

‎apps/web/src/modelSelection.test.ts‎

Lines changed: 140 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ describe("composer fallback to another instance of the same driver", () => {
860860
readonly providers: ReadonlyArray<ServerProvider>;
861861
readonly draft?: Parameters<typeof deriveEffectiveComposerModelState>[0]["draft"];
862862
readonly threadModelSelection: ReturnType<typeof createModelSelection>;
863+
readonly customModels?: Partial<Record<string, ReadonlyArray<string>>>;
863864
}) {
864865
const settings = {
865866
...DEFAULT_UNIFIED_SETTINGS,
@@ -869,7 +870,13 @@ describe("composer fallback to another instance of the same driver", () => {
869870
{
870871
driver: provider.driver,
871872
enabled: provider.enabled,
872-
config: {},
873+
config: {
874+
customModels: (input.customModels?.[provider.instanceId] ?? []).map((slug) => ({
875+
slug,
876+
name: slug,
877+
capabilities: null,
878+
})),
879+
},
873880
},
874881
]),
875882
),
@@ -954,6 +961,138 @@ describe("composer fallback to another instance of the same driver", () => {
954961
expect(traits.modelOptionsForDispatch).toBeUndefined();
955962
});
956963

964+
describe("with model aliases", () => {
965+
const reasoningModel = (
966+
slug: string,
967+
id: string,
968+
extra: Partial<ServerProvider["models"][number]> = {},
969+
): ServerProvider["models"][number] => ({
970+
slug,
971+
name: slug,
972+
isCustom: false,
973+
...extra,
974+
capabilities: {
975+
optionDescriptors: [
976+
{
977+
id,
978+
label: id,
979+
type: "select",
980+
options: ["medium", "high", "xhigh"].map((value) => ({
981+
id: value,
982+
label: value,
983+
isDefault: value === "medium",
984+
})),
985+
},
986+
],
987+
},
988+
});
989+
990+
it.each([
991+
["5.4", "gpt-5.4"],
992+
["gpt-5-codex", "gpt-5.4"],
993+
["gpt-5.4", "5.4"],
994+
])("keeps the effort from %s on fallback %s", (savedModel, fallbackModel) => {
995+
const disabledCodex = ProviderInstanceId.make("codex");
996+
const fallbackCodex = ProviderInstanceId.make("codex_team");
997+
const models = [reasoningModel(fallbackModel, "reasoningEffort")];
998+
const { selectedInstanceId, state, traits } = composerFor({
999+
providers: [
1000+
{ ...provider({ provider: codex, instanceId: disabledCodex }), enabled: false, models },
1001+
{ ...provider({ provider: codex, instanceId: fallbackCodex }), models },
1002+
],
1003+
threadModelSelection: createModelSelection(disabledCodex, savedModel, [
1004+
{ id: "reasoningEffort", value: "xhigh" },
1005+
]),
1006+
});
1007+
1008+
expect(selectedInstanceId).toBe(fallbackCodex);
1009+
expect(state.selectedModel).toBe(fallbackModel);
1010+
expect(traits.promptEffort).toBe("xhigh");
1011+
});
1012+
1013+
it.each([
1014+
{
1015+
// A disabled Codex instance reports only its custom models.
1016+
state: "disabled",
1017+
requested: {
1018+
enabled: false,
1019+
models: [reasoningModel("5.4", "reasoningEffort", { isCustom: true })],
1020+
},
1021+
},
1022+
{
1023+
// An unavailable instance reports no models; its custom models are only in settings.
1024+
state: "unavailable",
1025+
requested: { enabled: false, availability: "unavailable" as const, models: [] },
1026+
},
1027+
])(
1028+
"does not alias-expand a custom model named 5.4 when the requested instance is $state",
1029+
({ requested }) => {
1030+
const disabledCodex = ProviderInstanceId.make("codex");
1031+
const { state, traits } = composerFor({
1032+
providers: [
1033+
{ ...provider({ provider: codex, instanceId: disabledCodex }), ...requested },
1034+
{
1035+
...provider({ provider: codex, instanceId: "codex_team" }),
1036+
models: [reasoningModel("gpt-5.4", "reasoningEffort")],
1037+
},
1038+
],
1039+
customModels: { [disabledCodex]: ["5.4"] },
1040+
threadModelSelection: createModelSelection(disabledCodex, "5.4", [
1041+
{ id: "reasoningEffort", value: "xhigh" },
1042+
]),
1043+
});
1044+
1045+
expect(state.selectedModel).toBe("gpt-5.4");
1046+
expect(traits.modelOptionsForDispatch).toBeUndefined();
1047+
},
1048+
);
1049+
1050+
it("does not alias-expand the fallback instance's custom model", () => {
1051+
const { state, traits } = composerFor({
1052+
providers: [
1053+
{ ...provider({ provider: codex, instanceId: "codex" }), enabled: false },
1054+
{
1055+
...provider({ provider: codex, instanceId: "codex_team" }),
1056+
models: [reasoningModel("5.4", "reasoningEffort", { isCustom: true })],
1057+
},
1058+
],
1059+
customModels: { codex_team: ["5.4"] },
1060+
threadModelSelection: createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
1061+
{ id: "reasoningEffort", value: "xhigh" },
1062+
]),
1063+
});
1064+
1065+
expect(state.selectedModel).toBe("5.4");
1066+
expect(traits.modelOptionsForDispatch).toBeUndefined();
1067+
});
1068+
1069+
it("does not carry options through an alias that names another model per instance", () => {
1070+
// "antigravity-default" is each Antigravity instance's current model.
1071+
const antigravity = ProviderDriverKind.make("antigravity");
1072+
const disabledAntigravity = ProviderInstanceId.make("antigravity");
1073+
const current = { isDefault: true, aliases: [ANTIGRAVITY_DEFAULT_MODEL] };
1074+
const { state, traits } = composerFor({
1075+
providers: [
1076+
{
1077+
...provider({ provider: antigravity, instanceId: disabledAntigravity }),
1078+
enabled: false,
1079+
models: [reasoningModel("gemini-3-pro", "thinking", current)],
1080+
},
1081+
{
1082+
...provider({ provider: antigravity, instanceId: "antigravity_work" }),
1083+
models: [reasoningModel("claude-sonnet-4-6", "thinking", current)],
1084+
},
1085+
],
1086+
threadModelSelection: createModelSelection(disabledAntigravity, ANTIGRAVITY_DEFAULT_MODEL, [
1087+
{ id: "thinking", value: "high" },
1088+
]),
1089+
});
1090+
1091+
expect(state.selectedModel).toBe("claude-sonnet-4-6");
1092+
expect(traits.modelOptionsForDispatch).toBeUndefined();
1093+
});
1094+
});
1095+
9571096
it("does not carry options to another driver", () => {
9581097
const codexOnly: ReadonlyArray<ServerProvider> = [
9591098
{

‎apps/web/src/modelSelection.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const MAX_CUSTOM_MODEL_LENGTH = 256;
3737
const DEFAULT_TEXT_GENERATION_INSTANCE_ID = ProviderInstanceId.make("codex");
3838

3939
// Legacy per-driver buckets would leak custom-instance models into stock instances.
40-
function readInstanceCustomModels(
40+
export function readInstanceCustomModels(
4141
settings: UnifiedSettings,
4242
instanceId: ProviderInstanceId,
4343
driverKind: ProviderDriverKind,

0 commit comments

Comments
 (0)