The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): a new thread's first message no longer returns to the composer after a lost launch reply (#32330)
Julius Marminge committed
Nov 13, 2026 at 14:04 UTC
134ab31276df64b0d021d2cf38537021043b29d7
2 files changed
+126
-5
apps/mobile/src/state/threadOutboxDelivery.permissions.test.ts
+103
-1
@@ -10,7 +10,7 @@ import {
10
import * as Cause from "effect/Cause";
11
import { AsyncResult, type Atom } from "effect/reactivity";
12
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
13
-import type { QueuedThreadMessage } from "./thread-outbox-model";
13
+import { threadOutboxRetryDelayMs, type QueuedThreadMessage } from "./thread-outbox-model";
14
15
const state = vi.hoisted(() => ({
16
draftText: "Keep this draft separate",
@@ -501,6 +501,108 @@ describe("queued task operation access", () => {
501
);
502
});
503
504
+describe("queued task whose launch reply is lost", () => {
505
+ const queuedTask = (creation: Partial<NonNullable<QueuedThreadMessage["creation"]>> = {}) =>
506
+ message({
507
+ threadId: ThreadId.make("new-thread"),
508
+ text: "My dictated idea",
509
+ modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
510
+ creation: {
511
+ projectId: ProjectId.make("project"),
512
+ projectCwd: "/repo",
513
+ workspaceMode: "local",
514
+ branch: null,
515
+ worktreePath: null,
516
+ ...creation,
517
+ },
518
+ });
519
+
520
+ /** The server creates the thread, but the launch reply is lost; the thread then shows up. */
521
+ async function loseLaunchReply(queued: QueuedThreadMessage, edit?: string): Promise<void> {
522
+ setOperateGrant("secondary", true);
523
+ vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout", "Date"] });
524
+ state.cleanups.push(() => vi.useRealTimers());
525
+ await state.manager.enqueue(queued);
526
+ state.start.mockImplementationOnce(async () => {
527
+ if (edit !== undefined) await state.manager.update({ ...queued, text: edit });
528
+ return AsyncResult.failure(Cause.fail(new Error("Socket is not connected")));
529
+ });
530
+ await runDrain();
531
+ expect(remaining()).toHaveLength(1);
532
+ appAtomRegistry.set(state.threadShells, [state.thread, { ...state.thread, id: "new-thread" }]);
533
+ }
534
+
535
+ async function fireRetry(): Promise<void> {
536
+ const settled = Promise.withResolvers<void>();
537
+ const release = appAtomRegistry.subscribe(dispatchingQueuedMessageIdAtom, (id) => {
538
+ if (id === null) settled.resolve();
539
+ });
540
+ vi.advanceTimersByTime(threadOutboxRetryDelayMs(1));
541
+ await settled.promise.finally(release);
542
+ }
543
+
544
+ it("resends an unedited launch instead of handing its text back", async () => {
545
+ await loseLaunchReply(queuedTask());
546
+ await fireRetry();
547
+
548
+ expect(state.draftText).toBe("Keep this draft separate");
549
+ // The resend reuses the launch's command and message ids, so the server replays it.
550
+ const [first, resent] = state.start.mock.calls.map(([call]) => call.input);
551
+ expect(state.start).toHaveBeenCalledTimes(2);
552
+ expect(resent.commandId).toBe(first.commandId);
553
+ expect(resent.message.messageId).toBe(first.message.messageId);
554
+ expect(remaining()).toEqual([]);
555
+ });
556
+
557
+ it("hands back a task edited while its launch was in flight", async () => {
558
+ await loseLaunchReply(queuedTask(), "Edited idea");
559
+ await fireRetry();
560
+
561
+ expect(state.draftText).toBe("Keep this draft separate\nEdited idea");
562
+ expect(state.start).toHaveBeenCalledOnce();
563
+ expect(remaining()).toEqual([]);
564
+ });
565
+
566
+ it("holds the resend while operation access is missing", async () => {
567
+ await loseLaunchReply(queuedTask());
568
+ setOperateGrant("secondary", false);
569
+ vi.advanceTimersByTime(threadOutboxRetryDelayMs(1));
570
+ expect(appAtomRegistry.get(dispatchingQueuedMessageIdAtom)).toBeNull();
571
+ expect(state.start).toHaveBeenCalledOnce();
572
+ expect(remaining()).toHaveLength(1);
573
+
574
+ setOperateGrant("secondary", true);
575
+ await runDrain();
576
+ expect(state.start).toHaveBeenCalledTimes(2);
577
+ expect(state.draftText).toBe("Keep this draft separate");
578
+ expect(remaining()).toEqual([]);
579
+ });
580
+
581
+ it("resends a pull request task in its launched worktree without checking out again", async () => {
582
+ state.checkout.mockResolvedValueOnce(
583
+ AsyncResult.success({
584
+ branch: "pr-123",
585
+ worktreePath: "/repo/.t3/worktrees/pr-123",
586
+ isOnPullRequestHead: true,
587
+ }),
588
+ );
589
+ await loseLaunchReply(
590
+ queuedTask({
591
+ workspaceMode: "worktree",
592
+ branch: "fork/feature",
593
+ pullRequestReference: "https://github.com/acme/repo/pull/123",
594
+ }),
595
+ );
596
+ await fireRetry();
597
+
598
+ expect(state.checkout).toHaveBeenCalledOnce();
599
+ const [first, resent] = state.start.mock.calls.map(([call]) => call.input);
600
+ expect(resent.bootstrap.createThread.worktreePath).toBe("/repo/.t3/worktrees/pr-123");
601
+ expect(resent.bootstrap).toEqual(first.bootstrap);
602
+ expect(remaining()).toEqual([]);
603
+ });
604
+});
605
+
606
describe("compaction before a queued send", () => {
607
const compactTurn = {
608
commandId: "command:compact",
apps/mobile/src/state/threadOutboxDelivery.ts
+23
-4
@@ -694,6 +694,12 @@ export function createThreadOutboxDelivery(): {
694
// Existing-thread turns the server accepted but whose outbox removal has
695
// not landed; the next pass retries only the removal, never the send.
696
const acknowledgedExistingThreadMessageIds = new Set<MessageId>();
697
+ // Revision and workspace each new task's launch carried. Launch replays by command id, so an
698
+ // unedited task whose reply was lost is resent in that workspace, not handed back.
699
+ const launchedCreations = new Map<
700
+ MessageId,
701
+ { readonly revision: number; readonly workspace: QueuedThreadCreation }
702
+ >();
703
// Targets the shell may have left out hold their thread family until they leave the queue, so
704
// the row stays readable through dispatch.
705
const familyMounts = new Map<MessageId, () => void>();
@@ -1064,7 +1070,10 @@ export function createThreadOutboxDelivery(): {
1070
);
1071
if (!hasAccess()) return true;
1072
let workspace = creation;
1067
- if (creation.pullRequestReference) {
1073
+ const launched = launchedCreations.get(persistedMessage.messageId);
1074
+ if (launched?.revision === deliveryRevision) {
1075
+ workspace = launched.workspace;
1076
+ } else if (creation.pullRequestReference) {
1077
const checkout = await runDeliveryCommand(gitEnvironment.preparePullRequestThread, {
1078
environmentId: queuedMessage.environmentId,
1079
input: { cwd: projectCwd, reference: creation.pullRequestReference, mode: "worktree" },
@@ -1094,6 +1103,7 @@ export function createThreadOutboxDelivery(): {
1103
startFromOrigin: false,
1104
};
1105
}
1106
+ launchedCreations.set(persistedMessage.messageId, { revision: deliveryRevision, workspace });
1107
const deliveryResult = await runDeliveryCommand(threadEnvironment.startTurn, {
1108
environmentId: queuedMessage.environmentId,
1109
input: buildProjectThreadStartTurnInput({
@@ -1196,6 +1206,11 @@ export function createThreadOutboxDelivery(): {
1206
acknowledgedExistingThreadMessageIds.delete(messageId);
1207
}
1208
}
1209
+ for (const messageId of launchedCreations.keys()) {
1210
+ if (!queuedMessageIds.has(messageId)) {
1211
+ launchedCreations.delete(messageId);
1212
+ }
1213
+ }
1214
for (const [messageId, release] of familyMounts) {
1215
if (!queuedMessageIds.has(messageId)) {
1216
release();
@@ -1290,9 +1305,13 @@ export function createThreadOutboxDelivery(): {
1305
);
1306
}
1307
}
1308
+ const resendLaunch =
1309
+ creation !== undefined &&
1310
+ launchedCreations.get(messageId)?.revision === threadOutboxRevision(messageId);
1311
const deliveryAction = resolveThreadOutboxDeliveryAction({
1312
isCreation: creation !== undefined,
1295
- threadExists: thread !== undefined,
1313
+ // A resend goes through the same gates as the first launch.
1314
+ threadExists: thread !== undefined && !resendLaunch,
1315
shellStatus,
1316
environmentConnected: environment?.connectionState === "connected",
1317
...(familyRead === undefined ? {} : { familyRead }),
@@ -1387,7 +1406,7 @@ export function createThreadOutboxDelivery(): {
1406
);
1407
const liveDeliveryAction = resolveThreadOutboxDeliveryAction({
1408
isCreation: creation !== undefined,
1390
- threadExists: liveThread !== undefined,
1409
+ threadExists: liveThread !== undefined && !resendLaunch,
1410
shellStatus,
1411
environmentConnected: environment?.connectionState === "connected",
1412
});
@@ -1397,7 +1416,7 @@ export function createThreadOutboxDelivery(): {
1416
}
1417
return deliveryAction === "remove"
1418
? creation !== undefined
1400
- ? // After restart, always recover delivered creations; lost in-memory state cannot distinguish edits from duplicate payloads.
1419
+ ? // Edited since launch, or launched before a restart that lost the revision: hand it back.
1420
recoverEditedCreationAfterDelivery(nextQueuedMessage)
1421
: removeQueuedMessage("[thread-outbox] failed to remove message for a missing thread")
1422
: creation !== undefined