The best way to control Claude Code, Codex and more from any computer or phone
fix(queued-message): avoid duplicate queued message entries (#26355)
Yash Singh committed
Oct 28, 2026 at 03:20 UTC
10e709c33786682217ad3c4f9226ba6c13e5edd7
5 files changed
+124
apps/mobile/src/lib/threadActivity.ts
+6
@@ -2191,6 +2191,12 @@ export function buildThreadFeed(
2191
const item = row.item;
2192
if (turnItemIsWorkspacePreparation(item)) continue;
2193
if (item.type === "todo_list" || item.type === "checkpoint") continue;
2194
+ if (
2195
+ item.type === "user_message" &&
2196
+ item.inputIntent === "queued_turn" &&
2197
+ item.status === "pending"
2198
+ )
2199
+ continue;
2200
if (item.type === "user_message" && foldedAnswerMessageIds.has(item.messageId)) continue;
2201
if (
2202
item.type === "run_interrupt_request" ||
apps/server/src/orchestration-v2/Orchestrator.ts
+4
@@ -1920,6 +1920,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1920
}),
1921
providerThreadId: queuedProviderThread.id,
1922
inputIntent: "queued_turn",
1923
+ status: "completed",
1924
startedAt: now,
1925
completedAt: now,
1926
updatedAt: now,
@@ -5749,6 +5750,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
5750
providerThreadId: queuedProviderThread.id,
5751
providerTurnId: null,
5752
inputIntent: "queued_turn",
5753
+ status: "pending",
5754
+ startedAt: null,
5755
+ completedAt: null,
5756
updatedAt: now,
5757
},
5758
});
apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts
+87
@@ -339,6 +339,13 @@ it.effect.each(
339
if (delivery !== null) {
340
yield* Deferred.succeed(rejectSteer, undefined);
341
yield* Fiber.join(delivery);
342
+ const requeued = yield* orchestrator.getThreadProjection(threadId);
343
+ const item = requeued.turnItems.find(
344
+ (item) => item.type === "user_message" && item.messageId === messageId,
345
+ );
346
+ assert.equal(item?.status, "pending");
347
+ assert.isNull(item?.startedAt);
348
+ assert.isNull(item?.completedAt);
349
}
350
if (timing === "before dispatch") yield* dispatchSteer;
351
yield* worker.drain();
@@ -391,6 +398,14 @@ it.effect.each(
398
]);
399
assert.equal(steerCalls, timing === "during delivery" ? 1 : 0);
400
const final = yield* orchestrator.getThreadProjection(threadId);
401
+ if (!mailbox) {
402
+ assert.equal(
403
+ final.turnItems.find(
404
+ (item) => item.type === "user_message" && item.messageId === messageId,
405
+ )?.status,
406
+ "completed",
407
+ );
408
+ }
409
assert.equal(final.messages.filter((message) => message.id === messageId).length, 1);
410
assert.equal(
411
final.messages.find((message) => message.id === messageId)?.runId,
@@ -669,6 +684,78 @@ it.effect("sends a selected held message once and preserves the remaining queue
684
),
685
);
686
687
+it.effect("force sends multiple queued messages and can force send a requeued message again", () =>
688
+ Effect.scoped(
689
+ Effect.gen(function* () {
690
+ const { started, steered, layer, startFirstTurn } = yield* nextTurnSelectionHarness(
691
+ "multiple-promoted-messages",
692
+ );
693
+ yield* Effect.gen(function* () {
694
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
695
+ const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
696
+ const threadId = yield* startFirstTurn;
697
+ const queue = (text: string, commandId: string) =>
698
+ orchestrator.dispatch({
699
+ type: "message.dispatch",
700
+ commandId: CommandId.make(commandId),
701
+ threadId,
702
+ messageId: MessageId.make(`message:${text}`),
703
+ text,
704
+ attachments: [],
705
+ dispatchMode: { type: "queue_after_active" },
706
+ createdBy: "user",
707
+ creationSource: "web",
708
+ });
709
+ for (const text of ["one", "two", "remaining"]) yield* queue(text, `queue-${text}`);
710
+ const promote = Effect.fn("test.promote")(function* (text: string, commandId: string) {
711
+ const projection = yield* orchestrator.getThreadProjection(threadId);
712
+ const queued = projection.runs.find(
713
+ (run) =>
714
+ run.status === "queued" && run.userMessageId === MessageId.make(`message:${text}`),
715
+ )!;
716
+ yield* orchestrator.dispatch({
717
+ type: "queued-message.promote-to-steer",
718
+ commandId: CommandId.make(commandId),
719
+ threadId,
720
+ queuedRunId: queued.id,
721
+ targetRunId: started[0]!.runId,
722
+ });
723
+ });
724
+ yield* promote("one", "promote-one");
725
+ yield* promote("two", "promote-two");
726
+ yield* worker.drain();
727
+ assert.deepEqual(steered, ["one", "two"]);
728
+
729
+ // The completion-race fallback redispatches the same message into the queue.
730
+ yield* queue("one", "requeue-one");
731
+ const requeued = yield* orchestrator.getThreadProjection(threadId);
732
+ assert.equal(
733
+ requeued.turnItems.find(
734
+ (item) => item.type === "user_message" && item.messageId === "message:one",
735
+ )?.status,
736
+ "pending",
737
+ );
738
+ yield* promote("one", "promote-one-again");
739
+ yield* worker.drain();
740
+ assert.deepEqual(steered, ["one", "two", "one"]);
741
+ assert.lengthOf(started, 1);
742
+ const final = yield* orchestrator.getThreadProjection(threadId);
743
+ assert.deepEqual(
744
+ final.runs.filter((run) => run.status === "queued").map((run) => run.userMessageId),
745
+ [MessageId.make("message:remaining")],
746
+ );
747
+ for (const text of ["one", "two"]) {
748
+ const items = final.turnItems.filter(
749
+ (item) => item.type === "user_message" && item.messageId === `message:${text}`,
750
+ );
751
+ assert.lengthOf(items, 1);
752
+ assert.equal(items[0]?.status, "completed");
753
+ }
754
+ }).pipe(Effect.provide(layer));
755
+ }),
756
+ ),
757
+);
758
+
759
it.effect("keeps a message queued when send now races with a running turn", () =>
760
Effect.scoped(
761
Effect.gen(function* () {
apps/web/src/session-logic.test.ts
+21
@@ -672,6 +672,27 @@ describe("V2 session presentation", () => {
672
scheduledTaskId: ScheduledTaskId.make("task-queued"),
673
senderThreadId: ThreadId.make("thread-agent-sender"),
674
} satisfies OrchestrationV2TurnItem;
675
+ for (const inputIntent of [
676
+ "queued_turn",
677
+ "turn_start",
678
+ "steer",
679
+ "promoted_queued_to_steer",
680
+ ] as const) {
681
+ expect(
682
+ deriveTimelineEntriesFromVisibleTurnItems({
683
+ visibleTurnItems: [
684
+ {
685
+ position: 0,
686
+ visibility: "local",
687
+ sourceThreadId: projection.thread.id,
688
+ sourceItemId: dispatchedItem.id,
689
+ item: { ...dispatchedItem, inputIntent, status: "pending" },
690
+ },
691
+ ],
692
+ optimisticMessages: [],
693
+ }),
694
+ ).toHaveLength(inputIntent === "queued_turn" ? 0 : 1);
695
+ }
696
const promotedEntries = deriveTimelineEntriesFromVisibleTurnItems({
697
visibleTurnItems: [
698
{
apps/web/src/session-logic.ts
+6
@@ -603,6 +603,12 @@ export function deriveTimelineEntriesFromVisibleTurnItems(
603
const { item } = row;
604
if (turnItemIsWorkspacePreparation(item)) continue;
605
if (item.type === "checkpoint") continue;
606
+ if (
607
+ item.type === "user_message" &&
608
+ item.inputIntent === "queued_turn" &&
609
+ item.status === "pending"
610
+ )
611
+ continue;
612
if (item.type === "user_message" && foldedAnswerMessageIds.has(item.messageId)) continue;
613
const createdAt = projectedItemCreatedAt(row);
614
const attempt = resolveAttempt(item);