@devries-cameron20 / t3code Mirror · read-only / commits / e0201d3ab5
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 18:00 UTC

fix(server): free worktrees for terminal thread statuses (#15150)

ANSH SINGH committed Oct 7, 2026 at 22:55 UTC e0201d3ab51b4593eff3c41d03ab9c9b2dc07471
2 files changed +48 -1
apps/server/src/storageCleanup.test.ts
+42
@@ -3,6 +3,7 @@ import {
3 ProjectId,
4 ProviderInstanceId,
5 RunId,
6 + RuntimeRequestId,
7 ThreadId,
8 type OrchestrationV2ThreadShell,
9 } from "@t3tools/contracts";
@@ -84,6 +85,47 @@ describe("V2 storage cleanup eligibility", () => {
85 },
86 );
87
88 + it.each(["idle", "completed", "interrupted", "failed", "cancelled", "rolled_back"] as const)(
89 + "allows cleanup once its thread is %s",
90 + (status) => {
91 + expect(storageCleanupThreadIdle(candidateWithStatus(status), NOW_MS)).toBe(true);
92 + },
93 + );
94 +
95 + it.each(["completed", "interrupted", "cancelled", "rolled_back"] as const)(
96 + "retains %s while background work is pending",
97 + (status) => {
98 + expect(
99 + storageCleanupThreadIdle(
100 + {
101 + ...candidateWithStatus(status),
102 + pendingBackgroundTasks: [{ taskId: "task-1", kind: "command" }],
103 + },
104 + NOW_MS,
105 + ),
106 + ).toBe(false);
107 + },
108 + );
109 +
110 + it.each(["completed", "interrupted", "cancelled", "rolled_back"] as const)(
111 + "retains %s while a runtime request is pending",
112 + (status) => {
113 + expect(
114 + storageCleanupThreadIdle(
115 + {
116 + ...candidateWithStatus(status),
117 + pendingRuntimeRequest: {
118 + id: RuntimeRequestId.make("request-1"),
119 + kind: "command",
120 + createdAt: at(0),
121 + },
122 + },
123 + NOW_MS,
124 + ),
125 + ).toBe(false);
126 + },
127 + );
128 +
129 it("retains an active run even if the shell status is idle", () => {
130 expect(
131 storageCleanupThreadIdle({ ...candidate(), activeRunId: RunId.make("run") }, NOW_MS),
apps/server/src/storageCleanup.ts
+6 -1
@@ -86,7 +86,12 @@ export function storageCleanupThreadIdle(thread: OrchestrationV2ThreadShell, now
86 thread.branch !== null &&
87 thread.worktreePath !== null &&
88 thread.activeRunId === null &&
89 - (thread.status === "idle" || thread.status === "failed") &&
89 + (thread.status === "idle" ||
90 + thread.status === "completed" ||
91 + thread.status === "interrupted" ||
92 + thread.status === "failed" ||
93 + thread.status === "cancelled" ||
94 + thread.status === "rolled_back") &&
95 (thread.pendingBackgroundTasks?.length ?? 0) === 0 &&
96 thread.pendingRuntimeRequest === null &&
97 !threadHasQueuedTurnStart(thread, now)