Skip to content

Commit c740ee5

Browse files
committed
fix(server): preserve worktree holds and queued resume providers
1 parent 39c49ba commit c740ee5

3 files changed

Lines changed: 32 additions & 14 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5598,6 +5598,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
55985598
// Buffered wakes need a T3 run for output the CLI already started producing.
55995599
// Stop still holds wakes that arrive before the active run settles.
56005600
const wakeSkipsHold =
5601+
!worktreeSetupUnresolved &&
56015602
activeRun !== undefined &&
56025603
queueIsHeld &&
56035604
command.createdBy === "agent" &&
@@ -12009,7 +12010,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1200912010
});
1201012011
}
1201112012
}
12012-
const nextRun = selectedRun ?? nextQueuedRun(projection);
12013+
const nextRun = selectedRun ?? queuedRunsInDeliveryOrder(projection)[0];
1201312014
if (
1201412015
usageLimitHoldsQueue(
1201512016
projection,

‎apps/server/src/orchestration-v2/ThreadLaunchService.test.ts‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,19 @@ it.effect.each(["failed", "interrupted"] as const)(
13041304
assert.equal(held.status, "queued");
13051305
assert.equal(held.queueHeld, true);
13061306

1307+
// A message the user starts does not release it: the held message would
1308+
// run after it in the project checkout.
1309+
yield* threads.sendToThread({
1310+
projectId,
1311+
commandId: CommandId.make(`command:launch:late-queued-follow-up-${ending}:start`),
1312+
threadId: launched.threadId,
1313+
messageId: MessageId.make(`message:launch:late-queued-follow-up-${ending}:start`),
1314+
text: "Sent after setup",
1315+
attachments: [],
1316+
mode: "auto",
1317+
createdBy: "user",
1318+
creationSource: "web",
1319+
});
13071320
yield* threads.dispatch({
13081321
type: "message.dispatch",
13091322
commandId: CommandId.make(`command:launch:late-queued-follow-up-${ending}:wake`),
@@ -1319,19 +1332,6 @@ it.effect.each(["failed", "interrupted"] as const)(
13191332
assert.equal(wake.status, "queued");
13201333
assert.isTrue(wake.queueHeld);
13211334

1322-
// A message the user starts does not release it: the held message would
1323-
// run after it in the project checkout.
1324-
yield* threads.sendToThread({
1325-
projectId,
1326-
commandId: CommandId.make(`command:launch:late-queued-follow-up-${ending}:start`),
1327-
threadId: launched.threadId,
1328-
messageId: MessageId.make(`message:launch:late-queued-follow-up-${ending}:start`),
1329-
text: "Sent after setup",
1330-
attachments: [],
1331-
mode: "auto",
1332-
createdBy: "user",
1333-
creationSource: "web",
1334-
});
13351335
// Nor does the next one, though the run that message started is now the
13361336
// latest and carries no workspace preparation.
13371337
yield* threads.sendToThread({

‎apps/server/src/orchestration-v2/runtimeLayer.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4681,6 +4681,23 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
46814681
threadId,
46824682
runId: limited.id,
46834683
});
4684+
yield* eventSink.write({
4685+
events: [
4686+
{
4687+
id: EventId.make(`${threadId}:hold-available`),
4688+
type: "run.updated",
4689+
threadId,
4690+
runId: available.id,
4691+
occurredAt: now,
4692+
payload: { ...available, queueHeld: true },
4693+
},
4694+
],
4695+
});
4696+
yield* orchestrator.dispatch({
4697+
type: "queue.resume",
4698+
commandId: CommandId.make(`${threadId}:resume-available`),
4699+
threadId,
4700+
});
46844701
yield* orchestrator.resumeQueuedRuns;
46854702
const after = yield* orchestrator.getThreadProjection(threadId);
46864703
const started = after.runs.find((run) => run.id === available.id);

0 commit comments

Comments
 (0)