From 1aea7ba0d3782beb47e4dc1999284b923264d2dc Mon Sep 17 00:00:00 2001 From: Shivam Sharma <91240327+shivamhwp@users.noreply.github.com> Date: Thu, 6 Aug 2026 03:06:35 +0530 Subject: [PATCH] fix(threads): include archived threads in the unfiltered thread refs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Worktree cleanup treats listAllThreadRefs as the complete set, but it mapped only the live shells. A worktree held solely by an archived thread was therefore classified orphaned and offered for removal — the same data-loss shape this RPC exists to prevent, through a different gap. Also drops the two toSorted calls in the subagent derivations: this module is mobile-reachable and Hermes ships no ES2023 change-by-copy array methods, so an Android import could crash. The regression deletes toSorted from the prototype while exercising both derivations. Co-Authored-By: Claude Fable 5 --- .../ThreadManagementService.test.ts | 8 ++++++-- .../orchestration-v2/ThreadManagementService.ts | 15 ++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) 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, + }), + ), })), );