Skip to content

Commit 0820469

Browse files
fix(server): scratch cleanup keeps folders with files unless untracked files may be deleted
Every file in a No project folder is untracked and cannot be recovered. The default keep rule protects untracked files in worktrees, but scratch folders with content were kept only under Any local files. They are now kept under every rule except Edited tracked files, the one documented to delete untracked files. Empty and node_modules-only folders are still pruned. Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent 38a3287 commit 0820469

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,6 +2349,8 @@ describe("storage cleanup reports and local file policies", () => {
23492349
yield* fixture.fs.writeFileString(`${folder}/notes.md`, "scratch\n");
23502350
fixture.setProjectRoots([scratchRoot]);
23512351
fixture.setStoredWorktreePaths([]);
2352+
// Only this rule lets cleanup delete untracked files, which is all a scratch folder has.
2353+
fixture.setPolicy("tracked-changes");
23522354
fixture.setThreads([
23532355
shell({ worktreePath: folder, settledAt: at(-20 * DAY_MS), status: "completed" }),
23542356
]);
@@ -2373,12 +2375,13 @@ describe("storage cleanup reports and local file policies", () => {
23732375
repository: ".git",
23742376
reason: "Contains a nested Git repository",
23752377
},
2378+
{ name: "files under the default keep rule", reason: "Has local files (notes.md)" },
23762379
{
2377-
name: "files under Any local files",
2378-
policy: "any-local-files",
2379-
reason: "Has local files (notes.md)",
2380+
name: "a scheduled task",
2381+
policy: "tracked-changes",
2382+
scheduled: true,
2383+
reason: "Thread has a scheduled task",
23802384
},
2381-
{ name: "a scheduled task", scheduled: true, reason: "Thread has a scheduled task" },
23822385
] as const)(
23832386
"keeps an idle No project thread's scratch folder with $name",
23842387
({

‎apps/server/src/storageCleanup.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,8 @@ const make = Effect.gen(function* () {
10211021
const realParent = yield* fs.realPath(path.dirname(folder));
10221022
if ((yield* fs.realPath(folder)) !== path.join(realParent, path.basename(folder)))
10231023
return "folder is a symbolic link";
1024-
if (rules.worktreeKeepWhen === "any-local-files") {
1024+
// Every file here is untracked, and only "tracked-changes" lets cleanup delete those.
1025+
if (rules.worktreeKeepWhen !== "tracked-changes") {
10251026
const file = (yield* fs.readDirectory(folder)).find((name) => name !== "node_modules");
10261027
if (file !== undefined) return `has local files (${file})`;
10271028
}

‎docs/user/project-settings.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,10 @@ The inactive and settled retention periods also apply to the folders of
254254
[threads without a project](./thread-sidebar.md#start-without-a-project). Those folders are not
255255
Git repositories, so their files are deleted with them and cannot be recovered; the thread stays,
256256
and its next turn starts in a new, empty folder. A folder is kept when it has a Git repository
257-
anywhere inside it, when its thread has an enabled scheduled task, or, under **Any local files**,
258-
when it holds anything other than `node_modules`. Folders that no thread uses are listed here too.
257+
anywhere inside it or when its thread has an enabled scheduled task. Every file in such a folder
258+
counts as untracked, so only **Edited tracked files** removes a folder that holds anything other
259+
than `node_modules`; the other two rules remove only empty folders. Folders that no thread uses
260+
are listed here too.
259261

260262
Browser captures and rotated logs have separate retention periods. Expired capture links stop
261263
working. Current logs, message attachments, and browser profiles are kept.

0 commit comments

Comments
 (0)