Skip to content

[Bug]: Cleanup shows the old size after files are removed from a kept worktree #39016

Closed

Description

@StiensWout

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Enable a worktree cleanup rule.
  2. Create a Git worktree in the managed worktrees folder without attaching it to a thread.
  3. Put a large build artifact in a subfolder of the worktree.
  4. After the worktree is at least an hour old, run Delete now under Settings → Maintenance.
  5. Open Last run to see the size of the kept worktree.
  6. Delete the build artifact without moving the worktree.
  7. Run Delete now again.

Expected behavior

The new report shows how much space the worktree still takes up.

Actual behavior

The new report still shows the size from before the build artifact was deleted.

kept worktree after build file removal

failure

Impact

Minor bug or occasional failure. Anyone who frees space inside a previously reported orphan worktree can see its old size on subsequent runs while cleanup keeps reporting the same folder.

Version or commit

main at 94baff19c6. The cause is at apps/server/src/storageCleanup.ts:597.

Environment

Linux x64 boat.dev default machine, a fresh checkout.

Logs or stack traces

expected: text containing /\b\d+(?:\.\d+)? KB\b/
Automated repro

Fails in 2 of 2 runs on main: apply the patch with git apply, then run the command.

diff --git a/scripts/scenarios/orphan-worktree-cleanup-refreshes-size.e2e.ts b/scripts/scenarios/orphan-worktree-cleanup-refreshes-size.e2e.ts
new file mode 100644
index 0000000000..71be92aa13
--- /dev/null
+++ b/scripts/scenarios/orphan-worktree-cleanup-refreshes-size.e2e.ts
@@ -0,0 +1,74 @@
+import { randomBytes } from "node:crypto";
+import { expect } from "e2e";
+import * as Effect from "effect/Effect";
+import * as FileSystem from "effect/FileSystem";
+import * as Schema from "effect/Schema";
+
+import { T3_HOME } from "../e2e.config.ts";
+import { run } from "./shell.ts";
+import { runPromise, test, WEB } from "./t3.ts";
+
+const decodeSettings = Schema.decodeSync(
+  Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown)),
+);
+
+test(
+  "Cleanup updates the displayed size of a kept worktree",
+  WEB,
+  async ({ t3, app, browser, screen }) => {
+    const project = await t3.project("cleanup-size", { "README.md": "Example project" });
+    const settingsPath = `${T3_HOME}/userdata/settings.json`;
+    const original = await runPromise(
+      Effect.flatMap(FileSystem.FileSystem, (fs) => fs.readFileString(settingsPath)),
+    );
+    const worktree = `${T3_HOME}/worktrees/cleanup-size-orphan`;
+    const build = `${worktree}/build`;
+    const git = (...args: ReadonlyArray<string>) => runPromise(run("git", args, { cwd: project }));
+    await git("worktree", "add", "--detach", worktree, "HEAD");
+    try {
+      await runPromise(
+        Effect.gen(function* () {
+          const fs = yield* FileSystem.FileSystem;
+          yield* fs.makeDirectory(build);
+          yield* fs.writeFile(`${build}/bundle.js`, randomBytes(8 * 1024 * 1024));
+          yield* fs.utimes(worktree, 1, 1);
+          yield* fs.writeFileString(
+            settingsPath,
+            JSON.stringify({
+              ...decodeSettings(original),
+              storageCleanup: { worktreeOnDelete: true },
+            }),
+          );
+        }),
+      );
+
+      await t3.open("/settings/maintenance");
+      const runCleanup = screen.getByRole("button", "Delete now", { exact: true });
+      await runCleanup.tap();
+      await screen.getByRole("button", /^Last run/).tap();
+      await screen.getByText(/^8\.\d{2} MB$/).waitFor();
+
+      await runPromise(
+        Effect.gen(function* () {
+          const fs = yield* FileSystem.FileSystem;
+          yield* fs.remove(`${build}/bundle.js`);
+        }),
+      );
+      await runCleanup.tap();
+      await runCleanup.waitFor();
+      await screen.getByText("No thread uses this worktree", { exact: true }).scrollIntoView();
+      try {
+        await expect(browser.locator("#storage-cleanup-last-run")).toContainText(
+          /\b\d+(?:\.\d+)? KB\b/,
+        );
+      } finally {
+        await app.screenshot("kept-worktree-after-build-file-removal");
+      }
+    } finally {
+      await git("worktree", "remove", "--force", worktree);
+      await runPromise(
+        Effect.flatMap(FileSystem.FileSystem, (fs) => fs.writeFileString(settingsPath, original)),
+      );
+    }
+  },
+);
pnpm scenarios:prove scripts/scenarios/orphan-worktree-cleanup-refreshes-size.e2e.ts --base main

Workaround

No response

Activity

  1. added
    vouch:trusted
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    vouch:trusted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions