The best way to control Claude Code, Codex and more from any computer or phone
fix(web,mobile): no pending handoff for a provider the next send would skip (#19523)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Jair Meza committed
Oct 20, 2026 at 01:16 UTC
a9af48a3d2a0a9e1b728767b5feebc39f3f0aa73
3 files changed
+159
-13
apps/mobile/src/state/thread-task-permissions.test.ts
+146
-10
@@ -1,4 +1,21 @@
1
-import { AuthOrchestrationOperateScope, RuntimeRequestId } from "@t3tools/contracts";
1
+import {
2
+ AuthOrchestrationOperateScope,
3
+ DEFAULT_SERVER_SETTINGS,
4
+ MessageId,
5
+ ProjectId,
6
+ ProviderDriverKind,
7
+ ProviderInstanceId,
8
+ RunId,
9
+ RuntimeRequestId,
10
+ TurnItemId,
11
+ type ModelSelection,
12
+ type OrchestrationV2ThreadProjection,
13
+ type ServerConfig,
14
+} from "@t3tools/contracts";
15
+import {
16
+ v2Now,
17
+ v2Projection,
18
+} from "../../../../packages/client-runtime/src/state/orchestrationV2TestFixtures";
19
import type { DraftComposerImageAttachment } from "../lib/composerImages";
20
import type { PendingThreadRequests } from "@t3tools/client-runtime/state/thread-requests";
21
import { AsyncResult, type Atom } from "effect/reactivity";
@@ -7,7 +24,13 @@ import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
24
const state = vi.hoisted(() => ({
25
grantedEnvironments: new Set<string>(),
26
connectionState: "connected",
10
- draft: { text: "Keep my draft", attachments: [] as DraftComposerImageAttachment[] },
27
+ draft: {
28
+ text: "Keep my draft",
29
+ attachments: [] as DraftComposerImageAttachment[],
30
+ modelSelection: undefined as ModelSelection | undefined,
31
+ },
32
+ serverConfig: null as ServerConfig | null,
33
+ projection: null as OrchestrationV2ThreadProjection | null,
34
pendingRequests: { approvals: [], userInputs: [] } as PendingThreadRequests,
35
enqueue: vi.fn(async () => undefined),
36
clearDraft: vi.fn(),
@@ -25,6 +48,7 @@ const state = vi.hoisted(() => ({
48
thread: {
49
id: "thread",
50
environmentId: "secondary",
51
+ projectId: "project",
52
modelSelection: { instanceId: "codex", model: "gpt-5.4" },
53
runtimeMode: "full-access",
54
interactionMode: "default",
@@ -70,15 +94,13 @@ vi.mock("./use-thread-selection", () => ({
94
selectedThreadCreation: null,
95
selectedEnvironmentRuntime: {
96
connectionState: state.connectionState,
73
- serverConfig: {
74
- providers: [{ instanceId: "codex", driver: "codex" }],
75
- environment: { capabilities: {} },
76
- },
97
+ serverConfig: state.serverConfig,
98
},
99
}),
100
}));
101
vi.mock("./use-thread-detail", () => ({
81
- useSelectedThreadProjection: () => null,
102
+ useSelectedThreadProjection: () =>
103
+ state.projection === null ? null : { projection: state.projection },
104
useSelectedThreadVisibleTurnItems: () => [],
105
useSelectedThreadPendingRequests: () => state.pendingRequests,
106
}));
@@ -126,7 +148,7 @@ vi.mock("./use-composer-drafts", async () => {
148
mergeComposerDraftContent: vi.fn(),
149
removeComposerDraftAttachment: vi.fn(),
150
useComposerDraft: () => state.draft,
129
- useComposerDraftSettings: () => ({}),
151
+ useComposerDraftSettings: () => state.draft,
152
questionAttachmentDraftsAtom: () => Atom.make({}),
153
};
154
});
@@ -144,7 +166,6 @@ vi.mock("../lib/commandMetadata", () => ({
166
}),
167
}));
168
vi.mock("../lib/copyTextWithHaptic", () => ({ copyTextWithHaptic: vi.fn() }));
147
-vi.mock("../lib/modelOptions", () => ({ isModelSelectionUnavailable: () => false }));
169
vi.mock("./use-remote-environment-registry", () => ({ setPendingConnectionError: vi.fn() }));
170
171
import { useThreadComposerState } from "./use-thread-composer-state";
@@ -153,7 +174,12 @@ import { useSelectedThreadRequests } from "./use-selected-thread-requests";
174
beforeEach(() => {
175
state.grantedEnvironments = new Set(["primary"]);
176
state.connectionState = "connected";
156
- state.draft = { text: "Keep my draft", attachments: [] };
177
+ state.draft = { text: "Keep my draft", attachments: [], modelSelection: undefined };
178
+ state.projection = null;
179
+ state.serverConfig = {
180
+ providers: [{ instanceId: "codex", driver: "codex", enabled: true }],
181
+ environment: { capabilities: {} },
182
+ } as unknown as ServerConfig;
183
state.pendingRequests = {
184
approvals: [
185
{
@@ -260,3 +286,113 @@ describe("mobile task permissions", () => {
286
});
287
});
288
});
289
+
290
+describe("mobile handoff preview and submission", () => {
291
+ it("follows project enablement and provider availability for the selected destination", async () => {
292
+ state.grantedEnvironments.add("secondary");
293
+ const instanceId = ProviderInstanceId.make("antigravity");
294
+ const projectId = ProjectId.make(state.thread.projectId);
295
+ const selection = { instanceId, model: "gemini" };
296
+ const provider = {
297
+ instanceId,
298
+ driver: ProviderDriverKind.make("antigravity"),
299
+ enabled: false,
300
+ installed: true,
301
+ auth: { status: "authenticated" as const },
302
+ availability: "available" as "available" | "unavailable",
303
+ models: [{ slug: selection.model }],
304
+ };
305
+ const projectOverride = { enabled: false };
306
+ state.serverConfig = {
307
+ ...state.serverConfig,
308
+ providers: [provider],
309
+ settings: {
310
+ ...DEFAULT_SERVER_SETTINGS,
311
+ providerInstances: { [instanceId]: { driver: provider.driver, enabled: false } },
312
+ projectSettingsOverrides: {
313
+ [projectId]: { providerInstances: { [instanceId]: projectOverride } },
314
+ },
315
+ },
316
+ } as unknown as ServerConfig;
317
+ state.draft.modelSelection = selection;
318
+ const source = v2Projection.thread.modelSelection;
319
+ state.projection = {
320
+ ...v2Projection,
321
+ runs: [
322
+ {
323
+ id: RunId.make("source-run"),
324
+ threadId: v2Projection.thread.id,
325
+ ordinal: 1,
326
+ providerInstanceId: source.instanceId,
327
+ modelSelection: source,
328
+ providerThreadId: null,
329
+ userMessageId: MessageId.make("source-message"),
330
+ rootNodeId: null,
331
+ activeAttemptId: null,
332
+ status: "completed",
333
+ requestedAt: v2Now,
334
+ startedAt: v2Now,
335
+ completedAt: v2Now,
336
+ checkpointId: null,
337
+ contextHandoffId: null,
338
+ },
339
+ ],
340
+ visibleTurnItems: [
341
+ {
342
+ position: 0,
343
+ visibility: "local",
344
+ sourceThreadId: v2Projection.thread.id,
345
+ sourceItemId: TurnItemId.make("reply"),
346
+ item: {
347
+ id: TurnItemId.make("reply"),
348
+ threadId: v2Projection.thread.id,
349
+ runId: RunId.make("source-run"),
350
+ nodeId: null,
351
+ providerThreadId: null,
352
+ providerTurnId: null,
353
+ nativeItemRef: null,
354
+ parentItemId: null,
355
+ ordinal: 1,
356
+ type: "assistant_message",
357
+ messageId: MessageId.make("reply"),
358
+ status: "completed",
359
+ title: null,
360
+ text: "Task started",
361
+ streaming: false,
362
+ startedAt: v2Now,
363
+ completedAt: v2Now,
364
+ updatedAt: v2Now,
365
+ },
366
+ },
367
+ ],
368
+ };
369
+
370
+ const disabled = useThreadComposerState();
371
+ expect(disabled.pendingHandoff).toBeNull();
372
+ expect(await disabled.onSendMessage()).toBeNull();
373
+ expect(state.enqueue).not.toHaveBeenCalled();
374
+ expect(state.clearDraft).not.toHaveBeenCalled();
375
+
376
+ projectOverride.enabled = true;
377
+ expect(useThreadComposerState().pendingHandoff).toEqual({ from: [source], to: selection });
378
+
379
+ provider.availability = "unavailable";
380
+ const unavailable = useThreadComposerState();
381
+ expect(unavailable.pendingHandoff).toBeNull();
382
+ expect(await unavailable.onSendMessage()).toBeNull();
383
+ expect(state.enqueue).not.toHaveBeenCalled();
384
+ expect(state.clearDraft).not.toHaveBeenCalled();
385
+
386
+ provider.availability = "available";
387
+ const available = useThreadComposerState();
388
+ expect(available.pendingHandoff).toEqual({ from: [source], to: selection });
389
+ expect(await available.onSendMessage()).toBe("message");
390
+ expect(state.enqueue).toHaveBeenCalledExactlyOnceWith(
391
+ expect.objectContaining({
392
+ modelSelection: selection,
393
+ text: "Keep my draft",
394
+ }),
395
+ );
396
+ expect(state.clearDraft).toHaveBeenCalledTimes(1);
397
+ });
398
+});
apps/mobile/src/state/use-thread-composer-state.ts
+5
-2
@@ -300,10 +300,13 @@ export function useThreadComposerState() {
300
const selectedThreadQueueCount = selectedThreadQueuedMessages.length;
301
const selectedThread = selectedThreadShell;
302
const modelSelection = selectedDraft.modelSelection ?? selectedThread?.modelSelection ?? null;
303
+ const serverConfig = selectedEnvironmentRuntime?.serverConfig;
304
const pendingHandoff = resolvePendingHandoff(
305
selectedThreadProjection?.projection,
305
- modelSelection,
306
- selectedEnvironmentRuntime?.serverConfig?.providers ?? [],
306
+ isModelSelectionUnavailable(serverConfig, modelSelection, selectedThread?.projectId ?? null)
307
+ ? null
308
+ : modelSelection,
309
+ serverConfig?.providers ?? [],
310
);
311
const runtimeMode = selectedDraft.runtimeMode ?? selectedThread?.runtimeMode ?? null;
312
const selectedProvider = selectedEnvironmentRuntime?.serverConfig?.providers.find(
apps/web/src/components/ChatView.tsx
+8
-1
@@ -5433,9 +5433,16 @@ export default function ChatView(props: ChatViewProps) {
5433
item.type === "user_message" &&
5434
(item.text.trim().toLowerCase() !== "/compact" || item.attachments.length > 0),
5435
);
5436
+ const pendingHandoffSelection = composerSelectedModelSelection ?? activeThread?.modelSelection;
5437
+ const pendingHandoffSelectionUsable = providerInstanceEntries.some(
5438
+ (entry) =>
5439
+ entry.instanceId === pendingHandoffSelection?.instanceId &&
5440
+ entry.enabled &&
5441
+ entry.isAvailable,
5442
+ );
5443
const pendingHandoff = resolvePendingHandoff(
5444
serverProjection,
5438
- composerSelectedModelSelection ?? activeThread?.modelSelection,
5445
+ pendingHandoffSelectionUsable ? pendingHandoffSelection : null,
5446
providerStatuses,
5447
);
5448
const compactThreadUnavailable =