Skip to content

Worktree removal discards private refs and clean in-progress Git state #6824

Closed

Description

@joeyfrasier

Summary

Removing a managed worktree can discard private Git recovery refs or an unfinished Git operation even when HEAD is retained by a local branch and porcelain status is empty.

This differs from #5952's archive-dialog request: a check based on uncommitted or unpushed HEAD state also misses these clean-status cases.

Version and environment

Reproduced through the real Worktree host-entry harness against commit 916d684ac23d0b0de82c09cfc7553a50287d2188. Linux, Node 26.13.0, Git 2.56.0. This is a source-level reproduction, not a claim about every released client.

Reproduction

The disposable Git fixtures are in #6823. They create a linked worktree and either:

  1. Create a unique commit with git commit-tree, then retain it only in refs/worktree/recovery, refs/bisect/recovery, or refs/rewritten/recovery.
  2. Create a same-tree side commit, then run git merge --no-ff --no-commit. Porcelain status remains empty, but MERGE_HEAD records the unfinished merge.

To run those fixtures against the original remover in a disposable checkout:

git clone --branch fix/preserve-worktree-on-retirement https://github.com/joeyfrasier/bb.git bb-preservation-repro
cd bb-preservation-repro
pnpm install --frozen-lockfile
git restore --source=916d684ac23d0b0de82c09cfc7553a50287d2188 -- plugins/environment-git-worktree/host.ts plugins/environment-git-worktree/host/worktree.ts
pnpm exec turbo run test --filter=bb-plugin-environment-git-worktree -- -t 'private refs|unfinished merge'

Expected and actual

Expected: removal returns failed and preserves the worktree, private refs, and operation metadata until the owner preserves or resolves the work.

Actual: the original handler returns removed and deletes the worktree metadata. The preservation assertions fail with:

AssertionError: expected { status: 'removed' } to match object { status: 'failed' }

Evidence and scope

The original removeWorktree implementation uses forced Git removal plus a recursive filesystem fallback. The regression fixtures exercise the real handler.

The three private-ref cases and clean pending-merge case were reproduced before their guards were added. With the proposed fix, the full Worktree plugin suite passes 136 tests and typechecking. Private refs and merge metadata remain intact.

This report covers provider removal safety. Archive-dialog choices and an atomic barrier against unrelated external writers remain separate work.

AGENT GENERATED

Activity

  1. added theissue type on Nov 2, 2026
  2. added
    workspaces
    confirmed-repro
    on Nov 2, 2026
  3. bb-slop-cop commented on Nov 2, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority: High · Effort: Medium · Labels: workspaces, confirmed-repro.
    • Report: https://get-bb.github.io/reports/issues/6824.html — REPRODUCED, high root-cause confidence.
    • Root cause: forced removal deletes a worktree's private Git directory without checking private refs or unfinished operation metadata; clean status and a branch retaining HEAD do not protect that state.
    • Evidence: four newly authored real-Git host-entry regressions fail on trusted main in two clean checkouts. They pass after the fix; the full plugin suite passes 126 tests and typecheck.
    • Ready PR: Preserve worktree-local Git state before retirement #6828 — 146 changed text lines across three files; no protocol or dependency changes. It guards removal under existing locks, not unrelated external Git writers.

    AGENT GENERATED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reproworkspaces

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions