Skip to content

Commit e88dcb0

Browse files
committed
fix(web): fallback reads an unavailable instance's custom models from settings
1 parent ef81c57 commit e88dcb0

3 files changed

Lines changed: 59 additions & 30 deletions

File tree

‎apps/web/src/composerDraftStore.ts‎

Lines changed: 15 additions & 6 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 (
@@ -1203,14 +1208,18 @@ function withFallbackInstanceOptions(input: {
12031208
const requestedProvider = input.providers.find(
12041209
(provider) => provider.instanceId === requestedInstanceId,
12051210
);
1206-
// The model of the selection the options came from, which can differ from the shown model's source.
1207-
// It can be a driver alias such as "5.4" for "gpt-5.4", expanded only when the requested instance
1208-
// does not offer that exact slug (a custom model can be named "5.4"). Catalog aliases are not used:
1209-
// Antigravity's "antigravity-default" names a different model on each instance.
1211+
// A driver alias such as "5.4" expands only when the requested instance does not offer that exact
1212+
// slug; custom models count, from settings too, since an unavailable instance reports none.
1213+
// Catalog aliases are not used: Antigravity's "antigravity-default" differs per instance.
12101214
const requestedModel = input.optionSelections?.[requestedInstanceId]?.model;
1215+
const requestedOffersSlug =
1216+
requestedProvider?.models.some((model) => model.slug === requestedModel) ||
1217+
readInstanceCustomModels(input.settings, requestedInstanceId, input.selectedProvider).some(
1218+
(model) => model.slug === requestedModel,
1219+
);
12111220
const sameModel =
12121221
requestedModel === input.selectedModel ||
1213-
(!requestedProvider?.models.some((model) => model.slug === requestedModel) &&
1222+
(!requestedOffersSlug &&
12141223
normalizeModelSlug(requestedModel, input.selectedProvider) === input.selectedModel);
12151224
if (!requestedOptions || requestedProvider?.driver !== input.selectedProvider || !sameModel) {
12161225
return modelOptions;

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

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,7 @@ describe("composer fallback to another instance of the same driver", () => {
829829
readonly providers: ReadonlyArray<ServerProvider>;
830830
readonly draft?: Parameters<typeof deriveEffectiveComposerModelState>[0]["draft"];
831831
readonly threadModelSelection: ReturnType<typeof createModelSelection>;
832+
readonly customModels?: Partial<Record<string, ReadonlyArray<string>>>;
832833
}) {
833834
const settings = {
834835
...DEFAULT_UNIFIED_SETTINGS,
@@ -838,7 +839,13 @@ describe("composer fallback to another instance of the same driver", () => {
838839
{
839840
driver: provider.driver,
840841
enabled: provider.enabled,
841-
config: {},
842+
config: {
843+
customModels: (input.customModels?.[provider.instanceId] ?? []).map((slug) => ({
844+
slug,
845+
name: slug,
846+
capabilities: null,
847+
})),
848+
},
842849
},
843850
]),
844851
),
@@ -969,29 +976,42 @@ describe("composer fallback to another instance of the same driver", () => {
969976
expect(traits.promptEffort).toBe("xhigh");
970977
});
971978

972-
it("does not alias-expand a custom model the requested instance offers", () => {
973-
// A disabled Codex instance reports only its custom models; this one is named "5.4".
974-
const disabledCodex = ProviderInstanceId.make("codex");
975-
const { state, traits } = composerFor({
976-
providers: [
977-
{
978-
...provider({ provider: codex, instanceId: disabledCodex }),
979-
enabled: false,
980-
models: [reasoningModel("5.4", "reasoningEffort", { isCustom: true })],
981-
},
982-
{
983-
...provider({ provider: codex, instanceId: "codex_team" }),
984-
models: [reasoningModel("gpt-5.4", "reasoningEffort")],
985-
},
986-
],
987-
threadModelSelection: createModelSelection(disabledCodex, "5.4", [
988-
{ id: "reasoningEffort", value: "xhigh" },
989-
]),
990-
});
979+
it.each([
980+
{
981+
// A disabled Codex instance reports only its custom models.
982+
state: "disabled",
983+
requested: {
984+
enabled: false,
985+
models: [reasoningModel("5.4", "reasoningEffort", { isCustom: true })],
986+
},
987+
},
988+
{
989+
// An unavailable instance reports no models; its custom models are only in settings.
990+
state: "unavailable",
991+
requested: { enabled: false, availability: "unavailable" as const, models: [] },
992+
},
993+
])(
994+
"does not alias-expand a custom model named 5.4 when the requested instance is $state",
995+
({ requested }) => {
996+
const disabledCodex = ProviderInstanceId.make("codex");
997+
const { state, traits } = composerFor({
998+
providers: [
999+
{ ...provider({ provider: codex, instanceId: disabledCodex }), ...requested },
1000+
{
1001+
...provider({ provider: codex, instanceId: "codex_team" }),
1002+
models: [reasoningModel("gpt-5.4", "reasoningEffort")],
1003+
},
1004+
],
1005+
customModels: { [disabledCodex]: ["5.4"] },
1006+
threadModelSelection: createModelSelection(disabledCodex, "5.4", [
1007+
{ id: "reasoningEffort", value: "xhigh" },
1008+
]),
1009+
});
9911010

992-
expect(state.selectedModel).toBe("gpt-5.4");
993-
expect(traits.modelOptionsForDispatch).toBeUndefined();
994-
});
1011+
expect(state.selectedModel).toBe("gpt-5.4");
1012+
expect(traits.modelOptionsForDispatch).toBeUndefined();
1013+
},
1014+
);
9951015

9961016
it("does not carry options through an alias that names another model per instance", () => {
9971017
// "antigravity-default" is each Antigravity instance's current model.

‎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)