Repository navigation
fix(cb-15cw): prune-worktrees.sh keeps a tree whose bead a live session holds - #536
Conversation
…on holds A producer still planning has a clean, landed, quiet tree, and the pruner removed it from under the session. The holder is read from the state files and believed only when agent-alive says the session is running, so a crashed session's tree still goes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WCDKf2aRvKRWd7G9dvQEJE
|
Review (cold read, The fix addresses the stated cause, sits ahead of the four checks, and a crashed session's tree still goes. Case 16 would fail before the change. The fleet view's tidy already guards this through
|
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🟢 Approval recommended
The change adds targeted logic to detect beads held by alive sessions and skip pruning corresponding worktrees, with regression tests covering both the “live holder keeps tree” and “once dead, tree prunes” scenarios and no remaining issues noted.
No open issues 🎉
What changed in this PR
Prevents scripts/prune-worktrees.sh from deleting a clean/landed/stale worktree and branch that are still in active use by a live agent session holding the corresponding bead.
Changes:
- Detect beads held by alive sessions (from state
beador handover when absent) once per sweep and keep matching worktrees. - Emit a keep reason that identifies the live session holding the bead.
- Add regression tests covering “live holder keeps tree” and “once dead, tree prunes” behavior.
| File | Description |
|---|---|
| tests/prune-worktrees.sh | Adds regression cases ensuring a live (stubbed) session holding a bead prevents pruning of an otherwise-eligible worktree, and that pruning resumes once the session is no longer alive. |
| scripts/prune-worktrees.sh | Updates the pruner to scan alive sessions for their current bead (via state or handover) and skip pruning any worktree whose bead is currently held. |
Review effort: Balanced
…and the pruner Answers the review: the handover fallback gets its own case, case 17 asserts the branch goes too, and the state-or-handover read moves to scripts/session-bead.sh so the two callers cannot drift. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WCDKf2aRvKRWd7G9dvQEJE
|
Answers to the review at
The diff is small and all the related suites are green (prune-worktrees, release-bead, worktree-safety, project-sweeps, fleet-retry, disk-preflight, consumer-fixture), so there is no follow-up review. |
Bead: cb-15cw (bugfix).
Bug:
scripts/prune-worktrees.shremoved a live producer's worktree and branch when the tree was clean, at main and unwritten past STALE_MINUTES — exactly a producer still planning (Cyclops on cb-yf8h, 2026-11-10).Reproduction:
tests/prune-worktrees.shcases 16–17: a clean, landed, 10-hour-old tree whose bead a live (stubbed) session holds is kept, with a reason naming the session; an unheld tree in the same sweep still goes; once the session is dead the same tree goes. Case 16 failed before the fix withremoved cb-live.Fix: once per sweep, read which bead each live session is on (state file
bead, or its handover while the state names none; believed only whenagent-alivesucceeds — the same testrelease-bead --worktreeuses for the fleet view's tidy, which already guarded this) and keep a tree whose bead one holds. The claim is still not the guard, so a crashed agent's tree is removed as before.Validation:
bash tests/prune-worktrees.sh,tests/project-sweeps.sh,tests/release-bead.shgreen.bash tests/gate: everything green except the fleet-* PTY suites (fleet-keys, fleet-board, fleet-launch, fleet-type) timing out under load (load avg ~8, other fleet sessions building); each passes run alone, and none touches the pruner.🤖 Generated with Claude Code
https://claude.ai/code/session_01WCDKf2aRvKRWd7G9dvQEJE