fix(server): free worktrees for terminal thread statuses (#15150)
This commit is contained in:
1 parent
93e864042c
commit
e0201d3ab5
2 files changed
+48
-1
No files matched your search
@@ -3,6 +3,7 @@ import {
|
||||
ProjectId,
|
||||
ProviderInstanceId,
|
||||
RunId,
|
||||
RuntimeRequestId,
|
||||
ThreadId,
|
||||
type OrchestrationV2ThreadShell,
|
||||
} from "@t3tools/contracts";
|
||||
@@ -84,6 +85,47 @@ describe("V2 storage cleanup eligibility", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["idle", "completed", "interrupted", "failed", "cancelled", "rolled_back"] as const)(
|
||||
"allows cleanup once its thread is %s",
|
||||
(status) => {
|
||||
expect(storageCleanupThreadIdle(candidateWithStatus(status), NOW_MS)).toBe(true);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["completed", "interrupted", "cancelled", "rolled_back"] as const)(
|
||||
"retains %s while background work is pending",
|
||||
(status) => {
|
||||
expect(
|
||||
storageCleanupThreadIdle(
|
||||
{
|
||||
...candidateWithStatus(status),
|
||||
pendingBackgroundTasks: [{ taskId: "task-1", kind: "command" }],
|
||||
},
|
||||
NOW_MS,
|
||||
),
|
||||
).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["completed", "interrupted", "cancelled", "rolled_back"] as const)(
|
||||
"retains %s while a runtime request is pending",
|
||||
(status) => {
|
||||
expect(
|
||||
storageCleanupThreadIdle(
|
||||
{
|
||||
...candidateWithStatus(status),
|
||||
pendingRuntimeRequest: {
|
||||
id: RuntimeRequestId.make("request-1"),
|
||||
kind: "command",
|
||||
createdAt: at(0),
|
||||
},
|
||||
},
|
||||
NOW_MS,
|
||||
),
|
||||
).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
it("retains an active run even if the shell status is idle", () => {
|
||||
expect(
|
||||
storageCleanupThreadIdle({ ...candidate(), activeRunId: RunId.make("run") }, NOW_MS),
|
||||
|
||||
@@ -86,7 +86,12 @@ export function storageCleanupThreadIdle(thread: OrchestrationV2ThreadShell, now
|
||||
thread.branch !== null &&
|
||||
thread.worktreePath !== null &&
|
||||
thread.activeRunId === null &&
|
||||
(thread.status === "idle" || thread.status === "failed") &&
|
||||
(thread.status === "idle" ||
|
||||
thread.status === "completed" ||
|
||||
thread.status === "interrupted" ||
|
||||
thread.status === "failed" ||
|
||||
thread.status === "cancelled" ||
|
||||
thread.status === "rolled_back") &&
|
||||
(thread.pendingBackgroundTasks?.length ?? 0) === 0 &&
|
||||
thread.pendingRuntimeRequest === null &&
|
||||
!threadHasQueuedTurnStart(thread, now)
|
||||
|
||||
Reference in new issue
Block a user