@devries-cameron20 / t3code-1 / commits / 2dc5ebd52f
Fork 0

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

fix(web): switching providers no longer drops the thread's stored effort (#33090)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Victor committed Nov 15, 2026 at 01:46 UTC 2dc5ebd52f238893344609a56a6918f700650438
7 files changed +212 -30
apps/mobile/src/features/threads/ThreadSettingsSheet.tsx
+9 -1
@@ -69,6 +69,7 @@ import {
69 serverConfigForCwd,
70 type ModelOption,
71 type ProviderGroup,
72 + withStoredThreadModelOptions,
73 } from "../../lib/modelOptions";
74 import { applyProviderOptionSelection } from "../../lib/providerOptions";
75 import { resolveProviderOptionDescriptors } from "../../lib/providerOptions";
@@ -1409,7 +1410,14 @@ export function ExistingThreadSettingsRouteScreen({
1410 prompt={prompt}
1411 onPromptChange={(text) => setComposerDraftText(draftKey, text)}
1412 reportedModelSelection={reportedModelSelection}
1412 - onSelectModel={(option) => updateModelSelection(withRememberedModelOptions(option.selection))}
1413 + onSelectModel={(option) =>
1414 + updateModelSelection(
1415 + withStoredThreadModelOptions(
1416 + withRememberedModelOptions(option.selection),
1417 + selectedThread.modelSelection,
1418 + ),
1419 + )
1420 + }
1421 restoreSelection={withRememberedModelOptions}
1422 optionDescriptors={resolveProviderOptionDescriptors({
1423 capabilities: currentModelOption?.capabilities,
apps/mobile/src/lib/modelOptions.test.ts
+22
@@ -18,6 +18,7 @@ import {
18 resolveDefaultableModelSelection,
19 resolveNewTaskModelSelection,
20 resolveSelectableModelSelection,
21 + withStoredThreadModelOptions,
22 type ModelOption,
23 } from "./modelOptions";
24
@@ -144,6 +145,27 @@ describe("mobile model options", () => {
145 expect(explicitOption?.selection.options).toEqual([{ id: "serviceTier", value: "priority" }]);
146 });
147
148 + it("carries a thread's stored options onto an optionless pick of its own model", () => {
149 + const claude = ProviderInstanceId.make("claudeAgent");
150 + const stored: ModelSelection = {
151 + instanceId: claude,
152 + model: "claude-opus-5-5",
153 + options: [{ id: "effort", value: "high" }],
154 + };
155 + expect(
156 + withStoredThreadModelOptions({ instanceId: claude, model: stored.model }, stored),
157 + ).toEqual(stored);
158 + const remembered: ModelSelection = { ...stored, options: [{ id: "effort", value: "low" }] };
159 + expect(withStoredThreadModelOptions(remembered, stored)).toBe(remembered);
160 + const otherInstance: ModelSelection = {
161 + instanceId: ProviderInstanceId.make("claude_work"),
162 + model: stored.model,
163 + };
164 + expect(withStoredThreadModelOptions(otherInstance, stored)).toBe(otherInstance);
165 + const otherModel: ModelSelection = { instanceId: claude, model: "claude-sonnet-5-5" };
166 + expect(withStoredThreadModelOptions(otherModel, stored)).toBe(otherModel);
167 + });
168 +
169 it("limits existing threads to their provider while new tasks keep every provider", () => {
170 const providers = ["codex", "claudeAgent"].map((instanceId) => ({
171 instanceId,
apps/mobile/src/lib/modelOptions.ts
+16
@@ -287,6 +287,22 @@ export function resolveNewTaskModelSelection(input: {
287 );
288 }
289
290 +// Rows built after a pick on another instance carry no options for the thread's own model.
291 +export function withStoredThreadModelOptions(
292 + selection: ModelSelection,
293 + stored: ModelSelection,
294 +): ModelSelection {
295 + if (
296 + (selection.options?.length ?? 0) > 0 ||
297 + !stored.options?.length ||
298 + selection.instanceId !== stored.instanceId ||
299 + selection.model !== stored.model
300 + ) {
301 + return selection;
302 + }
303 + return { ...selection, options: stored.options };
304 +}
305 +
306 export function buildModelOptions(
307 config: T3ServerConfig | null | undefined,
308 fallbackModelSelection: ModelSelection | null,
apps/web/src/components/ChatView.modelPick.browser.test.tsx
+30 -7
@@ -1,8 +1,9 @@
1 import { createMemoryHistory } from "@tanstack/react-router";
2 +import { ProviderInstanceId } from "@t3tools/contracts";
3 import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
4 import type * as Context from "effect/Context";
5 import { expect, it, vi } from "vite-plus/test";
5 -import { page } from "vite-plus/test/browser";
6 +import { page, userEvent } from "vite-plus/test/browser";
7
8 import { AppRoot } from "~/AppRoot";
9 // The route loads ChatView lazily, and its first transform (React Compiler over ~4k lines)
@@ -36,8 +37,17 @@ vi.mock(import("~/rpc/requestLatencyState"), async (original) => ({
37
38 // Its own file: the app's shell subscription outlives a test, and it must list this thread.
39 it("a model picked for an existing thread reaches the server before any message is sent", async () => {
39 - const thread = threadWithHistory("thread-model-pick", 1);
40 - using _environment = installFakeEnvironment([thread], { acceptCommands: true });
40 + const stored = {
41 + instanceId: ProviderInstanceId.make("codex"),
42 + model: "gpt-5.4",
43 + options: [{ id: "reasoningEffort", value: "high" }],
44 + };
45 + const thread = { ...threadWithHistory("thread-model-pick", 1), modelSelection: stored };
46 + const aliasThread = {
47 + ...threadWithHistory("thread-model-alias", 1),
48 + modelSelection: { ...stored, model: "gpt-5-codex" },
49 + };
50 + using _environment = installFakeEnvironment([thread, aliasThread], { acceptCommands: true });
51 __setClientSettingsForTests({
52 ...DEFAULT_CLIENT_SETTINGS,
53 onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
@@ -52,16 +62,29 @@ it("a model picked for an existing thread reaches the server before any message
62 });
63 await expect.element(page.getByText("Answer 0 for thread-model-pick.")).toBeVisible();
64
65 + const modelSets = () =>
66 + dispatchedCommands().filter((command) => command.type === "thread.model-selection.set");
67 +
68 await page.getByRole("button", { name: "GPT-5.4", exact: true }).click();
69 await page.getByRole("option", { name: /GPT-5\.5/ }).click();
70 await vi.waitFor(() =>
58 - expect(
59 - dispatchedCommands().filter((command) => command.type === "thread.model-selection.set"),
60 - ).toEqual([
71 + expect(modelSets()).toEqual([
72 expect.objectContaining({
73 threadId: thread.id,
63 - modelSelection: expect.objectContaining({ instanceId: "codex", model: "gpt-5.5" }),
74 + modelSelection: { instanceId: "codex", model: "gpt-5.5" },
75 }),
76 ]),
77 );
78 +
79 + // A thread stored under an alias keeps its options when its canonical model is picked.
80 + await userEvent.keyboard("{Escape}");
81 + await router.navigate({ href: `/${ENVIRONMENT_ID}/${aliasThread.id}` });
82 + await expect.element(page.getByText("Answer 0 for thread-model-alias.")).toBeVisible();
83 + await page.getByRole("button", { name: "GPT-5.4", exact: true }).click();
84 + await page.getByRole("option", { name: /GPT-5\.4/ }).click();
85 + await vi.waitFor(() =>
86 + expect(modelSets().at(-1)).toEqual(
87 + expect.objectContaining({ threadId: aliasThread.id, modelSelection: stored }),
88 + ),
89 + );
90 });
apps/web/src/components/chat/useComposerSelection.ts
+21 -3
@@ -23,7 +23,11 @@ import {
23 resolveNewDraftStartFromOrigin,
24 threadHasStarted,
25 } from "../../lib/chatThreadActions";
26 -import { type DraftThreadEnvMode, useComposerDraftStore } from "../../composerDraftStore";
26 +import {
27 + type DraftThreadEnvMode,
28 + isSameModel,
29 + useComposerDraftStore,
30 +} from "../../composerDraftStore";
31 import {
32 getStartedThreadModelChangeBlockReason,
33 deriveLockedProvider,
@@ -188,9 +192,23 @@ export function useComposerSelection(input: ComposerSelectionInput) {
192 }
193 const rememberedOptions =
194 useComposerDraftStore.getState().stickyOptionsByModelByProvider[instanceId]?.[resolvedModel];
191 - const nextModelSelection: ModelSelection =
195 + const threadSelection = activeThread.modelSelection;
196 + // This pick replaces the stored options, so the thread's own model carries them over.
197 + const pickOptions =
198 rememberedOptions !== undefined && rememberedOptions.length > 0
193 - ? { instanceId, model: resolvedModel, options: [...rememberedOptions] }
199 + ? rememberedOptions
200 + : threadSelection.instanceId === instanceId &&
201 + entry !== undefined &&
202 + isSameModel(
203 + { providers: providerStatuses, selectedProvider: entry.driver, settings },
204 + threadSelection,
205 + { instanceId, model: resolvedModel },
206 + )
207 + ? threadSelection.options
208 + : undefined;
209 + const nextModelSelection: ModelSelection =
210 + pickOptions !== undefined && pickOptions.length > 0
211 + ? { instanceId, model: resolvedModel, options: [...pickOptions] }
212 : { instanceId, model: resolvedModel };
213 const modelChangeBlockReason = getStartedThreadModelChangeBlockReason({
214 hasStartedSession: activeRuntime !== null,
apps/web/src/composerDraftStore.ts
+52 -19
@@ -1338,23 +1338,32 @@ export function deriveEffectiveComposerModelState(input: {
1338 baseSelection?.instanceId ?? activeSelectionInstanceId,
1339 baseSelection?.model,
1340 );
1341 - // Draft options win; otherwise an existing thread's options, even none, outrank the project's.
1342 - // Selections stay with them, so a fallback instance can check which model the options belong to.
1343 - const optionSelections =
1344 - [
1345 - draft?.modelSelectionByProvider,
1346 - draftPicksOtherModel ? null : selectionsByInstance(baseSelection),
1347 - ].find((selections) => modelSelectionByProviderToOptions(selections) !== null) ?? null;
1348 - const modelOptions = modelSelectionByProviderToOptions(optionSelections);
1349 -
1350 - return {
1351 - selectedModel,
1352 - modelOptions: withFallbackInstanceOptions({
1341 + // An existing thread's options, even none, outrank the project's. Next to draft options, they
1342 + // fill in only for the model they were stored with. Each source keeps its selections so a
1343 + // fallback instance can check which model its options belong to.
1344 + const optionsFrom = (optionSelections: Partial<Record<string, ModelSelection>> | null) =>
1345 + withFallbackInstanceOptions({
1346 ...input,
1354 - modelOptions,
1347 + modelOptions: modelSelectionByProviderToOptions(optionSelections),
1348 optionSelections,
1349 selectedModel,
1357 - }),
1350 + });
1351 + const draftOptions = optionsFrom(draft?.modelSelectionByProvider ?? null);
1352 + const storedIsShownModel =
1353 + baseSelection != null &&
1354 + isSameModel(input, baseSelection, {
1355 + instanceId: input.selectedInstanceId ?? baseSelection.instanceId,
1356 + model: selectedModel,
1357 + });
1358 + const storedOptions = optionsFrom(
1359 + !draftPicksOtherModel && (draftOptions === null || storedIsShownModel)
1360 + ? selectionsByInstance(baseSelection)
1361 + : null,
1362 + );
1363 +
1364 + return {
1365 + selectedModel,
1366 + modelOptions: draftOptions || storedOptions ? { ...storedOptions, ...draftOptions } : null,
1367 };
1368 }
1369
@@ -1387,17 +1396,41 @@ function withFallbackInstanceOptions(input: {
1396 const requestedProvider = input.providers.find(
1397 (provider) => provider.instanceId === requestedInstanceId,
1398 );
1390 - const requestedModel = input.optionSelections?.[requestedInstanceId]?.model;
1391 - const sameModel =
1392 - requestedModel === input.selectedModel ||
1393 - composerModelIdentity(input, requestedInstanceId, requestedModel) ===
1394 - composerModelIdentity(input, selectedInstanceId, input.selectedModel);
1399 + const sameModel = isSameModel(
1400 + input,
1401 + {
1402 + instanceId: requestedInstanceId,
1403 + model: input.optionSelections?.[requestedInstanceId]?.model,
1404 + },
1405 + { instanceId: selectedInstanceId, model: input.selectedModel },
1406 + );
1407 if (!requestedOptions || requestedProvider?.driver !== input.selectedProvider || !sameModel) {
1408 return modelOptions;
1409 }
1410 return { ...modelOptions, [selectedInstanceId]: requestedOptions };
1411 }
1412
1413 +interface InstanceModel {
1414 + readonly instanceId: ProviderInstanceId;
1415 + readonly model: string | undefined;
1416 +}
1417 +
1418 +export function isSameModel(
1419 + input: {
1420 + readonly providers: ReadonlyArray<ServerProvider>;
1421 + readonly selectedProvider: ProviderDriverKind;
1422 + readonly settings: UnifiedSettings;
1423 + },
1424 + a: InstanceModel,
1425 + b: InstanceModel,
1426 +): boolean {
1427 + return (
1428 + a.model === b.model ||
1429 + composerModelIdentity(input, a.instanceId, a.model) ===
1430 + composerModelIdentity(input, b.instanceId, b.model)
1431 + );
1432 +}
1433 +
1434 function revokeObjectPreviewUrl(previewUrl: string): void {
1435 if (typeof URL === "undefined") {
1436 return;
apps/web/src/modelSelection.test.ts
+62
@@ -863,6 +863,68 @@ describe("instance-scoped model selection", () => {
863 ).toEqual(createModelSelection(instanceId, "openai/gpt-5.5"));
864 });
865
866 + it("keeps a thread's stored options while the draft holds options for another provider", () => {
867 + const codex = ProviderInstanceId.make("codex");
868 + const claude = ProviderInstanceId.make("claudeAgent");
869 + const providers = [
870 + provider({ instanceId: "codex", models: ["gpt-5.5", "gpt-5.4"] }),
871 + provider({
872 + provider: ProviderDriverKind.make("claudeAgent"),
873 + instanceId: "claudeAgent",
874 + models: ["claude-opus-5-5"],
875 + }),
876 + ];
877 + const stored = createModelSelection(codex, "gpt-5.5", [
878 + { id: "reasoningEffort", value: "high" },
879 + { id: "fastMode", value: true },
880 + ]);
881 + const claudePick = createModelSelection(claude, "claude-opus-5-5", [
882 + { id: "effort", value: "max" },
883 + ]);
884 + const optionsFor = (
885 + draftSelections: Record<string, ReturnType<typeof createModelSelection>>,
886 + threadModelSelection = stored,
887 + ) =>
888 + deriveEffectiveComposerModelState({
889 + threadStarted: true,
890 + draft: {
891 + activeProvider: codex,
892 + modelSelectionByProvider: draftSelections,
893 + modelSelectionExplicit: true,
894 + },
895 + providers,
896 + selectedProvider: ProviderDriverKind.make("codex"),
897 + selectedInstanceId: codex,
898 + requestedInstanceId: claude,
899 + threadModelSelection,
900 + projectModelSelection: null,
901 + settings: DEFAULT_UNIFIED_SETTINGS,
902 + }).modelOptions;
903 +
904 + expect(
905 + optionsFor({ [claude]: claudePick, [codex]: createModelSelection(codex, "gpt-5.5") }),
906 + ).toEqual({ [claude]: claudePick.options, [codex]: stored.options });
907 + // Claude turned off after an unsent pick: the composer is back on the thread's instance.
908 + expect(optionsFor({ [claude]: claudePick })?.[codex]).toEqual(stored.options);
909 + const fastOff = createModelSelection(codex, "gpt-5.5", [
910 + { id: "reasoningEffort", value: "high" },
911 + { id: "fastMode", value: false },
912 + ]);
913 + expect(optionsFor({ [claude]: claudePick, [codex]: fastOff })?.[codex]).toEqual(
914 + fastOff.options,
915 + );
916 + // A stored alias of the shown model still counts as that model.
917 + const storedAlias = createModelSelection(codex, "gpt-5-codex", stored.options);
918 + expect(optionsFor({ [claude]: claudePick }, storedAlias)?.[codex]).toEqual(stored.options);
919 + const storedOtherModel = createModelSelection(codex, "gpt-5.4", stored.options);
920 + expect(
921 + optionsFor(
922 + { [claude]: claudePick, [codex]: createModelSelection(codex, "gpt-5.5") },
923 + storedOtherModel,
924 + )?.[codex],
925 + ).toBeUndefined();
926 + });
927 +
928 it("keeps the default instance's draft model off a custom instance of the same driver", () => {
929 const driver = ProviderDriverKind.make("opencode");
930 const defaultInstanceId = ProviderInstanceId.make("opencode");