Skip to content

Commit eec3b71

Browse files
Gourav224claude
andcommitted
fix(server): a message sent after a stopped worktree setup waits instead of running in the project checkout
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent ed3f965 commit eec3b71

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5225,13 +5225,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
52255225
(candidate) => candidate.id === projection.thread.activeProviderThreadId,
52265226
);
52275227
const activeRun = projection.runs.find(isBlockingRun);
5228-
// A message queued during worktree setup can arrive after that setup failed
5229-
// without a worktree. It waits, held, like the messages queued before the
5230-
// failure, instead of starting in the project checkout.
5228+
// A message can arrive after worktree setup failed or was stopped without a
5229+
// worktree, whether it was queued during setup or sent fresh afterwards. It
5230+
// waits, held, like the messages queued before the failure, instead of
5231+
// starting in the project checkout.
52315232
const latestRun = latestExecutedRun(projection.runs);
52325233
const worktreeMissingRun =
52335234
activeRun === undefined &&
5234-
dispatchMode.type === "queue_after_active" &&
5235+
(dispatchMode.type === "queue_after_active" || dispatchMode.type === "start_immediately") &&
52355236
(latestRun?.status === "failed" || latestRun?.status === "interrupted") &&
52365237
latestRun.workspacePreparation?.type === "worktree" &&
52375238
projection.thread.worktreePath === null

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ it.effect.each(["fails", "is interrupted"] as const)(
12421242
);
12431243

12441244
it.effect.each(["failed", "interrupted"] as const)(
1245-
"holds a message queued during setup that arrives after the setup %s",
1245+
"holds every message that arrives after the setup %s without a worktree",
12461246
(ending) => {
12471247
let fetchEntered: Deferred.Deferred<void> | null = null;
12481248
const harness = makeHarness({
@@ -1304,9 +1304,9 @@ 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({
1307+
// A message sent fresh after the setup ended waits behind it too, rather
1308+
// than starting in the project checkout with no worktree.
1309+
const sentAfter = yield* threads.sendToThread({
13101310
projectId,
13111311
commandId: CommandId.make(`command:launch:late-queued-follow-up-${ending}:start`),
13121312
threadId: launched.threadId,
@@ -1317,9 +1317,8 @@ it.effect.each(["failed", "interrupted"] as const)(
13171317
createdBy: "user",
13181318
creationSource: "web",
13191319
});
1320-
// Nor does the next one, though the run that message started is now the
1321-
// latest and carries no workspace preparation.
1322-
yield* threads.sendToThread({
1320+
assert.equal(sentAfter.delivery, "queued");
1321+
const sentAgain = yield* threads.sendToThread({
13231322
projectId,
13241323
commandId: CommandId.make(`command:launch:late-queued-follow-up-${ending}:again`),
13251324
threadId: launched.threadId,
@@ -1330,8 +1329,18 @@ it.effect.each(["failed", "interrupted"] as const)(
13301329
createdBy: "user",
13311330
creationSource: "web",
13321331
});
1332+
assert.equal(sentAgain.delivery, "queued");
13331333
const after = yield* threads.getThreadProjection(launched.threadId);
13341334
assert.isTrue(after.runs.find((run) => run.id === held.id)?.queueHeld);
1335+
assert.deepStrictEqual(
1336+
after.runs.slice(1).map((run) => [run.status, run.queueHeld === true]),
1337+
[
1338+
["queued", true],
1339+
["queued", true],
1340+
["queued", true],
1341+
],
1342+
);
1343+
assert.equal(after.thread.worktreePath, null);
13351344
}).pipe(Effect.provide(harness.layer));
13361345
},
13371346
);

0 commit comments

Comments
 (0)