diff --git a/apps/server/src/orchestration-v2/ThreadManagementService.test.ts b/apps/server/src/orchestration-v2/ThreadManagementService.test.ts index b494a637c4..d0002cfe35 100644 --- a/apps/server/src/orchestration-v2/ThreadManagementService.test.ts +++ b/apps/server/src/orchestration-v2/ThreadManagementService.test.ts @@ -393,6 +393,7 @@ it.effect("lists compact references for every active thread, including hidden su parentThreadId: null, relationshipToParent: null, } as const; + const archivedId = ThreadId.make("thread:thread-management:refs-archived"); const threads = [ shell(rootId, rootLineage, null), shell( @@ -417,7 +418,10 @@ it.effect("lists compact references for every active thread, including hidden su schemaVersion: 3, snapshotSequence: 10, threads, - archivedThreads: [], + // An archived thread still holds its worktree; worktree cleanup + // treats this RPC as the complete set, so omitting the archive + // would classify that worktree as orphaned and remove it. + archivedThreads: [shell(archivedId, rootLineage, null)], }), }), ), @@ -427,7 +431,7 @@ it.effect("lists compact references for every active thread, including hidden su const service = yield* ThreadManagementService; expect(yield* service.listAllThreadRefs()).toEqual({ - threadRefs: threads.map((thread) => ({ + threadRefs: [...threads, shell(archivedId, rootLineage, null)].map((thread) => ({ threadId: thread.id, projectId, worktreePath, diff --git a/apps/server/src/orchestration-v2/ThreadManagementService.ts b/apps/server/src/orchestration-v2/ThreadManagementService.ts index 3ef3deb727..d1562e32d3 100644 --- a/apps/server/src/orchestration-v2/ThreadManagementService.ts +++ b/apps/server/src/orchestration-v2/ThreadManagementService.ts @@ -479,11 +479,16 @@ const make = Effect.gen(function* () { const listAllThreadRefs: ThreadManagementServiceShape["listAllThreadRefs"] = () => orchestrator.getShellSnapshot().pipe( Effect.map((snapshot) => ({ - threadRefs: snapshot.threads.map(({ id, projectId, worktreePath }) => ({ - threadId: id, - projectId, - worktreePath, - })), + // Worktree cleanup treats this as the complete set: an archived thread + // still holds its worktree, so omitting the archive would classify it + // as orphaned and remove it. + threadRefs: [...snapshot.threads, ...snapshot.archivedThreads].map( + ({ id, projectId, worktreePath }) => ({ + threadId: id, + projectId, + worktreePath, + }), + ), })), );