Skip to content

Commit fd4439f

Browse files
refactor(server): keep only the preparation rewrite for the empty-repo fallback
Recording the run's preparation as root at release is what stops queue promotion from treating the project-folder fallback as failed worktree setup. Drop the extra status guard in queue promotion, which also changed holding for unrelated completed runs, along with its runtime test. Trim the launch tests to one case per behavior. AI-assisted; verified with the tests and tools listed above. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5bb3601 commit fd4439f

3 files changed

Lines changed: 27 additions & 87 deletions

File tree

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,16 +1930,13 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
19301930
return;
19311931
}
19321932
// Failed worktree creation would run queued work in the project checkout; wait for the user.
1933-
// A successful empty-repo fallback rewrites preparation to root before release, so it
1934-
// must not match here: only failed or interrupted worktree prep keeps the queue held.
19351933
const failedRun = latestExecutedRun(projection.runs);
19361934
const failureClass =
19371935
failedRun?.id === options?.failedRunId
19381936
? latestRootProviderFailure(failedRun, projection.turnItems)?.class
19391937
: undefined;
19401938
const worktreeMissing =
19411939
failedRun?.id === options?.endedRunId &&
1942-
(failedRun?.status === "failed" || failedRun?.status === "interrupted") &&
19431940
failedRun?.workspacePreparation?.type === "worktree" &&
19441941
projection.thread.worktreePath === null;
19451942
const settings = yield* serverSettings.getSettings.pipe(Effect.orDie);
@@ -10625,14 +10622,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1062510622
updatedAt: now,
1062610623
},
1062710624
});
10628-
// Empty-repo worktree launches fall back to the project folder and leave
10629-
// worktreePath null; rewrite preparation so queue promotion does not treat
10630-
// the successful run as a failed worktree setup.
10631-
const resolvedPreparation =
10625+
// An empty repository has no commit for a worktree, so launch ran in the project
10626+
// folder. Record that, or queue promotion reads it as failed worktree setup.
10627+
const ranInProjectFolder =
1063210628
state.run.workspacePreparation?.type === "worktree" &&
10633-
projection.thread.worktreePath === null
10634-
? ({ type: "root" } as const)
10635-
: state.run.workspacePreparation;
10629+
projection.thread.worktreePath === null;
1063610630
yield* emitEvent({
1063710631
type: "run.updated",
1063810632
threadId: command.threadId,
@@ -10643,9 +10637,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
1064310637
payload: {
1064410638
...state.run,
1064510639
status: "starting",
10646-
...(resolvedPreparation === undefined
10647-
? {}
10648-
: { workspacePreparation: resolvedPreparation }),
10640+
...(ranInProjectFolder ? { workspacePreparation: { type: "root" as const } } : {}),
1064910641
},
1065010642
});
1065110643
yield* Ref.update(effects, (existing) => [

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

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,24 +1178,14 @@ it.effect("fetches the origin base from the remote it already resolved", () => {
11781178
}).pipe(Effect.provide(harness.layer));
11791179
});
11801180

1181-
// Issue 22017: `git worktree add` has no commit to start from when the
1182-
// repository (and any requested origin base) is still empty.
11831181
it.effect.each([
1184-
{
1185-
name: "without a resolvable origin base",
1186-
startFromOrigin: false,
1187-
fetchBase: null as { commitSha: string; remoteRefName: string } | null,
1188-
},
1189-
{
1190-
name: "whose origin has no base branch",
1191-
startFromOrigin: true,
1192-
fetchBase: null as { commitSha: string; remoteRefName: string } | null,
1193-
},
1182+
{ name: "without an origin base", startFromOrigin: false },
1183+
{ name: "whose origin has no base branch", startFromOrigin: true },
11941184
])("runs in the project folder for a repository with no commits $name", (testCase) => {
11951185
const suffix = testCase.startFromOrigin ? "empty-origin" : "empty-local";
11961186
const harness = makeHarness({
11971187
hasCommit: () => Effect.succeed(false),
1198-
fetchWorktreeBaseCommit: () => Effect.succeed(testCase.fetchBase),
1188+
fetchWorktreeBaseCommit: () => Effect.succeed(null),
11991189
});
12001190
return Effect.gen(function* () {
12011191
const launches = yield* ThreadLaunch.ThreadLaunchService;
@@ -1226,37 +1216,25 @@ it.effect.each([
12261216
}).pipe(Effect.provide(harness.layer));
12271217
});
12281218

1229-
it.effect.each([
1230-
{ baseRef: "main", startRef: "remote-main-sha" },
1231-
{ baseRef: "origin/main", startRef: "remote-main-sha" },
1232-
])(
1233-
"checks out $baseRef fetched from origin when the local repository has no commits",
1234-
(testCase) => {
1235-
const suffix = testCase.baseRef.replaceAll("/", "-");
1236-
const harness = makeHarness({
1237-
hasCommit: ({ refName }) => Effect.succeed(refName === testCase.startRef),
1238-
});
1239-
return Effect.gen(function* () {
1240-
const launches = yield* ThreadLaunch.ThreadLaunchService;
1241-
const launched = yield* launches.launch(
1242-
launchInput({
1243-
command: `command:launch:empty-repo-origin:${suffix}`,
1244-
thread: `thread:launch:empty-repo-origin:${suffix}`,
1245-
message: "Reply with OK only",
1246-
workspace: {
1247-
type: "worktree",
1248-
baseRef: testCase.baseRef,
1249-
startFromOrigin: true,
1250-
},
1251-
}),
1252-
);
1253-
const projection = yield* preparationSettled(launched.threadId);
1254-
assert.equal(projection.runs[0]?.status, "starting");
1255-
assert.equal(projection.thread.worktreePath, "/repo-worktrees/feature");
1256-
assert.equal(harness.createWorktree.mock.calls[0]?.[0]?.refName, testCase.startRef);
1257-
}).pipe(Effect.provide(harness.layer));
1258-
},
1259-
);
1219+
it.effect("checks out the origin base when the local repository has no commits", () => {
1220+
const harness = makeHarness({
1221+
hasCommit: ({ refName }) => Effect.succeed(refName === "remote-main-sha"),
1222+
});
1223+
return Effect.gen(function* () {
1224+
const launches = yield* ThreadLaunch.ThreadLaunchService;
1225+
const launched = yield* launches.launch(
1226+
launchInput({
1227+
command: "command:launch:empty-repo-origin",
1228+
thread: "thread:launch:empty-repo-origin",
1229+
message: "Reply with OK only",
1230+
workspace: { type: "worktree", baseRef: "main", startFromOrigin: true },
1231+
}),
1232+
);
1233+
const projection = yield* preparationSettled(launched.threadId);
1234+
assert.equal(projection.thread.worktreePath, "/repo-worktrees/feature");
1235+
assert.equal(harness.createWorktree.mock.calls[0]?.[0]?.refName, "remote-main-sha");
1236+
}).pipe(Effect.provide(harness.layer));
1237+
});
12601238

12611239
it.effect("shows the fetch diagnosis when preparing a worktree from origin fails", () => {
12621240
const detail =

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5787,36 +5787,6 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
57875787
}),
57885788
);
57895789

5790-
// A successful empty-repo fallback leaves worktreePath null with a completed run; that must
5791-
// not hold the queue the way a failed worktree setup does.
5792-
it.effect("starts the next queued run after a completed worktree prep without a worktree", () =>
5793-
Effect.gen(function* () {
5794-
const orchestrator = yield* Orchestrator.OrchestratorV2;
5795-
const eventSink = yield* EventSink.EventSinkV2;
5796-
const threadId = ThreadId.make("runtime-layer-empty-repo-worktree-fallback");
5797-
const { send, runFor, end, startedRunIds } = yield* queueTestThread(threadId);
5798-
yield* send("setup", "agent", true);
5799-
yield* send("queued", "agent", false);
5800-
const { thread } = yield* orchestrator.getThreadProjection(threadId);
5801-
yield* eventSink.write({
5802-
events: [
5803-
{
5804-
id: EventId.make(`${threadId}:worktree-fallback`),
5805-
type: "thread.metadata-updated",
5806-
threadId,
5807-
occurredAt: yield* DateTime.now,
5808-
payload: { ...thread, worktreePath: null },
5809-
},
5810-
],
5811-
});
5812-
yield* end("setup", "completed", "", {
5813-
workspacePreparation: { type: "worktree", baseRef: "main" },
5814-
});
5815-
assert.equal(yield* Queue.take(startedRunIds), (yield* runFor("queued")).id);
5816-
assert.notEqual((yield* runFor("queued")).queueHeld, true);
5817-
}),
5818-
);
5819-
58205790
it.effect("keeps queued user selections and pauses only the limited provider", () =>
58215791
Effect.gen(function* () {
58225792
const orchestrator = yield* Orchestrator.OrchestratorV2;

0 commit comments

Comments
 (0)