The best way to control Claude Code, Codex and more from any computer or phone
fix(web): Cursor threads keep a stored model the catalog doesn't list (#24872)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Victor committed
Nov 12, 2026 at 17:17 UTC
a98bc6967659f53555ad9fdb409f2ef1ab4e4a4c
7 files changed
+239
-7
apps/web/src/components/chat/ModelPickerContent.tsx
+3
-1
@@ -113,7 +113,9 @@ function shouldIncludeModelPickerOption(input: {
113
if (isProviderInstancePickerReady(input.entry)) return true;
114
return (
115
input.entry.enabled &&
116
- (input.entry.driverKind === "opencode" || input.entry.driverKind === "antigravity") &&
116
+ (input.entry.driverKind === "opencode" ||
117
+ input.entry.driverKind === "antigravity" ||
118
+ input.entry.driverKind === "cursor") &&
119
input.entry.instanceId === input.activeInstanceId &&
120
input.option.slug === input.activeModel &&
121
input.option.isUnavailable === true
apps/web/src/components/chat/TraitsPicker.tsx
+1
-1
@@ -122,7 +122,7 @@ function getSelectedTraits(
122
) {
123
const caps = getProviderModelCapabilities(models, model, provider, includePlanAgent);
124
const modelIsUnavailable =
125
- provider === "opencode" &&
125
+ (provider === "opencode" || provider === "cursor") &&
126
!models.some((candidate) => candidate.slug === normalizeModelSlug(model, provider));
127
const descriptors = modelIsUnavailable
128
? buildUnavailableModelOptionDescriptors(
apps/web/src/components/chat/composerProviderState.tsx
+1
-1
@@ -86,7 +86,7 @@ export function getComposerProviderState(input: ComposerProviderStateInput): Com
86
promptInjectionState = "none",
87
includePlanAgent,
88
} = input;
89
- if (provider === "opencode") {
89
+ if (provider === "opencode" || provider === "cursor") {
90
const normalizedModel = normalizeModelSlug(model, provider);
91
const modelIsInCatalog = models.some((candidate) => candidate.slug === normalizedModel);
92
if (!modelIsInCatalog) {
apps/web/src/components/chat/useComposerSelection.browser.test.tsx
new
+177
@@ -0,0 +1,177 @@
1
+import { scopeThreadRef } from "@t3tools/client-runtime/environment";
2
+import type { AtomCommandResult } from "@t3tools/client-runtime/state/runtime";
3
+import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
4
+import {
5
+ EnvironmentId,
6
+ ProviderDriverKind,
7
+ ProviderInstanceId,
8
+ ThreadId,
9
+ type ServerProvider,
10
+} from "@t3tools/contracts";
11
+import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings";
12
+import { createModelSelection } from "@t3tools/shared/model";
13
+import * as Cause from "effect/Cause";
14
+import { AsyncResult, Atom } from "effect/reactivity";
15
+import { expect, it, vi } from "vite-plus/test";
16
+import { page } from "vite-plus/test/browser";
17
+
18
+const mocks = vi.hoisted(() => ({
19
+ setModelSelection: null as ((value: unknown) => Promise<AtomCommandResult<void, unknown>>) | null,
20
+}));
21
+
22
+vi.mock(import("../../state/use-orchestration-command"), async (importOriginal) => ({
23
+ ...(await importOriginal()),
24
+ useOrchestrationCommand: (() => (value: unknown) => mocks.setModelSelection?.(value)) as never,
25
+}));
26
+
27
+vi.mock(import("../../state/threads"), async (original) => {
28
+ const actual = await original();
29
+ return {
30
+ ...actual,
31
+ environmentThreadShells: {
32
+ ...actual.environmentThreadShells,
33
+ threadShellAtom: ((ref: { threadId: string }) => shellAtom(ref.threadId)) as never,
34
+ },
35
+ };
36
+});
37
+
38
+import { render } from "../../../test/render";
39
+import { deriveEffectiveComposerModelState, useComposerDraftStore } from "../../composerDraftStore";
40
+import { AppAtomRegistryProvider, appAtomRegistry } from "../../rpc/atomRegistry";
41
+import { useComposerSelection } from "./useComposerSelection";
42
+
43
+// Kept alive so a shell set before the hook mounts is still there when it saves a pick.
44
+const shellAtom = Atom.family((_threadId: string) => Atom.make<unknown>(null).pipe(Atom.keepAlive));
45
+
46
+function setup() {
47
+ const setModelSelection = vi.fn<(value: unknown) => Promise<AtomCommandResult<void, unknown>>>();
48
+ mocks.setModelSelection = setModelSelection;
49
+ return { setModelSelection };
50
+}
51
+
52
+const environmentId = EnvironmentId.make("environment-local");
53
+const cursor = ProviderInstanceId.make("cursor");
54
+const stored = createModelSelection(cursor, "claude-opus-5-5", [{ id: "effort", value: "medium" }]);
55
+
56
+const providers: ReadonlyArray<ServerProvider> = [
57
+ {
58
+ instanceId: cursor,
59
+ driver: ProviderDriverKind.make("cursor"),
60
+ enabled: true,
61
+ installed: true,
62
+ version: null,
63
+ status: "ready",
64
+ auth: { status: "authenticated" },
65
+ checkedAt: "2026-01-01T00:00:00.000Z",
66
+ models: [{ slug: "auto-smart", name: "Auto", isCustom: false, capabilities: {} }],
67
+ slashCommands: [],
68
+ skills: [],
69
+ },
70
+];
71
+
72
+// The hook reads only the thread's identity and stored selection.
73
+function cursorThread(id: string) {
74
+ return { environmentId, id: ThreadId.make(id), modelSelection: stored } as EnvironmentThreadShell;
75
+}
76
+
77
+function Picker(props: {
78
+ thread: EnvironmentThreadShell;
79
+ runtime: Parameters<typeof useComposerSelection>[0]["activeRuntime"];
80
+ model?: string;
81
+}) {
82
+ const { onProviderModelSelectStable } = useComposerSelection({
83
+ environmentId,
84
+ composerDraftTarget: scopeThreadRef(environmentId, props.thread.id),
85
+ draftThread: null,
86
+ activeThread: props.thread,
87
+ activeRuntime: props.runtime,
88
+ activeProjectSettings: { settings: { newWorktreesStartFromOrigin: false } },
89
+ settings: DEFAULT_UNIFIED_SETTINGS,
90
+ providerStatuses: providers,
91
+ lockedProvider: null,
92
+ supportsProviderSwitchingViaHandoff: true,
93
+ multipleModelSelections: null,
94
+ runtimeMode: "full-access",
95
+ isLocalDraftThread: false,
96
+ canOverrideServerThreadEnvMode: false,
97
+ setPendingServerThreadEnvModeEntry: () => {},
98
+ setPendingServerThreadStartFromOriginByThreadId: () => {},
99
+ scheduleComposerFocus: () => {},
100
+ });
101
+ return (
102
+ <button
103
+ type="button"
104
+ onClick={() => onProviderModelSelectStable(cursor, props.model ?? stored.model)}
105
+ >
106
+ Pick the model
107
+ </button>
108
+ );
109
+}
110
+
111
+it("keeps a Cursor thread's stored model and options when the user re-picks its unavailable row", async () => {
112
+ setup();
113
+ const thread = cursorThread("thread-cursor");
114
+ await using _screen = await render(<Picker thread={thread} runtime={null} />);
115
+ await page.getByRole("button", { name: "Pick the model" }).click();
116
+
117
+ await vi.waitFor(() => {
118
+ const draft = useComposerDraftStore
119
+ .getState()
120
+ .getComposerDraft(scopeThreadRef(environmentId, thread.id));
121
+ expect(draft?.modelSelectionByProvider[cursor] ?? thread.modelSelection).toEqual(stored);
122
+ });
123
+});
124
+
125
+it("switches back to the thread's stored model while the session runs on another instance", async () => {
126
+ setup();
127
+ const thread = cursorThread("thread-cursor-handoff");
128
+ const runtime = { providerInstanceId: ProviderInstanceId.make("codex") } as Parameters<
129
+ typeof useComposerSelection
130
+ >[0]["activeRuntime"];
131
+ await using _screen = await render(<Picker thread={thread} runtime={runtime} />);
132
+ await page.getByRole("button", { name: "Pick the model" }).click();
133
+
134
+ await vi.waitFor(() => {
135
+ const draft = useComposerDraftStore
136
+ .getState()
137
+ .getComposerDraft(scopeThreadRef(environmentId, thread.id));
138
+ expect(draft?.activeProvider).toBe(cursor);
139
+ expect(
140
+ deriveEffectiveComposerModelState({
141
+ draft,
142
+ providers,
143
+ selectedProvider: ProviderDriverKind.make("cursor"),
144
+ selectedInstanceId: cursor,
145
+ threadModelSelection: thread.modelSelection,
146
+ projectModelSelection: null,
147
+ settings: DEFAULT_UNIFIED_SETTINGS,
148
+ }),
149
+ ).toEqual({ selectedModel: stored.model, modelOptions: { [cursor]: stored.options } });
150
+ });
151
+});
152
+
153
+it("saves a re-picked model again when its first save failed", async () => {
154
+ const { setModelSelection } = setup();
155
+ setModelSelection
156
+ .mockResolvedValueOnce(AsyncResult.failure(Cause.fail(new Error("offline"))))
157
+ .mockResolvedValue(AsyncResult.success(undefined));
158
+ const thread = cursorThread("thread-cursor-retry");
159
+ appAtomRegistry.set(shellAtom(thread.id), thread);
160
+ await using _screen = await render(
161
+ <AppAtomRegistryProvider>
162
+ <Picker thread={thread} runtime={null} model="auto-smart" />
163
+ </AppAtomRegistryProvider>,
164
+ );
165
+ const pick = page.getByRole("button", { name: "Pick the model" });
166
+ await pick.click();
167
+ await vi.waitFor(() => expect(setModelSelection).toHaveBeenCalledTimes(1));
168
+ await pick.click();
169
+
170
+ const autoSave = expect.objectContaining({
171
+ input: {
172
+ threadId: thread.id,
173
+ modelSelection: expect.objectContaining({ instanceId: cursor, model: "auto-smart" }),
174
+ },
175
+ });
176
+ await vi.waitFor(() => expect(setModelSelection.mock.calls).toEqual([[autoSave], [autoSave]]));
177
+});
apps/web/src/components/chat/useComposerSelection.ts
+18
-2
@@ -152,13 +152,30 @@ export function useComposerSelection(input: ComposerSelectionInput) {
152
return;
153
}
154
}
155
+ // The picker lists an unavailable model only as the active selection, so re-picking keeps it.
156
const resolvedModel = resolveAppModelSelectionForInstance(
157
instanceId,
158
settings,
159
providerStatuses,
160
model,
161
+ { preserveUnavailableSelection: true },
162
);
161
- if (!resolvedModel) {
163
+ const threadRef = scopeThreadRef(activeThread.environmentId, activeThread.id);
164
+ const draft = useComposerDraftStore.getState().getComposerDraft(threadRef);
165
+ const shownInstanceId =
166
+ draft?.activeProvider ??
167
+ activeRuntime?.providerInstanceId ??
168
+ activeThread.modelSelection.instanceId;
169
+ const shownSelection =
170
+ draft?.modelSelectionByProvider[shownInstanceId] ?? activeThread.modelSelection;
171
+ if (
172
+ !resolvedModel ||
173
+ (instanceId === shownInstanceId &&
174
+ shownSelection.instanceId === instanceId &&
175
+ shownSelection.model === resolvedModel)
176
+ ) {
177
+ // Re-picking the shown model keeps its options and saves it again if that save failed.
178
+ if (resolvedModel && !isLocalDraftThread) applyThreadModelPick(threadRef);
179
if (options?.focusComposer !== false) scheduleComposerFocus();
180
return;
181
}
@@ -184,7 +201,6 @@ export function useComposerSelection(input: ComposerSelectionInput) {
201
if (options?.focusComposer !== false) scheduleComposerFocus();
202
return;
203
}
187
- const threadRef = scopeThreadRef(activeThread.environmentId, activeThread.id);
204
setComposerDraftModelSelection(threadRef, nextModelSelection, {
205
explicit: true,
206
replaceOptions: true,
apps/web/src/modelSelection.test.ts
+33
@@ -404,6 +404,11 @@ describe("instance-scoped model selection", () => {
404
availableModel: "gemini-3.1-pro",
405
missingModel: "gemini-3.1-pro-high",
406
},
407
+ {
408
+ driverName: "cursor",
409
+ availableModel: "auto-smart",
410
+ missingModel: "claude-opus-5-5",
411
+ },
412
])("$driverName catalog gaps", ({ driverName, availableModel, missingModel }) => {
413
it("preserves a selected model when a catalog refresh no longer contains it", () => {
414
const providers = [
@@ -510,6 +515,34 @@ describe("instance-scoped model selection", () => {
515
expect(dispatch.modelOptionsForDispatch).toBeUndefined();
516
});
517
518
+ it("sends a Cursor thread's stored model and options when the catalog lacks them", () => {
519
+ const instanceId = ProviderInstanceId.make("cursor");
520
+ const driver = ProviderDriverKind.make("cursor");
521
+ const stored = createModelSelection(instanceId, "claude-opus-5-5", [
522
+ { id: "effort", value: "medium" },
523
+ ]);
524
+ const providers = [provider({ provider: driver, instanceId, models: ["auto-smart"] })];
525
+ const state = deriveEffectiveComposerModelState({
526
+ draft: null,
527
+ providers,
528
+ selectedProvider: driver,
529
+ selectedInstanceId: instanceId,
530
+ threadModelSelection: stored,
531
+ projectModelSelection: null,
532
+ settings: settingsWithProviderInstances(),
533
+ });
534
+ const dispatch = getComposerProviderState({
535
+ provider: driver,
536
+ model: state.selectedModel,
537
+ models: providers[0]!.models,
538
+ modelOptions: state.modelOptions?.[instanceId],
539
+ });
540
+
541
+ expect(
542
+ createModelSelection(instanceId, state.selectedModel, dispatch.modelOptionsForDispatch),
543
+ ).toEqual(stored);
544
+ });
545
+
546
it("preserves an explicit draft OpenCode selection while the catalog is empty", () => {
547
const instanceId = ProviderInstanceId.make("opencode_work");
548
const driver = ProviderDriverKind.make("opencode");
apps/web/src/modelSelection.ts
+6
-2
@@ -80,7 +80,9 @@ function appendUnavailableDynamicModelSelection(
80
selectedModel: string | null | undefined,
81
hiddenModels: ReadonlyArray<string>,
82
): AppModelOption[] {
83
- if (provider !== "opencode" && provider !== "antigravity") return options;
83
+ if (provider !== "opencode" && provider !== "antigravity" && provider !== "cursor") {
84
+ return options;
85
+ }
86
const slug = normalizeCustomModelSlug(selectedModel);
87
if (!slug) return options;
88
if (provider === "antigravity" && slug === ANTIGRAVITY_DEFAULT_MODEL) return options;
@@ -282,7 +284,9 @@ export function resolveAppModelSelectionForInstance(
284
}
285
if (
286
resolutionOptions?.preserveUnavailableSelection &&
285
- (entry.driverKind === "opencode" || entry.driverKind === "antigravity")
287
+ (entry.driverKind === "opencode" ||
288
+ entry.driverKind === "antigravity" ||
289
+ entry.driverKind === "cursor")
290
) {
291
const unavailableSelection = normalizeCustomModelSlug(selectedModel);
292
const hiddenModels = readInstanceModelPreferences(settings, entry.instanceId).hiddenModels;