Skip to content

Commit 4410854

Browse files
committed
fix(server): let worktree cleanup finish
1 parent fff33f9 commit 4410854

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,51 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
14891489
}),
14901490
);
14911491

1492+
it.effect("allows worktree removal to run longer than the default command timeout", () =>
1493+
Effect.gen(function* () {
1494+
const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
1495+
const removalStarted = yield* Deferred.make<void>();
1496+
const delayedRemovalSpawner = ChildProcessSpawner.make((command) =>
1497+
Effect.gen(function* () {
1498+
if (
1499+
ChildProcess.isStandardCommand(command) &&
1500+
command.args[0] === "worktree" &&
1501+
command.args[1] === "remove"
1502+
) {
1503+
yield* Deferred.succeed(removalStarted, undefined);
1504+
yield* Effect.sleep("31 seconds");
1505+
}
1506+
return yield* delegate.spawn(command);
1507+
}),
1508+
);
1509+
const driver = yield* makeGitVcsDriverCore().pipe(
1510+
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, delayedRemovalSpawner),
1511+
Effect.provide(ServerConfigLayer),
1512+
);
1513+
const cwd = yield* makeTmpDir();
1514+
const { initialBranch } = yield* initRepoWithCommit(cwd);
1515+
const fileSystem = yield* FileSystem.FileSystem;
1516+
const pathService = yield* Path.Path;
1517+
const worktreePath = pathService.join(yield* makeTmpDir("git-worktrees-"), "slow-removal");
1518+
1519+
yield* driver.createWorktree({
1520+
cwd,
1521+
path: worktreePath,
1522+
refName: initialBranch,
1523+
newRefName: "feature/slow-removal",
1524+
});
1525+
1526+
const removal = yield* driver
1527+
.removeWorktree({ cwd, path: worktreePath, force: true })
1528+
.pipe(Effect.forkChild({ startImmediately: true }));
1529+
yield* Deferred.await(removalStarted);
1530+
yield* TestClock.adjust("31 seconds");
1531+
yield* Fiber.join(removal);
1532+
1533+
assert.equal(yield* fileSystem.exists(worktreePath), false);
1534+
}),
1535+
);
1536+
14921537
it.effect("removes the same worktree path twice without failing", () =>
14931538
Effect.gen(function* () {
14941539
const cwd = yield* makeTmpDir();

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const DEFAULT_TIMEOUT_MS = 30_000;
4343
// take well beyond the default 30s (e.g. a 375k-file repo takes ~40s on an idle
4444
// machine). Give it generous headroom while still bounding a genuinely hung git.
4545
const WORKTREE_ADD_TIMEOUT_MS = 300_000;
46+
const WORKTREE_REMOVE_TIMEOUT_MS = Duration.toMillis(Duration.minutes(5));
4647
const DEFAULT_MAX_OUTPUT_BYTES = 1_000_000;
4748
const OUTPUT_TRUNCATED_MARKER = "\n\n[truncated]";
4849
const PREPARED_COMMIT_PATCH_MAX_OUTPUT_BYTES = 49_000;
@@ -3078,7 +3079,13 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
30783079
"GitVcsDriver.removeWorktree",
30793080
input.cwd,
30803081
args,
3081-
{ timeoutMs: 15_000, allowNonZeroExit: true },
3082+
{
3083+
// Removing dependency-heavy worktrees is filesystem-bound and can take
3084+
// minutes, especially on Windows. Keep it bounded without interrupting
3085+
// git midway through cleanup.
3086+
timeoutMs: WORKTREE_REMOVE_TIMEOUT_MS,
3087+
allowNonZeroExit: true,
3088+
},
30823089
);
30833090
if (result.exitCode === 0) {
30843091
return;

0 commit comments

Comments
 (0)