TypeScript
fix(server): setup actions no longer run for threads in the main checkout (#18891)
Victor Ajibade34b0a9e1bbe6
diff --git a/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts b/apps/server/src/orchestration-v2/ThreadLaunchService.test.tsindex 93f2e3c2f80..35f7d17005d 100644--- a/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts+++ b/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts@@ -383,6 +383,7 @@ it.effect("retains automation and sender attribution while a message waits in thcommand: "command:automation:queue",thread: "thread:automation:queue",message: "First message",+ workspace: { type: "worktree", baseRef: "main" },}),);const scheduledTaskId = ScheduledTaskId.make("scheduled-task:queued");@@ -500,6 +501,7 @@ it.effect("provisions independent launches concurrently instead of behind a globcommand: "command:launch:concurrent-a",thread: "thread:launch:concurrent-a",message: "First",+ workspace: { type: "worktree", baseRef: "main" },}),),launches.launch(@@ -507,6 +509,7 @@ it.effect("provisions independent launches concurrently instead of behind a globcommand: "command:launch:concurrent-b",thread: "thread:launch:concurrent-b",message: "Second",+ workspace: { type: "worktree", baseRef: "main" },}),),],@@ -1124,6 +1127,37 @@ it.effect("runs a Scratch thread launched at the root in its own folder", () =>}),);+it.effect("starts a thread in the main checkout without running the setup action", () =>+ Effect.gen(function* () {+ const harness = makeHarness();+ yield* Effect.gen(function* () {+ const launches = yield* ThreadLaunch.ThreadLaunchService;+ const threads = yield* ThreadManagement.ThreadManagementService;+ const input = launchInput({+ command: "command:launch:main-checkout",+ thread: "thread:launch:main-checkout",+ message: "Work in the main checkout",+ });+ const launched = yield* launches.launch(input);+ assert.isNull(launched.projection.thread.worktreePath);+ const events = yield* threads.streamStoredEventsFrom({ threadId: launched.threadId }).pipe(+ Stream.takeUntil(+ (stored) =>+ stored.commandId === CommandId.make(`${input.commandId}:release`) &&+ stored.event.type === "run.updated",+ ),+ Stream.runCollect,+ );+ assert.isFalse(+ events.some(+ (stored) => stored.commandId === CommandId.make(`${input.commandId}:progress:setup`),+ ),+ );+ assert.equal(harness.runSetup.mock.calls.length, 0);+ }).pipe(Effect.provide(harness.layer));+ }),+);+it.effect("names the worktree itself when the client provides no branch", () =>Effect.gen(function* () {const harness = makeHarness();@@ -1872,6 +1906,7 @@ it.effect("replays a server-allocated launch", () =>command: "command:launch:allocated-retry",thread: "unused",message: "Only once",+ workspace: { type: "worktree", baseRef: "main" },});const first = yield* launches.launch(rest);yield* Deferred.await(setupEntered);@@ -2106,6 +2141,7 @@ it.effect("bounds concurrent first launches to one thread per command", () =>command: "command:launch:concurrent-allocated",thread: "unused",message: "Race me",+ workspace: { type: "worktree", baseRef: "main" },});const results = yield* Effect.all([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", () =>command: "command:launch:retry",thread: "thread:launch:retry",message: "Only once",+ workspace: { type: "worktree", baseRef: "main" },});const [first, retry] = yield* Effect.all([launches.launch(input), launches.launch(input)], {concurrency: "unbounded",@@ -2196,6 +2233,7 @@ it.effect("does not let a failing same-command caller strand a concurrent durablcommand,thread: "thread:launch:failed-owner-race",message: "This invalid reuse fails",+ workspace: { type: "worktree", baseRef: "main" },}),reuseExistingThread: true,})@@ -2205,6 +2243,7 @@ it.effect("does not let a failing same-command caller strand a concurrent durablcommand,thread: "thread:launch:successful-peer",message: "This peer persists",+ workspace: { type: "worktree", baseRef: "main" },}),),],@@ -2240,6 +2279,7 @@ it.effect("schedules an accepted preparing message exactly once across concurrencommand: "command:launch:accepted-before-fork",thread: "thread:launch:accepted-before-fork",message: "Resume preparation",+ workspace: { type: "worktree", baseRef: "main" },});const messageId = MessageId.make("message:launch:accepted-before-fork");diff --git a/apps/server/src/orchestration-v2/ThreadLaunchService.ts b/apps/server/src/orchestration-v2/ThreadLaunchService.tsindex dc98263a650..44c6e56a0fc 100644--- a/apps/server/src/orchestration-v2/ThreadLaunchService.ts+++ b/apps/server/src/orchestration-v2/ThreadLaunchService.ts@@ -562,8 +562,7 @@ const make = Effect.gen(function* () {);}- const cwd = worktreePath ?? project.workspaceRoot;- if (runId !== null) {+ if (runId !== null && worktreePath !== null) {yield* threads.dispatch({type: "prepared-run.progress",@@ -575,27 +574,30 @@ const make = Effect.gen(function* () {.pipe(Effect.mapError(mapError(input, "update-thread", threadId)));}yield* setupTracker.stageStatus(threadId, "setup-script", "running");- const setup = yield* setupScripts- .runForThread({- threadId,- projectId: input.projectId,- projectCwd: project.workspaceRoot,- worktreePath: cwd,- ...(tracked- ? {- observeCompletion: {- onOutputLine: (line: string) =>- setupTracker.appendTail(threadId, "setup-script", line),+ const setup =+ worktreePath === null+ ? ({ status: "no-script" } as const)+ : yield* setupScripts+ .runForThread({+ threadId,+ projectId: input.projectId,+ projectCwd: project.workspaceRoot,+ worktreePath,+ ...(tracked+ ? {+ observeCompletion: {+ onOutputLine: (line: string) =>+ setupTracker.appendTail(threadId, "setup-script", line),+ },+ }+ : {}),+ project: {+ id: project.id,+ workspaceRoot: project.workspaceRoot,+ scripts: project.scripts,},- }- : {}),- project: {- id: project.id,- workspaceRoot: project.workspaceRoot,- scripts: project.scripts,- },- })- .pipe(Effect.mapError(mapError(input, "run-setup-script", threadId)));+ })+ .pipe(Effect.mapError(mapError(input, "run-setup-script", threadId)));let awaitAsyncSetup = Effect.void;if (setup.status === "started") {