@devries-cameron20 / t3code-1 / commits / 71c2d3a302
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): storage report lists project worktrees nested inside plain folders (#25883)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 7, 2026 at 17:27 UTC 71c2d3a302092b94511eb7e6ab4e6844a66dbf22
2 files changed +87 -1
apps/server/src/storageCleanup.test.ts
+65
@@ -1797,6 +1797,71 @@ describe("orphan worktree reports", () => {
1797 ),
1798 );
1799
1800 + it.live("reports linked worktrees nested deeper inside a plain folder", () =>
1801 + runCleanupTest(
1802 + Effect.gen(function* () {
1803 + const fixture = yield* cleanupFixture();
1804 + fixture.setThreads([]);
1805 + const replay = `${fixture.config.worktreesDir}/repository/replay`;
1806 + const deep = `${fixture.config.worktreesDir}/repository/deep`;
1807 + const worktrees = [`${deep}/a/b`, `${replay}/1376`];
1808 + for (const [index, worktree] of worktrees.entries()) {
1809 + yield* fixture.command(fixture.repo, [
1810 + "worktree",
1811 + "add",
1812 + "-b",
1813 + `nested-${index}`,
1814 + worktree,
1815 + ]);
1816 + }
1817 + for (const folder of [...worktrees, `${deep}/a`, deep, replay]) {
1818 + yield* fixture.fs.utimes(folder, 1, 1);
1819 + }
1820 + const report = yield* fixture.service.runNow;
1821 + expect(
1822 + report.entries
1823 + .map((entry) => ({ path: entry.path, reason: entry.reason }))
1824 + .sort((left, right) => String(left.path).localeCompare(String(right.path))),
1825 + ).toEqual(worktrees.map((path) => ({ path, reason: "No thread uses this worktree" })));
1826 + }),
1827 + ),
1828 + );
1829 +
1830 + it.live("still reports a plain folder whose nested worktree registration is stale", () =>
1831 + runCleanupTest(
1832 + Effect.gen(function* () {
1833 + const fixture = yield* cleanupFixture();
1834 + fixture.setThreads([]);
1835 + const replay = `${fixture.config.worktreesDir}/repository/replay`;
1836 + const worktree = `${replay}/1376`;
1837 + yield* fixture.command(fixture.repo, ["worktree", "add", "-b", "locked", worktree]);
1838 + yield* fixture.command(fixture.repo, ["worktree", "lock", worktree]);
1839 + yield* fixture.fs.rename(worktree, `${replay}/moved`);
1840 + yield* fixture.fs.makeDirectory(worktree);
1841 + yield* fixture.fs.utimes(replay, 1, 1);
1842 + expect((yield* fixture.service.runNow).entries.map((entry) => entry.path)).toEqual([
1843 + replay,
1844 + ]);
1845 + }),
1846 + ),
1847 + );
1848 +
1849 + it.live("does not report nested worktrees inside a project checkout", () =>
1850 + runCleanupTest(
1851 + Effect.gen(function* () {
1852 + const fixture = yield* cleanupFixture();
1853 + fixture.setThreads([]);
1854 + const project = `${fixture.config.worktreesDir}/repository/replay/project`;
1855 + const worktree = `${project}/nested`;
1856 + yield* fixture.fs.makeDirectory(project, { recursive: true });
1857 + fixture.setProjectRoots([fixture.repo, project]);
1858 + yield* fixture.command(fixture.repo, ["worktree", "add", "-b", "nested", worktree]);
1859 + for (const folder of [worktree, project]) yield* fixture.fs.utimes(folder, 1, 1);
1860 + expect((yield* fixture.service.runNow).entries).toEqual([]);
1861 + }),
1862 + ),
1863 + );
1864 +
1865 it.live("continues after an inaccessible directory's git probe", (context) =>
1866 runCleanupTest(
1867 Effect.gen(function* () {
apps/server/src/storageCleanup.ts
+22 -1
@@ -545,6 +545,26 @@ const make = Effect.gen(function* () {
545 },
546 Effect.orElseSucceed(() => undefined),
547 );
548 + // Linked worktrees can sit deeper inside a plain folder, like <repository>/replay/<n>. Ask
549 + // the projects' Git for them rather than walking folders that may hold large non-git trees.
550 + let registered: ReadonlyArray<string> | undefined;
551 + const nestedWorktrees = Effect.fnUntraced(function* (folder: string, managedRoot: string) {
552 + if (yield* fs.exists(path.join(folder, ".git"))) return [];
553 + registered ??= (yield* Effect.forEach(new Set(projectRoots), (root) =>
554 + git.listWorktreePaths(root).pipe(Effect.orElseSucceed((): string[] => [])),
555 + )).flat();
556 + // Locked registrations outlive their directory, whose path may since hold something else.
557 + return yield* Effect.filter(
558 + registered.filter(
559 + (worktree) => inside(folder, worktree) && !inProject(worktree, managedRoot),
560 + ),
561 + (worktree) =>
562 + Effect.gen(function* () {
563 + if (pathKey(yield* fs.realPath(worktree)) !== pathKey(worktree)) return false;
564 + return (yield* fs.stat(path.join(worktree, ".git"))).type === "File";
565 + }).pipe(Effect.orElseSucceed(() => false)),
566 + );
567 + });
568 for (const root of roots) {
569 // Worktrees can be <root>/<repository>/<branch> or explicitly <root>/<name>.
570 for (const projectDirectory of yield* directories(root, root)) {
@@ -556,7 +576,8 @@ const make = Effect.gen(function* () {
576 return;
577 }
578 for (const worktreePath of yield* directories(projectDirectory, root)) {
559 - yield* report(worktreePath);
579 + const nested = yield* nestedWorktrees(worktreePath, root);
580 + for (const target of nested.length > 0 ? nested : [worktreePath]) yield* report(target);
581 }
582 }).pipe(Effect.orElseSucceed(() => undefined));
583 }