@devries-cameron20 / t3code-1 / commits / ad50f62eef
Fork 0

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

fix(mobile): picking a model shows its remembered options before saving (#15719)

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

nekohasekai committed Oct 20, 2026 at 04:25 UTC ad50f62eefd3ab5e923a3eda7cd0de30f4be271b
4 files changed +121 -19
apps/mobile/src/features/threads/ThreadComposer.tsx
+1
@@ -605,6 +605,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
605 reportedModelSelection: props.reportedModelSelection,
606 onSelectModel: (option) =>
607 props.onUpdateModelSelection(withRememberedModelOptions(option.selection)),
608 + restoreSelection: withRememberedModelOptions,
609 optionDescriptors: providerOptionDescriptors,
610 onUpdateOptionSelections: (options) => {
611 rememberModelOptions(
apps/mobile/src/features/threads/ThreadSettingsSheet.tsx
+18 -4
@@ -28,7 +28,15 @@ import { useNavigation, useRoute, type RouteProp } from "@react-navigation/nativ
28 import { type NativeStackNavigationProp } from "@react-navigation/native-stack";
29 import * as Haptics from "expo-haptics";
30 import { AsyncResult } from "effect/reactivity";
31 -import { createContext, use, useEffect, useRef, useState, type ReactNode } from "react";
31 +import {
32 + createContext,
33 + use,
34 + useEffect,
35 + useEffectEvent,
36 + useRef,
37 + useState,
38 + type ReactNode,
39 +} from "react";
40 import { Platform, Pressable, RefreshControl, ScrollView, TextInput, View } from "react-native";
41 import Animated, { FadeIn, FadeOut, LinearTransition } from "react-native-reanimated";
42 import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -51,7 +59,10 @@ import {
59 import { applyProviderOptionSelection } from "../../lib/providerOptions";
60 import { resolveProviderOptionDescriptors } from "../../lib/providerOptions";
61 import { useUniwindTheme } from "../../lib/useUniwindTheme";
54 -import { rememberModelOptions } from "../../state/use-model-option-memory";
62 +import {
63 + rememberModelOptions,
64 + withRememberedModelOptions,
65 +} from "../../state/use-model-option-memory";
66 import { NativeStackScreenOptions, nativeHeaderScrollEdgeEffects } from "../../native/StackHeader";
67 import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
68 import { ChatGptSharingStatus } from "./ChatGptSharingStatus";
@@ -234,6 +245,7 @@ type ThreadSettingsSessionProps = {
245 readonly selectedModel: ModelSelection | null;
246 readonly reportedModelSelection?: ModelSelection | null;
247 readonly onSelectModel: (option: ModelOption) => void;
248 + readonly restoreSelection?: (selection: ModelSelection) => ModelSelection;
249 readonly optionDescriptors: ReadonlyArray<ProviderOptionDescriptor>;
250 readonly onUpdateOptionSelections: (selections: ReadonlyArray<ProviderOptionSelection>) => void;
251 readonly runtimeMode: RuntimeMode;
@@ -533,6 +545,7 @@ function ThreadSettingsSessionProvider(
545 current,
546 pressed: option,
547 pressedIsApplied: isApplied(option),
548 + restoreSelection: props.restoreSelection,
549 }),
550 );
551 };
@@ -1122,10 +1135,10 @@ function ThreadSettingsModelsScreen() {
1135 const usesNativeMailSearchToolbar = useNativeMailSearchToolbar();
1136 const theme = useUniwindTheme();
1137 const hasCustomCatalogFilter = session.providerFilter !== null || session.showLegacy;
1125 - const commitAndClose = () => {
1138 + const commitAndClose = useEffectEvent(() => {
1139 if (!session.commitPendingModel()) return;
1140 presentation.onClose();
1128 - };
1141 + });
1142 const providerFilters = [
1143 { id: "all-providers", title: "All providers", value: null },
1144 { id: "favorites", title: "Favorites", value: FAVORITES_PROVIDER_FILTER },
@@ -1455,6 +1468,7 @@ export function NewTaskThreadSettingsRouteScreen() {
1468 providerGroups={flow.providerGroups}
1469 selectedModel={flow.selectedModel}
1470 onSelectModel={(option) => flow.setSelectedModelKey(option.key, option.selection.options)}
1471 + restoreSelection={withRememberedModelOptions}
1472 optionDescriptors={optionDescriptors}
1473 onUpdateOptionSelections={flow.setSelectedModelOptions}
1474 runtimeMode={flow.runtimeMode}
apps/mobile/src/features/threads/thread-settings-sheet-state.test.ts
+94 -13
@@ -1,8 +1,16 @@
1 -import { describe, expect, it } from "vite-plus/test";
1 +import { afterEach, beforeEach, describe, expect, it } from "@effect/vitest";
2 +import { vi } from "vite-plus/test";
3
4 import { ProviderInstanceId, type ProviderOptionSelection } from "@t3tools/contracts";
5 +import { getProviderOptionDescriptors } from "@t3tools/shared/model";
6
7 import type { ModelOption } from "../../lib/modelOptions";
8 +import { appAtomRegistry } from "../../state/atom-registry";
9 +import { modelOptionMemoryAtom } from "../../state/use-composer-drafts";
10 +import {
11 + rememberModelOptions,
12 + withRememberedModelOptions,
13 +} from "../../state/use-model-option-memory";
14 import {
15 canCommitPendingModel,
16 favoritesFirst,
@@ -23,7 +31,30 @@ function modelOption(
31 providerDriver: "codex",
32 isDefault: false,
33 isLegacy: false,
26 - capabilities: null,
34 + capabilities: {
35 + optionDescriptors: [
36 + {
37 + id: "effort",
38 + label: "Reasoning",
39 + type: "select",
40 + options: [
41 + { id: "medium", label: "Medium", isDefault: true },
42 + { id: "high", label: "High" },
43 + ],
44 + currentValue: "medium",
45 + },
46 + {
47 + id: "serviceTier",
48 + label: "Service Tier",
49 + type: "select",
50 + options: [
51 + { id: "default", label: "Standard", isDefault: true },
52 + { id: "priority", label: "Fast" },
53 + ],
54 + currentValue: "default",
55 + },
56 + ],
57 + },
58 selection: {
59 instanceId: ProviderInstanceId.make("codex"),
60 model,
@@ -32,6 +63,16 @@ function modelOption(
63 };
64 }
65
66 +beforeEach(() => {
67 + vi.useFakeTimers();
68 +});
69 +
70 +afterEach(() => {
71 + vi.clearAllTimers();
72 + vi.useRealTimers();
73 + appAtomRegistry.set(modelOptionMemoryAtom, {});
74 +});
75 +
76 describe("thread settings sheet state", () => {
77 it("keeps favorites in catalog order ahead of other models", () => {
78 const models = [
@@ -101,7 +142,8 @@ describe("thread settings sheet state", () => {
142 ).toBeNull();
143 });
144
104 - it("preserves staged options when the highlighted model is pressed again", () => {
145 + it("preserves in-progress edits when the staged model is pressed again", () => {
146 + rememberModelOptions("codex", "gpt-next", [{ id: "effort", value: "medium" }]);
147 const pending = modelOption("gpt-next", [{ id: "effort", value: "high" }]);
148
149 expect(
@@ -109,20 +151,59 @@ describe("thread settings sheet state", () => {
151 current: pending,
152 pressed: modelOption("gpt-next"),
153 pressedIsApplied: false,
112 - }),
113 - ).toBe(pending);
154 + restoreSelection: withRememberedModelOptions,
155 + })?.selection.options,
156 + ).toEqual([{ id: "effort", value: "high" }]);
157 + });
158 +
159 + it("previews remembered options before Save when switching models", () => {
160 + const remembered = [
161 + { id: "effort", value: "high" },
162 + { id: "serviceTier", value: "priority" },
163 + ];
164 + rememberModelOptions("codex", "gpt-other", remembered);
165 + const pressed = modelOption("gpt-other");
166 +
167 + const pending = pendingModelAfterPress({
168 + current: modelOption("gpt-next"),
169 + pressed,
170 + pressedIsApplied: false,
171 + restoreSelection: withRememberedModelOptions,
172 + });
173 +
174 + expect(pending?.selection).toEqual({ ...pressed.selection, options: remembered });
175 + const preview = getProviderOptionDescriptors({
176 + caps: pressed.capabilities!,
177 + selections: pending?.selection.options,
178 + });
179 + expect(preview.map(({ id, currentValue }) => ({ id, value: currentValue }))).toEqual(
180 + remembered,
181 + );
182 + expect(pending?.selection).toEqual(withRememberedModelOptions(pressed.selection));
183 });
184
116 - it("stages a different model", () => {
185 + it("keeps catalog defaults for scheduled-task picks even when options are remembered", () => {
186 + rememberModelOptions("codex", "gpt-other", [
187 + { id: "effort", value: "high" },
188 + { id: "serviceTier", value: "priority" },
189 + ]);
190 const pressed = modelOption("gpt-other");
191
119 - expect(
120 - pendingModelAfterPress({
121 - current: modelOption("gpt-next"),
122 - pressed,
123 - pressedIsApplied: false,
124 - }),
125 - ).toBe(pressed);
192 + const pending = pendingModelAfterPress({
193 + current: modelOption("gpt-next"),
194 + pressed,
195 + pressedIsApplied: false,
196 + });
197 +
198 + expect(pending?.selection).toEqual(pressed.selection);
199 + const preview = getProviderOptionDescriptors({
200 + caps: pressed.capabilities!,
201 + selections: pending?.selection.options,
202 + });
203 + expect(preview.map(({ id, currentValue }) => ({ id, value: currentValue }))).toEqual([
204 + { id: "effort", value: "medium" },
205 + { id: "serviceTier", value: "default" },
206 + ]);
207 });
208
209 it("cannot select a hidden model exposed only for visibility management", () => {
apps/mobile/src/features/threads/thread-settings-sheet-state.ts
+8 -2
@@ -1,5 +1,5 @@
1 import type { ModelOption, ProviderGroup } from "../../lib/modelOptions";
2 -import type { ProviderInstanceId } from "@t3tools/contracts";
2 +import type { ModelSelection, ProviderInstanceId } from "@t3tools/contracts";
3
4 export function modelFavoriteKey(provider: ProviderInstanceId, model: string): string {
5 return `${provider}:${model}`;
@@ -39,11 +39,17 @@ export function pendingModelAfterPress(input: {
39 readonly current: ModelOption | null;
40 readonly pressed: ModelOption;
41 readonly pressedIsApplied: boolean;
42 + readonly restoreSelection?: (selection: ModelSelection) => ModelSelection;
43 }): ModelOption | null {
44 if (input.pressedIsApplied) {
45 return null;
46 }
46 - return input.current?.key === input.pressed.key ? input.current : input.pressed;
47 + if (input.current?.key === input.pressed.key) {
48 + return input.current;
49 + }
50 + return input.restoreSelection
51 + ? { ...input.pressed, selection: input.restoreSelection(input.pressed.selection) }
52 + : input.pressed;
53 }
54
55 export function canCommitPendingModel(