Skip to content

Commit 433d154

Browse files
fix(server): storage cleanup still matches missing project roots by their stored spelling
Comparing only the worktree's real path dropped the alias-to-alias match for a project root that no longer exists, since its realPath falls back to the stored alias spelling. Check both of the worktree's spellings. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5e7e83d commit 433d154

2 files changed

Lines changed: 29 additions & 12 deletions

File tree

‎apps/server/src/storageCleanup.test.ts‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,18 +1313,30 @@ describe("storage cleanup reports and local file policies", () => {
13131313
}),
13141314
),
13151315
);
1316-
it.live.each(["before-check", "while-measuring"] as const)(
1317-
"keeps a worktree protected by a missing project root (%s)",
1318-
(timing) =>
1316+
it.live.each([
1317+
["before-check", "stored"],
1318+
["while-measuring", "stored"],
1319+
["before-check", "symlinked parent"],
1320+
["while-measuring", "symlinked parent"],
1321+
] as const)(
1322+
"keeps a worktree protected by a missing project root (%s, %s spelling)",
1323+
([timing, spelling]) =>
13191324
runCleanupTest(
13201325
Effect.gen(function* () {
13211326
const fixture = yield* pausedMeasurementFixture();
1327+
let worktree = fixture.worktree;
1328+
if (spelling === "symlinked parent") {
1329+
const linkedParent = `${yield* fixture.fs.makeTempDirectoryScoped({ prefix: "cleanup-link-" })}/worktrees`;
1330+
yield* fixture.fs.symlink(fixture.config.worktreesDir, linkedParent);
1331+
worktree = `${linkedParent}/feature`;
1332+
fixture.setThreads([shell({ branch: "feature", worktreePath: worktree })]);
1333+
}
13221334
if (timing === "before-check")
1323-
fixture.setProjectRoots([fixture.repo, `${fixture.worktree}/removed-checkout`]);
1335+
fixture.setProjectRoots([fixture.repo, `${worktree}/removed-checkout`]);
13241336
const cleanup = yield* fixture.service.runNow.pipe(Effect.forkChild);
13251337
if (timing === "while-measuring") {
13261338
yield* Deferred.await(fixture.measuring);
1327-
fixture.setProjectRoots([fixture.repo, `${fixture.worktree}/removed-checkout`]);
1339+
fixture.setProjectRoots([fixture.repo, `${worktree}/removed-checkout`]);
13281340
}
13291341
yield* Deferred.succeed(fixture.resume, undefined);
13301342
const report = yield* Fiber.join(cleanup);

‎apps/server/src/storageCleanup.ts‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,21 @@ const make = Effect.gen(function* () {
321321
});
322322

323323
const containsProjectRoot = Effect.fn("StorageCleanup.containsProjectRoot")(function* (
324-
worktreePath: string,
324+
worktreePaths: ReadonlyArray<string>,
325325
projects: ReadonlyArray<{ readonly workspaceRoot: string }>,
326326
) {
327+
const contains = (projectPath: string) =>
328+
worktreePaths.some(
329+
(worktreePath) =>
330+
pathKey(projectPath) === pathKey(worktreePath) || inside(worktreePath, projectPath),
331+
);
327332
for (const project of projects) {
328333
const projectPath = path.resolve(project.workspaceRoot);
329-
if (pathKey(projectPath) === pathKey(worktreePath) || inside(worktreePath, projectPath))
330-
return true;
334+
if (contains(projectPath)) return true;
331335
const realPath = yield* fs
332336
.realPath(projectPath)
333337
.pipe(Effect.orElseSucceed(() => projectPath));
334-
if (pathKey(realPath) === pathKey(worktreePath) || inside(worktreePath, realPath))
335-
return true;
338+
if (contains(realPath)) return true;
336339
}
337340
return false;
338341
});
@@ -816,7 +819,9 @@ const make = Effect.gen(function* () {
816819
return keep("worktree is a symbolic link");
817820
if (!roots.some((root) => inside(root, realPath)))
818821
return keep("outside the managed worktree folder");
819-
if (yield* containsProjectRoot(worktreeKey, [project, ...snapshot.projects]))
822+
if (
823+
yield* containsProjectRoot([worktreePath, worktreeKey], [project, ...snapshot.projects])
824+
)
820825
return keep("contains a project checkout");
821826
if ((yield* fs.stat(path.join(worktreePath, ".git"))).type !== "File")
822827
return keep("not a linked worktree");
@@ -934,7 +939,7 @@ const make = Effect.gen(function* () {
934939
// Re-read this path's threads and sessions so new activity cancels removal; full per-worktree snapshots take seconds.
935940
const blockedSinceCheck = Effect.fnUntraced(function* () {
936941
const latestProjects = yield* projectStore.listShells();
937-
if (yield* containsProjectRoot(worktreeKey, [project, ...latestProjects]))
942+
if (yield* containsProjectRoot([worktreePath, worktreeKey], [project, ...latestProjects]))
938943
return "contains a project checkout";
939944
const bindings = yield* projections.getThreadWorktreePaths({ includeArchived: true });
940945
const bindingKeys = yield* Effect.forEach(bindings, (binding) =>

0 commit comments

Comments
 (0)