Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import { OrchestrationEngineService } from "../Services/OrchestrationEngine.ts";
import { ProviderCommandReactor } from "../Services/ProviderCommandReactor.ts";
import { ProjectionSnapshotQuery } from "../Services/ProjectionSnapshotQuery.ts";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { withWorkspaceLease } from "../../workspace/workspaceLease.ts";
import * as Clock from "effect/Clock";
import { ServerSettingsService } from "../../serverSettings.ts";
import { ServerActivation } from "../../serverActivation.ts";
Expand Down Expand Up @@ -432,7 +433,13 @@ describe("ProviderCommandReactor", () => {
},
}),
);
const runSetupScript = vi.fn(() => Effect.succeed({ status: "no-script" as const }));
// The real runner opens a terminal, which takes the worktree's workspace lease.
const runSetupScript = vi.fn((input: { readonly worktreePath: string }) =>
withWorkspaceLease(
NodePath.resolve(input.worktreePath),
Effect.succeed({ status: "no-script" as const }),
),
);
const pruneWorktrees = vi.fn((_: { readonly cwd: string }) => Effect.void);
const refreshStatus = vi.fn((_: string) =>
Effect.succeed({
Expand Down
28 changes: 22 additions & 6 deletions apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,12 +668,28 @@ const make = Effect.gen(function* () {
cwd: managedWorktree.projectCwd,
...recoveryPlan,
});
yield* projectSetupScriptRunner.runForThread({
threadId: input.thread.id,
projectId: input.thread.projectId,
projectCwd: managedWorktree.projectCwd,
worktreePath: managedWorktree.path,
});
// Opening the setup terminal takes this worktree's workspace lease, which
// the turn start already holds. Fork so it queues behind the turn start
// instead of deadlocking on it.
yield* projectSetupScriptRunner
.runForThread({
threadId: input.thread.id,
projectId: input.thread.projectId,
projectCwd: managedWorktree.projectCwd,
worktreePath: managedWorktree.path,
})
.pipe(
Effect.catchCause((cause) =>
Cause.hasInterruptsOnly(cause)
? Effect.void
: Effect.logWarning("failed to run setup script for recreated worktree", {
threadId: input.thread.id,
worktreePath: managedWorktree.path,
cause: Cause.pretty(cause),
}),
),
Effect.forkScoped,
);
yield* Effect.logInfo("recreated missing managed thread worktree", {
threadId: input.thread.id,
branch: input.thread.branch,
Expand Down
Loading