Skip to content

fix(cb-7suc): the worktree pruner removes finished trees in a repo with submodules or squash merges - #471

Merged
rmstdope merged 3 commits into
mainfrom
cb-7suc-prune
Sep 27, 2026
Merged

rmstdope merged 3 commits into
mainfrom
cb-7suc-prune

Conversation

@rmstdope

Copy link
Copy Markdown
Owner

Bead cb-7suc (P0 bug). Seen on neser: 80 trees, 442 GB, the pruner removing nothing.

Both faults live in scripts/worktree-safety.sh, which prune-worktrees.sh and the fleet view's tidy (release-bead --worktree) share, so one fix covers both callers.

  • Squash merges. cerebro_worktree_landed now asks, after ancestry and before merged_check, whether a commit on origin/main names the tree's bead, through scripts/bead-delivery.sh, the same test that calls a bead delivered. It needs no network, so a gh that cannot answer no longer keeps a delivered tree for ever. The tree's name is tried as it stands, then less a -mockup or -2 suffix, since a bead id ends in -<word> itself.
  • Submodules. git worktree remove refuses any tree containing a populated submodule. cerebro_worktree_remove now, on a refusal, deletes a tree that carries .gitmodules and is not locked directly and prunes the registration; the caller's clean-and-landed tests already hold, and a locked tree is still refused.

Tests first in tests/worktree-safety.sh: a squash-merged bead's tree is landed with gh answering no, the -2 and -mockup names are judged by their bead, an undelivered bead is still kept, and a tree with an initialised submodule that git refuses is removed with its branch and registration gone. Every bash suite green. docs/agent-workflow.md's pruner paragraph says what the pruner now does.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GKiLr59caM9f6DxkrsDYR8

…th submodules or squash merges

Two faults kept every finished tree on a consumer with submodules that
squash-merges: git refuses to remove a working tree containing a
submodule, whatever its state, so the pruner and the view's tidy kept
each one as "git would not remove it"; and a squash-merged branch's
commits are never ancestors of main, so when gh could not answer the
tree was kept as holding work not on main. The safety library now
judges a tree landed when a commit on main names its bead, the fleet's
own delivery test, before asking gh; and a clean, landed tree git
refuses only for its submodule is deleted directly and its registration
pruned, a locked tree still refused.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GKiLr59caM9f6DxkrsDYR8

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

It performs destructive rm -rf removals and broadens the "landed" heuristic in shared, all-consumer worktree-janitor logic, which warrants final human review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

This PR fixes bead cb-7suc (P0): the shared worktree-pruning safety logic in scripts/worktree-safety.sh (used by both prune-worktrees.sh and release-bead --worktree) was leaving finished worktrees behind on consumers that squash-merge or use submodules, causing large disk buildup (reported: 80 trees, 442 GB). It addresses two independent faults with one change to the shared file, so both callers benefit.

Changes:

  • Adds a network-free "delivered" test: cerebro_worktree_landed now also treats a tree as landed when a commit on origin/<base> names the tree's bead (via scripts/bead-delivery.sh), mapping the directory name to candidate bead ids (raw, then minus a -mockup or numeric suffix).
  • Makes cerebro_worktree_remove delete a tree that git worktree remove refuses solely because it contains a populated submodule (guarded by a new cerebro_worktree_locked check and the presence of .gitmodules), then prunes the registration.
  • Adds tests for squash-merge landing, suffix-name mapping, an undelivered bead still kept, and submodule-tree removal; updates the pruner paragraph in docs/agent-workflow.md.
File Description
scripts/​worktree-safety.sh New cerebro_worktree_bead/cerebro_worktree_delivered/cerebro_worktree_locked helpers; landed gains the delivery-commit test; remove deletes submodule-containing trees git refuses.
tests/​worktree-safety.sh Adds coverage for squash-merged/suffixed/undelivered trees and for removing a clean, landed tree containing an initialised submodule.
docs/​agent-workflow.md Rewrites the pruner paragraph to describe the bead-name delivery check and direct submodule-tree removal.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread scripts/worktree-safety.sh Outdated
Comment on lines +36 to +37
# less the one `assign-bead' adds when a name is taken (`<bead>-2'). Candidates rather than one
# answer, because a bead id ends in `-<word>' itself (`cb-7suc', `sq-1') and stripping blindly

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right: the directory is always the bead, the suffix goes on the branch. The numeric case is dropped; the candidates are the name as it stands, less -mockup, or less -retro (the verifier's retrospective tree). The test now asserts sq-1 yields only itself.

rmstdope and others added 2 commits September 28, 2026 00:29
…submodule source has an identity

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GKiLr59caM9f6DxkrsDYR8
…ner's default

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GKiLr59caM9f6DxkrsDYR8
@rmstdope
rmstdope merged commit 8083518 into main Sep 27, 2026
3 checks passed
@rmstdope
rmstdope deleted the cb-7suc-prune branch September 27, 2026 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants