Skip to content

Commit 4225c9d

Browse files
Gourav224maria-rcksjuliusmarminge
authored
fix(server): a message sent after a stopped worktree setup waits instead of running in the project checkout (pingdotgg#23618)
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent 84efa01 commit 4225c9d

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7084,13 +7084,12 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
70847084
(candidate) => candidate.id === projection.thread.activeProviderThreadId,
70857085
);
70867086
const activeRun = projection.runs.find(isActiveRun);
7087-
// A message queued during worktree setup can arrive after that setup failed
7088-
// without a worktree. It waits, held, like the messages queued before the
7089-
// failure, instead of starting in the project checkout.
7087+
// Messages after failed or stopped worktree setup must wait for a worktree,
7088+
// rather than start in the project checkout.
70907089
const latestRun = latestExecutedRun(projection.runs);
70917090
const worktreeMissingRun =
70927091
activeRun === undefined &&
7093-
dispatchMode.type === "queue_after_active" &&
7092+
(dispatchMode.type === "queue_after_active" || dispatchMode.type === "start_immediately") &&
70947093
(latestRun?.status === "failed" || latestRun?.status === "interrupted") &&
70957094
latestRun.workspacePreparation?.type === "worktree" &&
70967095
projection.thread.worktreePath === null

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ it.effect.each(["fails", "is interrupted"] as const)(
15401540
);
15411541

15421542
it.effect.each(["failed", "interrupted"] as const)(
1543-
"holds a message queued during setup that arrives after the setup %s",
1543+
"holds every message that arrives after the setup %s without a worktree",
15441544
(ending) => {
15451545
let fetchEntered: Deferred.Deferred<void> | null = null;
15461546
const harness = makeHarness({
@@ -1602,9 +1602,9 @@ it.effect.each(["failed", "interrupted"] as const)(
16021602
assert.equal(held.status, "queued");
16031603
assert.equal(held.queueHeld, true);
16041604

1605-
// A message the user starts does not release it: the held message would
1606-
// run after it in the project checkout.
1607-
yield* threads.sendToThread({
1605+
// A message sent fresh after the setup ended waits behind it too, rather
1606+
// than starting in the project checkout with no worktree.
1607+
const sentAfter = yield* threads.sendToThread({
16081608
projectId,
16091609
commandId: CommandId.make(`command:launch:late-queued-follow-up-${ending}:start`),
16101610
threadId: launched.threadId,
@@ -1615,6 +1615,7 @@ it.effect.each(["failed", "interrupted"] as const)(
16151615
createdBy: "user",
16161616
creationSource: "web",
16171617
});
1618+
assert.equal(sentAfter.delivery, "queued");
16181619
yield* threads.dispatch({
16191620
type: "message.dispatch",
16201621
commandId: CommandId.make(`command:launch:late-queued-follow-up-${ending}:wake`),
@@ -1630,9 +1631,7 @@ it.effect.each(["failed", "interrupted"] as const)(
16301631
assert.equal(wake.status, "queued");
16311632
assert.isTrue(wake.queueHeld);
16321633

1633-
// Nor does the next one, though the run that message started is now the
1634-
// latest and carries no workspace preparation.
1635-
yield* threads.sendToThread({
1634+
const sentAgain = yield* threads.sendToThread({
16361635
projectId,
16371636
commandId: CommandId.make(`command:launch:late-queued-follow-up-${ending}:again`),
16381637
threadId: launched.threadId,
@@ -1643,8 +1642,19 @@ it.effect.each(["failed", "interrupted"] as const)(
16431642
createdBy: "user",
16441643
creationSource: "web",
16451644
});
1645+
assert.equal(sentAgain.delivery, "queued");
16461646
const after = yield* threads.getThreadProjection(launched.threadId);
16471647
assert.isTrue(after.runs.find((run) => run.id === held.id)?.queueHeld);
1648+
assert.deepStrictEqual(
1649+
after.runs.slice(1).map((run) => [run.status, run.queueHeld === true]),
1650+
[
1651+
["queued", true],
1652+
["queued", true],
1653+
["queued", true],
1654+
["queued", true],
1655+
],
1656+
);
1657+
assert.equal(after.thread.worktreePath, null);
16481658
}).pipe(Effect.provide(harness.layer));
16491659
},
16501660
);

0 commit comments

Comments
 (0)