The best way to control Claude Code, Codex and more from any computer or phone
fix(server): setup actions no longer run for threads in the main checkout (#18891)
Victor Ajibade committed
Oct 18, 2026 at 20:52 UTC
34b0a9e1bbe63efe78546455811e9c26805ecb31
2 files changed
+64
-22
apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
+40
@@ -383,6 +383,7 @@ it.effect("retains automation and sender attribution while a message waits in th
383
command: "command:automation:queue",
384
thread: "thread:automation:queue",
385
message: "First message",
386
+ workspace: { type: "worktree", baseRef: "main" },
387
}),
388
);
389
const scheduledTaskId = ScheduledTaskId.make("scheduled-task:queued");
@@ -500,6 +501,7 @@ it.effect("provisions independent launches concurrently instead of behind a glob
501
command: "command:launch:concurrent-a",
502
thread: "thread:launch:concurrent-a",
503
message: "First",
504
+ workspace: { type: "worktree", baseRef: "main" },
505
}),
506
),
507
launches.launch(
@@ -507,6 +509,7 @@ it.effect("provisions independent launches concurrently instead of behind a glob
509
command: "command:launch:concurrent-b",
510
thread: "thread:launch:concurrent-b",
511
message: "Second",
512
+ workspace: { type: "worktree", baseRef: "main" },
513
}),
514
),
515
],
@@ -1124,6 +1127,37 @@ it.effect("runs a Scratch thread launched at the root in its own folder", () =>
1127
}),
1128
);
1129
1130
+it.effect("starts a thread in the main checkout without running the setup action", () =>
1131
+ Effect.gen(function* () {
1132
+ const harness = makeHarness();
1133
+ yield* Effect.gen(function* () {
1134
+ const launches = yield* ThreadLaunch.ThreadLaunchService;
1135
+ const threads = yield* ThreadManagement.ThreadManagementService;
1136
+ const input = launchInput({
1137
+ command: "command:launch:main-checkout",
1138
+ thread: "thread:launch:main-checkout",
1139
+ message: "Work in the main checkout",
1140
+ });
1141
+ const launched = yield* launches.launch(input);
1142
+ assert.isNull(launched.projection.thread.worktreePath);
1143
+ const events = yield* threads.streamStoredEventsFrom({ threadId: launched.threadId }).pipe(
1144
+ Stream.takeUntil(
1145
+ (stored) =>
1146
+ stored.commandId === CommandId.make(`${input.commandId}:release`) &&
1147
+ stored.event.type === "run.updated",
1148
+ ),
1149
+ Stream.runCollect,
1150
+ );
1151
+ assert.isFalse(
1152
+ events.some(
1153
+ (stored) => stored.commandId === CommandId.make(`${input.commandId}:progress:setup`),
1154
+ ),
1155
+ );
1156
+ assert.equal(harness.runSetup.mock.calls.length, 0);
1157
+ }).pipe(Effect.provide(harness.layer));
1158
+ }),
1159
+);
1160
+
1161
it.effect("names the worktree itself when the client provides no branch", () =>
1162
Effect.gen(function* () {
1163
const harness = makeHarness();
@@ -1872,6 +1906,7 @@ it.effect("replays a server-allocated launch", () =>
1906
command: "command:launch:allocated-retry",
1907
thread: "unused",
1908
message: "Only once",
1909
+ workspace: { type: "worktree", baseRef: "main" },
1910
});
1911
const first = yield* launches.launch(rest);
1912
yield* Deferred.await(setupEntered);
@@ -2106,6 +2141,7 @@ it.effect("bounds concurrent first launches to one thread per command", () =>
2141
command: "command:launch:concurrent-allocated",
2142
thread: "unused",
2143
message: "Race me",
2144
+ workspace: { type: "worktree", baseRef: "main" },
2145
});
2146
const results = yield* Effect.all(
2147
[launches.launch(rest).pipe(Effect.exit), launches.launch(rest).pipe(Effect.exit)],
@@ -2160,6 +2196,7 @@ it.effect("deduplicates retried launch side effects in-process", () =>
2196
command: "command:launch:retry",
2197
thread: "thread:launch:retry",
2198
message: "Only once",
2199
+ workspace: { type: "worktree", baseRef: "main" },
2200
});
2201
const [first, retry] = yield* Effect.all([launches.launch(input), launches.launch(input)], {
2202
concurrency: "unbounded",
@@ -2196,6 +2233,7 @@ it.effect("does not let a failing same-command caller strand a concurrent durabl
2233
command,
2234
thread: "thread:launch:failed-owner-race",
2235
message: "This invalid reuse fails",
2236
+ workspace: { type: "worktree", baseRef: "main" },
2237
}),
2238
reuseExistingThread: true,
2239
})
@@ -2205,6 +2243,7 @@ it.effect("does not let a failing same-command caller strand a concurrent durabl
2243
command,
2244
thread: "thread:launch:successful-peer",
2245
message: "This peer persists",
2246
+ workspace: { type: "worktree", baseRef: "main" },
2247
}),
2248
),
2249
],
@@ -2240,6 +2279,7 @@ it.effect("schedules an accepted preparing message exactly once across concurren
2279
command: "command:launch:accepted-before-fork",
2280
thread: "thread:launch:accepted-before-fork",
2281
message: "Resume preparation",
2282
+ workspace: { type: "worktree", baseRef: "main" },
2283
});
2284
const messageId = MessageId.make("message:launch:accepted-before-fork");
2285
apps/server/src/orchestration-v2/ThreadLaunchService.ts
+24
-22
@@ -562,8 +562,7 @@ const make = Effect.gen(function* () {
562
);
563
}
564
565
- const cwd = worktreePath ?? project.workspaceRoot;
566
- if (runId !== null) {
565
+ if (runId !== null && worktreePath !== null) {
566
yield* threads
567
.dispatch({
568
type: "prepared-run.progress",
@@ -575,27 +574,30 @@ const make = Effect.gen(function* () {
574
.pipe(Effect.mapError(mapError(input, "update-thread", threadId)));
575
}
576
yield* setupTracker.stageStatus(threadId, "setup-script", "running");
578
- const setup = yield* setupScripts
579
- .runForThread({
580
- threadId,
581
- projectId: input.projectId,
582
- projectCwd: project.workspaceRoot,
583
- worktreePath: cwd,
584
- ...(tracked
585
- ? {
586
- observeCompletion: {
587
- onOutputLine: (line: string) =>
588
- setupTracker.appendTail(threadId, "setup-script", line),
577
+ const setup =
578
+ worktreePath === null
579
+ ? ({ status: "no-script" } as const)
580
+ : yield* setupScripts
581
+ .runForThread({
582
+ threadId,
583
+ projectId: input.projectId,
584
+ projectCwd: project.workspaceRoot,
585
+ worktreePath,
586
+ ...(tracked
587
+ ? {
588
+ observeCompletion: {
589
+ onOutputLine: (line: string) =>
590
+ setupTracker.appendTail(threadId, "setup-script", line),
591
+ },
592
+ }
593
+ : {}),
594
+ project: {
595
+ id: project.id,
596
+ workspaceRoot: project.workspaceRoot,
597
+ scripts: project.scripts,
598
},
590
- }
591
- : {}),
592
- project: {
593
- id: project.id,
594
- workspaceRoot: project.workspaceRoot,
595
- scripts: project.scripts,
596
- },
597
- })
598
- .pipe(Effect.mapError(mapError(input, "run-setup-script", threadId)));
599
+ })
600
+ .pipe(Effect.mapError(mapError(input, "run-setup-script", threadId)));
601
602
let awaitAsyncSetup = Effect.void;
603
if (setup.status === "started") {