Skip to content

Commit bd05aac

Browse files
vitalyiegorovclaude
andcommitted
fix(server): only client-sent messages inherit a queued pick
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 88f20f5 commit bd05aac

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5464,12 +5464,6 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
54645464
dispatchMode.type === "start_immediately" ||
54655465
dispatchMode.type === "queue_after_active";
54665466
const shouldQueue = queueBehindRun !== undefined && startsOrQueuesRun;
5467-
// A queued pick reaches the thread only when its run starts; unpicked messages behind it follow it.
5468-
const newestQueuedRun =
5469-
shouldQueue && command.modelSelection === undefined && command.createdBy === "user"
5470-
? queuedRunsInDeliveryOrder(projection).at(-1)
5471-
: undefined;
5472-
if (newestQueuedRun) modelSelection = queuedRunModelSelection(projection, newestQueuedRun);
54735467
// Client messages resume held queues; server continuations and scheduled tasks do not.
54745468
// Provider failure or usage limits re-hold the queue. Failed worktree setup keeps it held
54755469
// until a worktree exists, so queued messages cannot start in the project checkout.
@@ -5484,6 +5478,12 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
54845478
command.createdBy === "user" &&
54855479
(command.creationSource === "web" || command.creationSource === "mobile") &&
54865480
command.scheduledTaskId === undefined;
5481+
// A queued pick reaches the thread only when its run starts; unpicked messages behind it follow it.
5482+
const newestQueuedRun =
5483+
shouldQueue && sentByUserFromClient && command.modelSelection === undefined
5484+
? queuedRunsInDeliveryOrder(projection).at(-1)
5485+
: undefined;
5486+
if (newestQueuedRun) modelSelection = queuedRunModelSelection(projection, newestQueuedRun);
54875487
const heldRunsToRelease =
54885488
sentByUserFromClient && startsOrQueuesRun && !worktreeSetupUnresolved
54895489
? projection.runs.filter((run) => run.status === "queued" && run.queueHeld === true)

‎apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,24 @@ describe("orchestration v2 provider switching", () => {
18041804
["queued", CLAUDE_MODEL_SELECTION.instanceId],
18051805
],
18061806
);
1807+
yield* orchestrator.dispatch({
1808+
type: "message.dispatch",
1809+
createdBy: "user",
1810+
creationSource: "server",
1811+
commandId: CommandId.make("command:queued-unpicked-follow-up:server"),
1812+
threadId,
1813+
messageId: MessageId.make("message:queued-unpicked-follow-up:server"),
1814+
text: "Server-created answer",
1815+
attachments: [],
1816+
dispatchMode: { type: "queue_after_active" },
1817+
});
1818+
const withServerMessage = yield* orchestrator.getThreadProjection(threadId);
1819+
assert.equal(
1820+
withServerMessage.runs.find(
1821+
(run) => run.userMessageId === "message:queued-unpicked-follow-up:server",
1822+
)?.modelSelection.instanceId,
1823+
CODEX_MODEL_SELECTION.instanceId,
1824+
);
18071825
yield* orchestrator.dispatch({
18081826
type: "thread.stop",
18091827
commandId: CommandId.make("command:queued-unpicked-follow-up:stop"),

0 commit comments

Comments
 (0)