Skip to content

Archived idle threads block branch checkout after the workspace is released #2068

Closed

Description

@hemaaanth

Workflow

In a project backed by a local unmanaged Git checkout:

  1. Finish and archive every thread attached to the project workspace.
  2. Create a new thread in that project.
  3. Select New branch from: main so bb checks out a branch in the existing workspace.

What happened

Thread creation failed with:

Cannot checkout branch while another thread is using this workspace

The project had no unarchived threads, including hidden threads. The remaining threads were archived and idle.

Archiving the threads did not release the workspace claim. bb thread stop did not help because stopping an idle thread is intentionally a no-op: the archived threads remained in idle status and continued to satisfy the checkout guard.

Using an isolated worktree or creating the thread without a requested branch checkout avoids the failure. Deleting the archived threads would also avoid it, but that should not be required and destroys history.

Expected behavior

After every thread attached to a workspace is archived, bb should allow a new thread to check out a branch in that workspace.

An unarchived thread that is actually starting, idle, or active should continue to block a branch checkout that would rewrite its working tree.

Likely mechanism

unmanagedAttachRefusal() calls hasLiveThreadAtHostPath() when a thread request includes a branch checkout.

hasLiveThreadAtHostPath() joins threads to environments and filters for:

  • the same host and physical path;
  • a non-deleted thread;
  • starting, idle, or active status.

It does not filter out rows with archivedAt set. Archiving an idle thread preserves its idle status, so an archived thread is treated as a live workspace user indefinitely.

There is already a liveThreads() query helper that adds archivedAt IS NULL, but this query currently uses nonDeletedThreads() instead.

The existing unmanagedAttachRefusal test covers an active thread blocking checkout, but not an archived idle thread releasing the claim.

The cross-project physical-path guard was introduced in #1049. This report does not challenge that safety guard; it concerns archived threads being included in its definition of a live workspace user.

Suggested fix

  • Exclude archived rows in hasLiveThreadAtHostPath() while retaining the nonterminal-status filter.
  • Add regression coverage proving:
    • an archived idle thread at the path does not produce a live-thread refusal;
    • an unarchived active thread at the path still does.

Environment

  • bb-app 0.38.0
  • Linux x64
  • Node.js 26.7.0
  • Local unmanaged Git workspace

A deterministic reproduction script using bb's in-memory server test harness will follow separately.

AGENT GENERATED: by GPT-5.6 Sol

Activity

  1. hemaaanth commented on Aug 20, 2026

    @hemaaanth
    ContributorAuthor

    Here is a deterministic reproducer that uses bb's in-memory server test harness and the real workspace-claim query. It does not touch a running bb service, an existing database, or a real workspace.

    With workspace dependencies installed, save it as apps/server/scripts/repro-archived-thread-blocks-checkout.mts and run:

    node --conditions=source --import tsx apps/server/scripts/repro-archived-thread-blocks-checkout.mts
    import assert from "node:assert/strict";
    import { archiveThread, getThread } from "@bb/db";
    import { unmanagedAttachRefusal } from "../src/services/threads/workspace-path-claims.js";
    import {
      seedEnvironment,
      seedHostSession,
      seedProjectWithSource,
      seedThread,
    } from "../test/helpers/seed.js";
    import { withTestHarness } from "../test/helpers/test-app.js";
    
    const HOST_DATA_DIR = "/home/agent/.bb";
    const SHARED_PATH = "/tmp/repro-archived-thread-workspace";
    
    await withTestHarness(async (harness) => {
      const { host } = seedHostSession(harness.deps, {
        id: "host-archived-thread-repro",
      });
      const { project } = seedProjectWithSource(harness.deps, {
        hostId: host.id,
        name: "Archived thread checkout repro",
        path: SHARED_PATH,
      });
      const environment = seedEnvironment(harness.deps, {
        hostId: host.id,
        projectId: project.id,
        path: SHARED_PATH,
      });
      const thread = seedThread(harness.deps, {
        projectId: project.id,
        environmentId: environment.id,
        status: "idle",
        title: "Archived idle thread",
      });
    
      archiveThread(harness.deps.db, harness.deps.hub, thread.id);
    
      const archivedThread = getThread(harness.deps.db, thread.id);
      assert.ok(archivedThread?.archivedAt, "thread was not archived");
      assert.equal(archivedThread.status, "idle");
    
      const refusal = unmanagedAttachRefusal(harness.deps.db, {
        checksOutBranch: true,
        dataDir: HOST_DATA_DIR,
        hostId: host.id,
        path: SHARED_PATH,
        projectId: project.id,
      });
    
      assert.deepEqual(refusal, {
        reason: "live-thread",
        message:
          "Cannot checkout branch while another thread is using this workspace",
      });
    
      console.log("BUG REPRODUCED: archived idle thread blocks branch checkout");
      console.log(
        JSON.stringify(
          {
            archived: archivedThread.archivedAt !== null,
            status: archivedThread.status,
            refusal,
          },
          null,
          2,
        ),
      );
    });

    Current output:

    BUG REPRODUCED: archived idle thread blocks branch checkout
    {
      "archived": true,
      "status": "idle",
      "refusal": {
        "reason": "live-thread",
        "message": "Cannot checkout branch while another thread is using this workspace"
      }
    }
    
  2. added theissue type on Aug 21, 2026
  3. added
    workspaces
    threads
    on Aug 21, 2026
  4. SawyerHood commented on Aug 21, 2026

    @SawyerHood
    Collaborator

    Reproduction & root-cause report: https://get-bb.github.io/reports/issues/2068.html

    • Verdict: REPRODUCED · root-cause confidence: high
    • Root cause (short): hasLiveThreadAtHostPath() (packages/db/src/data/threads.ts#L1398-L1417) filters on deleted_at IS NULL + status in starting/idle/active but never on archived_at, and archiveThread() leaves status 'idle', so an archived idle thread satisfies the branch-checkout guard in unmanagedAttachRefusal() forever and every "New branch from" thread create in that folder gets 409.
    • Linked PR review: Allow branch checkout after workspace threads are archived #2069 → MERGE — One-line root-cause fix (nonDeletedThreads -> liveThreads in hasLiveThreadAtHostPath) with a regression test; verified live (409 -> 201, branch bb/ created) and an unarchived active/idle thread still blocks; full @bb/server (1901) and @bb/db (406) suites pass when cherry-picked onto fcada5a.
    • Proposed fix: In packages/db/src/data/threads.ts hasLiveThreadAtHostPath, wrap the status predicate with the existing liveThreads() helper (adds archived_at IS NULL) instead of nonDeletedThreads(); keep the starting/idle/active status filter. This is exactly PR Allow branch checkout after workspace threads are archived #2069. Safe because archiving an active thread synchronously moves it to 'stopping' (a status the guard already ignores) and unarchive re-applies the guard. Optional follow-ups: a route-level test via createThreadFromRequest with branch {kind:"new"}, include 'stopping' threads with a live turn in the guard, and name the blocking thread in the 409 mes…
    • Caveats: Reproduced on macOS 26.5 / Node 22 rather than the reporter's Linux / Node 26 (the query is platform-independent). The live repro used two tiny real claude-code turns. The UI thread view screenshot on the PR build was taken after the thread finished, not mid-create. Worktree left on branch pr2069-on-base (PR commit cherry-picked onto fcada5a) with the untracked repro test file; origin/main (3 co…

    The report has copy-paste repro steps, screenshots where the bug is visual, code permalinks at the base commit, and repro artifacts. It was independently re-run by a second agent (see its Verification section).

    AGENT GENERATED: by Claude Opus 5

  5. added
    confirmed-repro
    on Aug 21, 2026
  6. self-assigned this
    on Aug 25, 2026
  7. added a commit that references this issue on Aug 25, 2026
    3658617
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

confirmed-reprothreadsworkspaces

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions