Skip to content

Commit 38a3287

Browse files
fix(server): scratch cleanup rechecks keep rules after the final folder walk
The walk under the lease can take seconds. The keep-rule, thread and settings checks ran before it, so a file written during the walk was removed even under Any local files. They now run after it, right before the folder is removed. Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent 4acd0b5 commit 38a3287

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎apps/server/src/storageCleanup.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,14 +1362,15 @@ const make = Effect.gen(function* () {
13621362
return yield* withWorkspaceLease(
13631363
worktreePath,
13641364
Effect.gen(function* () {
1365+
// Walked again under the lease: a repository deleted with the folder is gone for good.
1366+
const finalInspection = yield* measureWorktree(worktreePath, "plain-folder");
1367+
if (finalInspection.reason !== null) return keep(finalInspection.reason);
1368+
// The walk takes time, so the cheap checks run last, right before removal.
13651369
const blockedWhileMeasuring =
13661370
(yield* scratchKeepReason(worktreePath, threadIds, settings)) ??
13671371
(yield* blockedSinceCheck());
13681372
if (blockedWhileMeasuring !== null) return keep(blockedWhileMeasuring);
13691373
if (yield* settingsChangedSinceCheck) return keep("settings changed since check");
1370-
// Walked again under the lease: a repository deleted with the folder is gone for good.
1371-
const finalInspection = yield* measureWorktree(worktreePath, "plain-folder");
1372-
if (finalInspection.reason !== null) return keep(finalInspection.reason);
13731374
yield* fs.remove(worktreePath, { recursive: true });
13741375
entries.push({
13751376
...entry,

0 commit comments

Comments
 (0)