Skip to content

Commit c324c3a

Browse files
fix(server): free worktrees for terminal thread statuses
storageCleanupThreadIdle only allowed idle and failed, so completed, cancelled, interrupted, and rolled_back threads kept their worktrees forever. Treat all terminal statuses as idle-eligible once the run, background, and queue guards pass.
1 parent 31a9da1 commit c324c3a

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ describe("V2 storage cleanup eligibility", () => {
8080
},
8181
);
8282

83+
it.each(["idle", "completed", "interrupted", "failed", "cancelled", "rolled_back"] as const)(
84+
"allows cleanup once its thread is %s",
85+
(status) => {
86+
expect(storageCleanupThreadIdle(candidateWithStatus(status), NOW_MS)).toBe(true);
87+
},
88+
);
89+
8390
it("retains an active run even if the shell status is idle", () => {
8491
expect(
8592
storageCleanupThreadIdle({ ...candidate(), activeRunId: RunId.make("run") }, NOW_MS),

‎apps/server/src/storageCleanup.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ export function storageCleanupThreadIdle(thread: OrchestrationV2ThreadShell, now
8585
thread.branch !== null &&
8686
thread.worktreePath !== null &&
8787
thread.activeRunId === null &&
88-
(thread.status === "idle" || thread.status === "failed") &&
88+
(thread.status === "idle" ||
89+
thread.status === "completed" ||
90+
thread.status === "interrupted" ||
91+
thread.status === "failed" ||
92+
thread.status === "cancelled" ||
93+
thread.status === "rolled_back") &&
8994
(thread.pendingBackgroundTasks?.length ?? 0) === 0 &&
9095
thread.pendingRuntimeRequest === null &&
9196
!threadHasQueuedTurnStart(thread, now)

0 commit comments

Comments
 (0)