Repository navigation
Remove a Worktree Holding a Saved Submodule in Cleanup - #4593
Conversation
`cleanup` kept every worktree git refuses for a submodule, so a drive in a repository with an initialized submodule ended at the maintainer. It now proves each submodule repository under the worktree's `modules` clean, untracked files included, stash-free, and contained in its own remote after a fetch. Only then does it delete the submodule links and `modules` and run the plain `worktree remove`. Otherwise it keeps the worktree, naming the submodule and the commit no remote contains. Closes #4583 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… Them The local review found two ways the proof passed while a commit was lost: a repository embedded inside a submodule's tree, and a commit only a local tag reached. The proof now checks every gitlink at each depth and every ref but the tags a remote also holds. The re-check after the remote delete reads the refs the first proof fetched, and the shared reads live in pr_cleanup_tree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The second local review found false refusals and a missed one. A submodule pinned at a release tag on no remote branch refused, and a branch that removed a submodule failed every run on its dangling core.worktree. An operation paused in a submodule passed. The proof now counts a remote-held tag as the remote's, reads each repository with its work tree overridden, refuses a paused operation, and proves every commit before any tree, so a nested commit names its own submodule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
A recorded local strict-review pass covers head |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 49 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
🟡 Changes recommended
Multiple unresolved safety flaws could let cleanup delete unverified work, including local-only tags, reflog-only commits, sequencer state, linked-worktree commits, or shallow-history commits.
11 open issues
Preserve remote-held tags during the re-check · New Inspect linked worktrees before clearing submodules · New Preserve local-only tags before fetching · New Detect sequencer operations before clearing submodules · New Exclude local-only tags by their full ref names · New Treat sequencer directories as in-progress operations · New Handle shallow history before asserting containment · New Include reflog-only commits in the loss check · New Make sweep recovery apply the submodule proof · New Report the actual nested submodule worktree path · New Share the read-only unlink helper · New
What changed in this PR
This pull request extends cleanup to remove worktrees containing initialized submodules after proving their contents can be safely discarded. It adds recursive repository checks, integrates verified submodule removal into cleanup, expands repository-backed tests, and updates documentation and generated skills.
Changes:
- Adds submodule safety proofs for repository state, recoverability, nested repositories, and paused operations.
- Integrates submodule validation and clearing into worktree cleanup while sharing tree-state helpers.
- Adds test coverage, updates script size limits, and synchronizes cleanup guidance across skill distributions.
| File | Description |
|---|---|
| tests/test_pr_review_size.py | Adds the new submodule cleanup module to the script size limits. |
| tests/test_pr_cleanup.py | Removes cleanup tests superseded by the dedicated submodule test suite. |
| tests/test_pr_cleanup_modules.py | Adds throwaway-repository tests for safe and refused submodule cleanup cases. |
| scripts/README.md | Documents the expanded cleanup contract and submodule removal behavior. |
| scripts/pr_cleanup.py | Integrates submodule validation and clearing into pull-request worktree cleanup. |
| scripts/pr_cleanup_tree.py | Centralizes shared cleanup status, gitlink, and operation-state helpers. |
| scripts/pr_cleanup_modules.py | Implements recursive submodule discovery, safety proofs, refusal reporting, and cleanup. |
| .github/skills/repo-worktree/SKILL.md | Updates the GitHub worktree cleanup skill with the new submodule behavior and recovery guidance. |
| .claude-plugin/fleet-skills/skills/repo-worktree/SKILL.md | Updates the Claude fleet worktree cleanup skill with the new submodule behavior and recovery guidance. |
| .claude-plugin/fleet-skills/.source-digests/repo-worktree | Refreshes the generated source digest for the repository worktree skill. |
| .agents/skills/repo-worktree/SKILL.md | Updates the canonical worktree cleanup skill with submodule removal and recovery guidance. |
Review effort: Lite
The third local pass found more ways the proof missed a submodule's own work. It now reads the commits a submodule holds before its fetch can prune a tag, and fetches with tag pruning off. It counts each HEAD reflog entry, refuses a pending sequencer and a submodule's own linked worktree, and names a shallow submodule it cannot prove. A refusal names the submodule by its path in the tree, and the commit proof moves to pr_cleanup_reach.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #4593 +/- ##
===========================================
+ Coverage 79.16% 79.32% +0.15%
===========================================
Files 52 55 +3
Lines 17234 17572 +338
===========================================
+ Hits 13644 13939 +295
- Misses 3590 3633 +43
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The fourth local pass found the proof failing on git before 2.42, which takes no rev-list options on standard input, and on a signed reflog read through git log. A tag refspec could still prune a local tag. A refusal now names the branch, tag, or reflog that reaches the commit, the fetch names each remote's branches itself, and a parent tree no longer reports a nested submodule's change as its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fifth local pass found the proof's fetch recursing into a nested submodule before that submodule's snapshot, so a tag refspec there could delete the only name for a commit. The fetch now leaves nested submodules to their own turn. A staged gitlink in a submodule's index now counts as a change, and the skill says what to do with a merged upstream branch and a commit only the reflog reaches. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
A recorded local strict-review pass covers head |
…a Commit The sixth local pass found a deinitialized submodule named by a path where git reaches the superproject, a note or replacement ref reported as HEAD, and no route for a submodule remote under another owner. A treeless submodule's refusal now names its git directory, the refusal names any non-remote ref, and the skill keeps pushes to this repository's owner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The seventh local pass found files in a deinitialized submodule's path that no status lists, so the removal deleted them unnamed, and the same held for a submodule never initialized. Such a path now keeps the worktree. A shallow submodule fetches only branch tips, so its proof no longer downloads its history, and a worktree and a submodule share one status read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
A recorded local strict-review pass covers head |
…hallow Pin The eighth local pass found a worktree whose tree was deleted by hand skipping the proof, so its git directory's submodule repositories were deleted unproved, by cleanup and by the sweep's prune alike. Such a worktree now refuses, and the sweep prunes nothing while one such entry is due. A shallow submodule fetches only the branches it tracks, so its pin stays connected once upstream moves, and the gitlink and paused-operation reads are shared. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ninth local pass found an annotated tag on a pushed commit deleted with its message, and one orphaned worktree entry blocking every other prune. A tag no remote holds now keeps the worktree. The sweep keeps the orphaned entry and removes the others one at a time, and the README no longer gives the sweep the clearing step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
A recorded local strict-review pass covers head |
Ten local passes kept finding edge cases in the ways the proof tried to avoid refusing, so it now refuses them outright. A shallow submodule refuses, the skill sends every refusal but this task's own pushable work to the maintainer, and a refusal for a missing tree names its modules directory. The sweep removes each prunable entry on its own, so it never prunes an entry it did not judge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…odules The Windows unit job failed on refusal paths that mixed git's forward slashes with the native separator, so each path is now read through realpath or normpath. The sweep again uses git worktree prune unless a prunable entry holds submodule repositories, since per-entry removal refused an entry whose .git file was gone. The recovery test now follows the skill on a branch commit the task may push. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s Singly The twelfth local pass found an embedded repository's refusal mixing path separators on Windows, and the README saying the sweep always removes prunable entries one at a time. Gitlink entry paths are now normalized, and the README limits the one-at-a-time removal to a run that keeps an entry for its submodule repositories. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
A recorded local strict-review pass covers head |
…ng Repository The thirteenth local pass found a worktree directory left without its .git file resolving to the repository around it, so cleanup proved and cleared the primary clone's own submodule repositories. A prunable entry now skips the proof and the clearing, and a held sweep keeps such an entry rather than failing to remove it. The unneeded pruneTags overrides and their two tests are gone, and the skill names a new branch as the only push target. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fourteenth local pass found a prunable worktree whose directory outlived its .git file passing preflight, so the remote branch went before git refused to remove it. It now refuses first. The clear deletes modules before the submodule links, so an interrupted clear reruns to completion, and the skill sends a branch commit to the maintainer, since it is often one a squash merge already landed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
A recorded local strict-review pass covers head |
… Husks The fifteenth local pass found the clear docstring promising a rerun that cannot read half-deleted repositories, and a held sweep predicting a removal git refuses. A failed clear now names the hand step, a held sweep keeps an entry whose directory outlived its .git file, and the note-ref test uses refs/notes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The sixteenth local pass found the hand step a failed clear prints leaving a submodule's files with no repository beside them, so the rerun refused for good. The hand step now removes the worktree itself before cleanup runs again, a test follows it literally, and the sweep text names the entry a held run keeps for a missing .git file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
A recorded local strict-review pass covers head |
The seventeenth local pass found the hand step's git worktree remove and the skill's git submodule update naming no directory, so each fails from where it is literally run. Both now name it with -C, and the interrupted-clear test runs the printed command as given, deleting with the read-only handler Windows needs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The eighteenth local pass found the printed git worktree remove splitting at a space in a path, as a Windows profile or a macOS home can hold. Both paths are now quoted, and the test checks the quoted form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
A recorded local strict-review pass covers head |
… Step The nineteenth local pass found a submodule update that leaves a rebase or merge submodule on its branch, a hand step no one was told to run, the README stating the clear order backwards, and a held sweep dropping git's reason. The skill now updates with --checkout and sends the hand step to the maintainer, and the held sweep prints git's reason. The clearing moves to pr_cleanup_clear.py and the reads to pr_cleanup_modules.py, so every file stays under its ceiling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The twentieth local pass found a .DS_Store that Finder writes into an uninitialized submodule's empty directory refusing an ordinary macOS worktree. Such file-manager metadata is no longer work. The prunable-entry refusal no longer says a surviving tree is gone, the module docstring drops the clearing that moved out, and the skill routes another owner's submodule work to the maintainer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
A recorded local strict-review pass covers head |
…ranch The twenty-first local pass found the skill telling an agent to stop on any nonzero cleanup exit while letting it clear one, claiming every refusal names a commit, and leaving the task's pushed submodule branch unreported. The exception is now named where the stop rule sits, the refusal text matches what cleanup prints, and the pushed branch goes to the maintainer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
A recorded local strict-review pass covers head |
|
@coderabbitai review |
|
/review |
Action not completed
|
…Hook-Path Denials (#4594) ## Promoted pull requests - #4590: Read the attention lists under a fine-grained token. The full check read still runs first. A token refused `contexts` or `checkSuites` gets a lean read of the same page and every later one. That read names failing pull requests from the head's Actions runs and the jobs of each run's listed attempt, and it records what went unread. - #4592: Deny a commit or push whose text sets GIT_CONFIG*, HOME, or XDG_CONFIG_HOME (each can change which hooks run), and read unquoted bash brace expansion in the guard's lexer so brace-expanded blanket adds and `commit -a` are refused under requirements 6 and 11. - #4596: Expand stepped alphabetic and signed brace ranges in the write guard, as bash does, so `git commit -{A..z..+32} x` is refused as the blanket commit it runs (fixes a Copilot finding raised on this promotion against #4592). - #4597: Show every write-guard denial in the decision-flow diagram, the brace cap and requirement 11 included, and split one self-test table through `_rows` (fixes this promotion's local review findings against #4592). - #4593: Let `cleanup` remove a worktree holding a populated submodule once a strict proof shows nothing is lost: every submodule repository clean, untracked files included, no stash, paused operation, linked worktree or shallow history, and every commit and tag its refs and HEAD reflog reach held by its own remote after a fetch. Anything it cannot show refuses and routes to the maintainer. The clearing lives in scripts/pr_cleanup_clear.py. - #4599: Answer the second local review of this promotion. The guard's docs state its fail-closed behavior without a closed list, one set of state-changing builtins serves both guard sites, and the attention read tolerates a check suite's unread `workflowRun` as the review gate does, marking only the pull request it names. ## Promotion review findings Copilot raised one finding on head ed0326f, that the lean retry could hide an unrelated null node. It was declined in its thread with the code path: the lean re-read tolerates nothing, so a null that persists still fails the read and exits 1. Copilot raised three findings on head 9acbb87, all against #4592: - Stepped alphabetic brace ranges were left literal. This was real, and #4596 fixed it (`6797d691`). The fix also reads a leading `+` sign as bash does. Copilot's own example, `-{a..z..2}`, was already denied, since its literal word carries an `a`, so the regression rows use cases that `develop` really allowed. - An empty brace word must be kept. Declined, because bash drops the empty word: `printf "[%s]" {,--all}` prints `[--all]`. - The zero-padded self-test fixture was wrong. Declined, because the fixture creates the directory `01` and the self-test passes. Copilot's round on head 6797d69 opened on a verdict naming no defect: that synthetic tests cannot establish live behavior. It was answered with the live evidence and acknowledged as declined. A local `frontier` pass against `main` at head 6797d69 raised two findings against #4592, and #4597 fixed both (`9a5af3f9`). The decision-flow diagram lacked the brace-cap denial, and requirement 11 as well, as #4597's own review found. One self-test table was split by hand rather than through `_rows`. A second local `frontier` pass against `main` at head 9a5af3f raised four findings, and #4599 fixed them (`e60890ad`). They were the brace cap missing from the guard's fail-closed docs, a phrase with no referent, two drifted lists of state-changing builtins, and a refused `workflowRun` failing the attention read. Closes #4584 Closes #4582 Closes #4514 Closes #4583 🤖 Generated with [Claude Code](https://claude.com/claude-code)



Summary
cleanupused to keep every worktree that git's ownworktree removerefuses for holding a submodule. So a drive in a repository with an initialized submodule ended atnext=maintainer.cleanupnow removes such a worktree once it proves nothing in it is lost. The proof covers every submodule repository under the worktree'smodules, nested ones included. It refuses outright whatever it cannot show cheaply, the maintainer's choice of a strict design.scripts/pr_cleanup_reach.pyproves a repository's commits and state:sequencerincluded), a linked worktree of its own, a shallow repository, and any tag no remote holds.HEAD, and itsHEADreflog.scripts/pr_cleanup_modules.pychecks each populated tree, andscripts/pr_cleanup_clear.pyclears it. It must be clean, untracked files included, with no embedded repository and no untracked gitlink files at any depth. It then deletes the submodule links andmodules, naming the git-ignored entries it loses, and runs the plainworktree remove.modulesrefuses. The sweep keeps such an entry and removes the other prunable entries one at a time while it does.pr_cleanup.pystays under its size ceiling. The shared reads moved intopr_cleanup_tree.py.scripts/README.mdand therepo-worktreeskill describe the rule. The skill hands the task only its own pushable work and sends every other refusal to the maintainer.Closes #4583
Testing
tests/test_pr_cleanup_modules.pyholds 38 cases on throwaway repositories, covering both outcomes. One case follows the skill's recovery steps literally through to a removal.Local review
Twenty-two local passes ran. The twenty-second, over the head, found nothing, so no local finding is open.
Earlier local findings and their outcomes
The third pass's eight findings, listed on the first push:
fetch.pruneTags;sequencer;unlink_read_onlyconsolidation, declined.local_review.py's handler swallows a failure and letsrmtreego on deleting the rest of a throwaway directory, inside afinallythat must not replace the read's result. This one must stop the removal at the first failure. Wrapping a raising handler in a suppress would stoprmtreeat the first error, so the two contracts do not share one body.docker_lint.py's copy has to stay standalone.The tenth pass's findings are answered in a95ac1e, the maintainer's strict redesign: the proof refuses outright what it cannot show cheaply. That covers a shallow submodule, a moved tag, and a reflog-only commit, and the skill routes each to the maintainer. The prune race is closed, and the dead tag strip is gone. The eleventh pass's findings are fixed in 1b0461e: Windows path separators, the sweep's prune for a
.git-less entry, the recovery test, the README pronoun, and the reflog docstring. The twelfth pass's findings are fixed in 797a3fe. The thirteenth pass's findings are fixed in 19ea787. That covers a prunable entry resolving to an enclosing repository, the held sweep, the unneededpruneTagsoverrides and their tests, the README tag sentence, and the skill's push target. The fourteenth pass's findings are fixed in 43cc019. A surviving worktree directory refuses before the remote delete,cleardeletesmodulesbefore the links, and a branch commit goes to the maintainer. The over-hardened sweep keep is gone. The fifteenth pass's findings are fixed in e16bfb6, and its reflog question is answered: the maintainer keeps the strict reflog rule, accepting that a squash-merged submodule commit refuses for git's reflog window. The sixteenth pass's findings are fixed in 72c812c. The seventeenth pass's findings are fixed in de0acf0, and the eighteenth pass's in a4a121e. The nineteenth pass's findings are fixed in 76b0262, which also splits the clearing intopr_cleanup_clear.pyso every file stays under its ceiling. The twentieth pass's findings are fixed in 487e94f, and the twenty-first pass's in b912bf2.The eighth pass's findings are fixed in e2718cc: a prunable worktree's submodule repositories, a moved shallow pin, and the shared gitlink and paused-operation reads. Its
unlink_read_onlyevidence,docker_lint.py's copy, is now named in that handler's docstring, and the decline stands. The ninth pass's findings are fixed in f32fc25: an unpushed tag on a pushed commit, the sweep held by one orphaned entry, and the README's sweep pronoun.The sixth pass's findings are fixed in 4f417f6: a treeless submodule's git directory, any ref that reaches a commit, and a remote under another owner. Its
unlink_read_onlyconsolidation stays declined, as above. The seventh pass's findings are fixed in 0cdd09b: files in a gitlink path no repository tracks, a shallow submodule's history download, the README contradiction, and the shared status read.The fourth and fifth passes' findings are fixed in e03dd7a and 843fea1. Those cover git before 2.42,
log.showSignature, a tag refspec, the refusal naming what reaches the commit, the sweep route, a nested submodule's label, a recursive fetch, a staged gitlink, and a merged upstream branch.🤖 Generated with Claude Code