@devries-cameron20 / t3code Mirror · read-only / commits / bc448b8697
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 08:15 UTC

fix(web): composer fallback keeps the effort of a model saved under an alias (#27859)

Co-authored-by: maria-rcks <maria@kuuro.net>

Mantas Kantautas committed Nov 1, 2026 at 04:43 UTC bc448b8697157a5523d36f5449e0f11b2008e0e9
3 files changed +165 -11
apps/web/src/composerDraftStore.ts
+24 -9
@@ -53,7 +53,11 @@ import type {
53 import { waitForDraftHeroTransition } from "./components/chat/draftHeroTransition";
54 import { getLocalStorageItem } from "./hooks/useLocalStorage";
55 import { readThreadPreviewState } from "./previewStateStore";
56 -import { resolveAppModelSelection, resolveAppModelSelectionForInstance } from "./modelSelection";
56 +import {
57 + readInstanceCustomModels,
58 + resolveAppModelSelection,
59 + resolveAppModelSelectionForInstance,
60 +} from "./modelSelection";
61 import {
62 DEFAULT_INTERACTION_MODE,
63 DEFAULT_RUNTIME_MODE,
@@ -1188,6 +1192,7 @@ function withFallbackInstanceOptions(input: {
1192 readonly selectedProvider: ProviderDriverKind;
1193 readonly selectedInstanceId?: ProviderInstanceId | null | undefined;
1194 readonly requestedInstanceId?: ProviderInstanceId | null | undefined;
1195 + readonly settings: UnifiedSettings;
1196 }): ProviderOptionSelectionsByProvider | null {
1197 const { modelOptions, selectedInstanceId, requestedInstanceId } = input;
1198 if (
@@ -1200,16 +1205,26 @@ function withFallbackInstanceOptions(input: {
1205 return modelOptions;
1206 }
1207 const requestedOptions = modelOptions[requestedInstanceId];
1203 - const requestedDriver = input.providers.find(
1208 + const requestedProvider = input.providers.find(
1209 (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 + );
1211 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) {
1228 return modelOptions;
1229 }
1230 return { ...modelOptions, [selectedInstanceId]: requestedOptions };
apps/web/src/modelSelection.test.ts
+140 -1
@@ -860,6 +860,7 @@ describe("composer fallback to another instance of the same driver", () => {
860 readonly providers: ReadonlyArray<ServerProvider>;
861 readonly draft?: Parameters<typeof deriveEffectiveComposerModelState>[0]["draft"];
862 readonly threadModelSelection: ReturnType<typeof createModelSelection>;
863 + readonly customModels?: Partial<Record<string, ReadonlyArray<string>>>;
864 }) {
865 const settings = {
866 ...DEFAULT_UNIFIED_SETTINGS,
@@ -869,7 +870,13 @@ describe("composer fallback to another instance of the same driver", () => {
870 {
871 driver: provider.driver,
872 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 + },
880 },
881 ]),
882 ),
@@ -954,6 +961,138 @@ describe("composer fallback to another instance of the same driver", () => {
961 expect(traits.modelOptionsForDispatch).toBeUndefined();
962 });
963
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 +
1096 it("does not carry options to another driver", () => {
1097 const codexOnly: ReadonlyArray<ServerProvider> = [
1098 {
apps/web/src/modelSelection.ts
+1 -1
@@ -37,7 +37,7 @@ export const MAX_CUSTOM_MODEL_LENGTH = 256;
37 const DEFAULT_TEXT_GENERATION_INSTANCE_ID = ProviderInstanceId.make("codex");
38
39 // Legacy per-driver buckets would leak custom-instance models into stock instances.
40 -function readInstanceCustomModels(
40 +export function readInstanceCustomModels(
41 settings: UnifiedSettings,
42 instanceId: ProviderInstanceId,
43 driverKind: ProviderDriverKind,