Skip to content

Commit d6b446e

Browse files
only21milclaude
andcommitted
fix(web): re-picking a Cursor thread's unavailable model keeps its options
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d76690b commit d6b446e

2 files changed

Lines changed: 50 additions & 23 deletions

File tree

‎apps/web/src/components/chat/useComposerSelection.browser.test.tsx‎

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { useComposerDraftStore } from "../../composerDraftStore";
1717
import { useComposerSelection } from "./useComposerSelection";
1818

1919
const environmentId = EnvironmentId.make("environment-local");
20-
const threadRef = scopeThreadRef(environmentId, ThreadId.make("thread-cursor"));
2120
const cursor = ProviderInstanceId.make("cursor");
2221
const stored = createModelSelection(cursor, "claude-opus-5-5", [{ id: "effort", value: "medium" }]);
2322

@@ -38,24 +37,25 @@ const providers: ReadonlyArray<ServerProvider> = [
3837
];
3938

4039
// The hook reads only the thread's identity and stored selection.
41-
const activeThread = {
42-
environmentId,
43-
id: threadRef.threadId,
44-
modelSelection: stored,
45-
} as EnvironmentThreadShell;
40+
function cursorThread(id: string) {
41+
return { environmentId, id: ThreadId.make(id), modelSelection: stored } as EnvironmentThreadShell;
42+
}
4643

47-
function Picker() {
44+
function Picker(props: {
45+
thread: EnvironmentThreadShell;
46+
runtime: Parameters<typeof useComposerSelection>[0]["activeRuntime"];
47+
}) {
4848
const { onProviderModelSelectStable } = useComposerSelection({
4949
environmentId,
50-
composerDraftTarget: threadRef,
50+
composerDraftTarget: scopeThreadRef(environmentId, props.thread.id),
5151
draftThread: null,
52-
activeThread,
53-
activeRuntime: null,
52+
activeThread: props.thread,
53+
activeRuntime: props.runtime,
5454
activeProjectSettings: { settings: { newWorktreesStartFromOrigin: false } },
5555
settings: DEFAULT_UNIFIED_SETTINGS,
5656
providerStatuses: providers,
5757
lockedProvider: null,
58-
supportsProviderSwitchingViaHandoff: false,
58+
supportsProviderSwitchingViaHandoff: true,
5959
multipleModelSelections: null,
6060
runtimeMode: "full-access",
6161
interactionMode: "default",
@@ -73,12 +73,27 @@ function Picker() {
7373
);
7474
}
7575

76-
it("keeps a Cursor thread's stored model when the user re-picks its unavailable row", async () => {
77-
await using _screen = await render(<Picker />);
76+
it("keeps a Cursor thread's stored model and options when the user re-picks its unavailable row", async () => {
77+
const thread = cursorThread("thread-cursor");
78+
await using _screen = await render(<Picker thread={thread} runtime={null} />);
79+
await page.getByRole("button", { name: "Pick the stored model" }).click();
80+
81+
const draft = useComposerDraftStore
82+
.getState()
83+
.getComposerDraft(scopeThreadRef(environmentId, thread.id));
84+
expect(draft?.modelSelectionByProvider[cursor] ?? thread.modelSelection).toEqual(stored);
85+
});
86+
87+
it("switches back to the thread's stored model while the session runs on another instance", async () => {
88+
const thread = cursorThread("thread-cursor-handoff");
89+
const runtime = { providerInstanceId: ProviderInstanceId.make("codex") } as Parameters<
90+
typeof useComposerSelection
91+
>[0]["activeRuntime"];
92+
await using _screen = await render(<Picker thread={thread} runtime={runtime} />);
7893
await page.getByRole("button", { name: "Pick the stored model" }).click();
7994

80-
expect(
81-
useComposerDraftStore.getState().getComposerDraft(threadRef)?.modelSelectionByProvider[cursor]
82-
?.model,
83-
).toBe("claude-opus-5-5");
95+
const draft = useComposerDraftStore
96+
.getState()
97+
.getComposerDraft(scopeThreadRef(environmentId, thread.id));
98+
expect(draft?.activeProvider).toBe(cursor);
8499
});

‎apps/web/src/components/chat/useComposerSelection.ts‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,20 @@ export function useComposerSelection(input: ComposerSelectionInput) {
182182
model,
183183
{ preserveUnavailableSelection: true },
184184
);
185-
if (!resolvedModel) {
185+
const threadRef = scopeThreadRef(activeThread.environmentId, activeThread.id);
186+
const draft = useComposerDraftStore.getState().getComposerDraft(threadRef);
187+
const shownInstanceId =
188+
draft?.activeProvider ??
189+
activeRuntime?.providerInstanceId ??
190+
activeThread.modelSelection.instanceId;
191+
const shownSelection =
192+
draft?.modelSelectionByProvider[shownInstanceId] ?? activeThread.modelSelection;
193+
if (
194+
!resolvedModel ||
195+
(instanceId === shownInstanceId &&
196+
shownSelection.instanceId === instanceId &&
197+
shownSelection.model === resolvedModel)
198+
) {
186199
if (options?.focusComposer !== false) scheduleComposerFocus();
187200
return;
188201
}
@@ -209,11 +222,10 @@ export function useComposerSelection(input: ComposerSelectionInput) {
209222
if (options?.focusComposer !== false) scheduleComposerFocus();
210223
return;
211224
}
212-
setComposerDraftModelSelection(
213-
scopeThreadRef(activeThread.environmentId, activeThread.id),
214-
nextModelSelection,
215-
{ explicit: true, replaceOptions: true },
216-
);
225+
setComposerDraftModelSelection(threadRef, nextModelSelection, {
226+
explicit: true,
227+
replaceOptions: true,
228+
});
217229
setStickyComposerModelSelection(nextModelSelection);
218230
if (options?.focusComposer !== false) scheduleComposerFocus();
219231
};

0 commit comments

Comments
 (0)