From 0046679d9df598f2fb965fb4d34f4208512d5295 Mon Sep 17 00:00:00 2001 From: Hemanth Soni Date: Thu, 20 Aug 2026 16:34:15 -0400 Subject: [PATCH] Allow branch checkout after workspace threads are archived --- .../threads/workspace-path-claims.test.ts | 36 +++++++++++++++++++ packages/db/src/data/threads.ts | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/apps/server/test/threads/workspace-path-claims.test.ts b/apps/server/test/threads/workspace-path-claims.test.ts index 91a1b891f6..7224bf6bc2 100644 --- a/apps/server/test/threads/workspace-path-claims.test.ts +++ b/apps/server/test/threads/workspace-path-claims.test.ts @@ -1,3 +1,4 @@ +import { archiveThread } from "@bb/db"; import { describe, expect, it } from "vitest"; import { unmanagedAttachRefusal } from "../../src/services/threads/workspace-path-claims.js"; import { @@ -141,4 +142,39 @@ describe("unmanagedAttachRefusal", () => { ).toMatchObject({ reason: "live-thread" }); }); }); + + it("allows branch checkout after every thread at the path is archived", async () => { + await withTestHarness(async (harness) => { + const { host } = seedHostSession(harness.deps, { + id: "host-claims-archived", + }); + const sharedPath = "/tmp/archived-shared"; + const { project } = seedProjectWithSource(harness.deps, { + hostId: host.id, + name: "Archived", + path: sharedPath, + }); + const environment = seedEnvironment(harness.deps, { + hostId: host.id, + projectId: project.id, + path: sharedPath, + }); + const thread = seedThread(harness.deps, { + projectId: project.id, + environmentId: environment.id, + status: "idle", + }); + archiveThread(harness.deps.db, harness.deps.hub, thread.id); + + expect( + unmanagedAttachRefusal(harness.deps.db, { + checksOutBranch: true, + dataDir: HOST_DATA_DIR, + hostId: host.id, + path: sharedPath, + projectId: project.id, + }), + ).toBeNull(); + }); + }); }); diff --git a/packages/db/src/data/threads.ts b/packages/db/src/data/threads.ts index eda475b8b3..f1c97c02a4 100644 --- a/packages/db/src/data/threads.ts +++ b/packages/db/src/data/threads.ts @@ -1411,7 +1411,7 @@ export function hasLiveThreadAtHostPath( and( eq(environments.hostId, args.hostId), eq(environments.path, args.path), - nonDeletedThreads( + liveThreads( inArray(threads.status, [...NON_TERMINAL_THREAD_STATUSES]), ), ),