Repository navigation
Add gh pr-review gc, the --doctor paths and one section on where reviews run - #18
Conversation
…tate folder, config file and clone roots
catalan-adobe
left a comment
There was a problem hiding this comment.
Approach
What it does: Adds gh pr-review gc to remove review worktrees and private refs for merged or closed PRs. --dry-run previews cleanup; local review history stays unless --purge is passed. --doctor and the README now show where those files live.
Fit with the repo: docs/superpowers/plans/2026-11-26-review-tracking-pr3-local-worktrees.md names lib/gc.sh, and gh-pr-review already dispatches gc to cmd_gc. Cleanup reuses the two existing locks and the worktree ownership checks. It adds no GC branch to the review flow.
Strongest case for the approach as built: The PR says “gc never runs git worktree prune.” That departure from the original plan is justified: #16’s lib/worktree.sh deliberately preserves unrelated worktree registrations when a volume is offline. Removing only the recorded review worktree honors the same promise.
Alternatives: Keep pr.json as the cleanup inventory. It names only the last clone used for a PR, but requires no new bookkeeping. If cleanup must also find artifacts in previously used clones, I’d record each clone used rather than scan for deletion candidates.
Questions for the author: None.
Missing context: The planned live review and timings are deferred; neither is needed to judge where cleanup belongs.
Approach: Sound
Strengths
- [tests/gc.sh:260] — The tests check the promise that matters to a clone owner: unrelated branches, worktrees, stash and config survive cleanup. The separate assertion that an offline worktree stays registered is especially valuable.
- [lib/gc.sh:112] — Deleting refs in one transaction with their observed object IDs avoids partially deleting a PR’s pins if a ref changes concurrently. That transaction is worth keeping.
- [lib/clones.sh:236] — Sharing
clone_rootsbetween lookup and--doctorkeeps the diagnostic accurate without scanning the filesystem.
Issues
🚨 Critical (Must Fix Before Merge)
-
[lib/gc.sh:220] —
--purgerecursively deletes user files that merely resemble run artifacts.round-notes.md,pr.json.backup, and even a user directory namedloop-check.mdall reachrm -rf. None is a run folder produced bylib/state.sh.- Match the writer’s actual names and types: numbered round directories, timestamped run/preview directories with their optional collision suffix, and known metadata files. Preserve ambiguous entries rather than recursively deleting them.
-
[lib/gc.sh:118] — The ref transaction can delete a branch outside the PR namespace. If a ref under
refs/pr-review/<key>/is symbolic and points to a local branch,%(objectname)supplies the target’s object ID andupdate-refdereferences the symbolic ref by default. The old-value check therefore does not protect the branch.- Use no-dereference semantics for every delete, or refuse symbolic refs without changing their targets. Add a real-Git assertion that the target branch survives.
-
[lib/gc.sh:83] — The worktree check protects only the state root of the current
gcinvocation. A second review can run--freshwithGH_PR_REVIEW_STATE=./statefrom inside the first review’s worktree. When the first PR closes,gcusing the default state root can force-remove that worktree, including the second review’s history, checkout and lock.- Make nested state recognizable independently of the caller’s environment and refuse removal when found. Cover two distinct state roots and PRs; neither lock for the first PR protects the second one.
⚠️ Important (Should Fix)
-
[lib/gc.sh:302] — With
--purge, a four-component directory name is enough to select a PR even withoutpr.jsonor any evidence of a review. With the supportedGH_PR_REVIEW_STATE=., an unrelated emptygithub.com/org/repo/7/is removed, along with empty parents, if GitHub says PR 7 is closed.- Keep support for
--freshhistory, but require a recognizable run artifact before treating a directory withoutpr.jsonas tool-owned. Validate the candidate’s path before taking its lock, not only later ingc_purge.
- Keep support for
-
[lib/gc.sh:64] — The missing-worktree path can report successful cleanup without checking the recorded registration. For example, if a branch directory was replaced by a symlink and the leaf is absent, the resolved path can fail
gc_shape; the function returns success, leaving the old registration in Git and allowing--purgeto erase the inventory. When the shape does match, this path skips the parentreviews_checkthat the existing-worktree path performs.- Distinguish “confirmed absent and unregistered” from “cannot safely resolve the recorded path.” Report the latter as left, keep
pr.json, and apply the parent-path checks before removing a registration or tidying its ancestors.
- Distinguish “confirmed absent and unregistered” from “cannot safely resolve the recorded path.” Report the latter as left, keep
-
[lib/gc.sh:415] — The discovery glob skips dot-prefixed repositories, including the explicitly supported
.githubrepo. I checked a temporary state tree containinggithub.com/org/.github/7/pr.json:gc --dry-runreported “No PRs.” Its worktree, pins and history would never be collected.- Include hidden path components during enumeration while retaining PR-key validation. Add
.githubto the GC fixture.
- Include hidden path components during enumeration while retaining PR-key validation. Add
-
[lib/gc.sh:233] — Every failed
rmdiris reported as “holds other files,” even when the directory is empty. If the PR directory is writable but its parent is read-only, purge can delete all its contents, fail to remove the empty directory, and exit 0 withholds other files ().gc_tidysimilarly discards removal errors at lines 133–142.- Treat confirmed nonempty directories as expected; report other removal failures and return 1. Delete
pr.jsonafter the run artifacts so an earlier removal failure preserves the clone and account needed for a retry.
- Treat confirmed nonempty directories as expected; report other removal failures and return 1. Delete
-
[lib/gc.sh:216] —
--dry-run --purgereports that it would remove the state folder without inspecting what would remain. In a temporary fixture it said this both for a PR containingnotes.txtand for one whoselock/contained a non-PID file. The real run keeps the directory in the first case and refuses the lock before cleanup in the second.- Share read-only candidate selection and lock validation between preview and execution. The preview need not predict races, but it should describe the outcome for an unchanged filesystem.
💡 Minor (Nice to Have)
- [gh-pr-review:412] —
--doctorchecks directory write permission but not search permission. A mode-0600state directory was reported without a warning, although the process cannot create a PR directory inside it. Check-xas well as-won the existing directory or nearest existing parent.
Recommendations
Keep the real-Git fixtures and add paired preview/execution cases: for the same initial state, assert what survives, what remains retryable, and the exit code. Sharing the ownership checks between those two paths would address several of the discrepancies above without adding a GC branch to the review flow.
Assessment
Ready to merge? No
Reasoning: The transaction and targeted worktree removal are sound choices, but the current deletion rules can cross the advertised boundary into user files, branch refs and another review’s state. Those are merge blockers for a cleanup command.
Review generated by gh pr-review · model: azure-openai-direct/gpt-6.2-astra
… such as round-notes.md stay
…eted itself, never the branch it points at
…w worktree that holds a state folder or a live lock
…a run folder in it or the state folder's marker, its path checked before its lock
…hen its recorded path still resolves where the run puts it, its folders checked
…g files as a failure, and deletes pr.json last
…cluded, so it prints the lines and exit code gc then gives
…t is writable but not searchable
|
Thanks for round 1. All nine items are fixed, one commit each, each with tests that failed on the code before its fix (controls that pass on both are labelled). The recommendation is in too: paired preview/execution cases check that, from the same starting files, the Critical
Important
Minor
Results on
|
catalan-adobe
left a comment
There was a problem hiding this comment.
Round 2 · since round 1
5 fixed · 4 still open · 5 new (3 in the new commits) · open blocking: 7 (was 8) · loop: early
Approach
What it does: Adds gh pr-review gc to remove closed PRs’ review worktrees and private refs. History stays unless --purge is passed.
Fit with the repo: The command still belongs in lib/gc.sh, as docs/superpowers/plans/2026-11-26-review-tracking-pr3-local-worktrees.md specifies. Two decisions since round 1 change my verdict. First, gc_lock_check now predicts refusal and takeover rules owned by lib/state.sh; gc_clone_lock also repeats path checks from lib/worktree.sh. A lock-policy change now needs two implementations to keep preview accurate. Second, gc_runs_left accepts a PR-shaped directory when “its state root has the marker.” With GH_PR_REVIEW_STATE=., one review proves the root contains review state, not that every matching directory under it belongs to the tool.
Strongest case for the approach as built: Preview takes no locks, and the root marker lets GC protect another review’s nested state before removing a worktree. Both are worth keeping.
Alternatives: Share read-only lock checks with the lock implementations, leaving atomic acquisition and rechecks there. That costs a contained refactor. Keep the root marker as a reason not to delete, but require per-PR evidence to purge. That leaves ambiguous empty directories behind; if collecting them matters, mark each PR directory when it is created.
Questions for the author: None. Those two changes would restore my round-1 verdict.
Missing context: None for this decision.
Approach: Questionable
Strengths
- [lib/gc.sh:246] — The ref transaction now uses
--no-derefand retains the old-object checks.tests/gc.sh:419verifies the important outcome: the symbolic ref is gone, but the user’s branch still points to the same commit. - [lib/gc.sh:179] — For a missing worktree, GC checks both the recorded and resolved paths against Git’s registrations. The tests at
tests/gc.sh:520verify that an unsafe registration and thepr.jsonneeded to retry both survive. - [tests/gc.sh:609] — Comparing preview and execution from the same starting state, including exit status, is a useful regression test for a destructive command.
Issues
🚨 Critical (Must Fix Before Merge)
-
F1 · [lib/gc.sh:357] — Purge still selects user backups and directories the writer cannot produce.
loop-check.md.backupmatches the six-character temporary-file suffix.run-20260101T000000-1also matches, althoughrun_dir_newstarts collision suffixes at-2. I checked both withgc_artifact; it accepted both. The latter is then deleted recursively.- Preserve ambiguous legacy temp files, give new temp files a tool-specific naming convention, and restrict collision suffixes to the writer’s actual format. Add both names to the preservation test.
-
F3 · [lib/gc.sh:126] — The marker protects the tested nested state root, but the fallback still misses real review state. A stopped
--checkcan leave onlyloop-check.md(gh-pr-review:528); a root created before the marker has no other evidence. I checked thatgc_state_inreports no state for that layout. There is also a current path to losing full rounds: if another state root’s repo directory points into the worktree, its root marker is outside, and its completed PR history can be shallower than the four levels required atlib/gc.sh:150.- Mark the physical per-PR directory as well as the root, and recognize the legacy loop-check-only layout before force-removing a worktree.
-
[lib/gc.sh:474] — Purging a
--freshrun bypasses the nested-state check entirely. A second PR can useGH_PR_REVIEW_STATE=./statefrom the first PR’s archivedpreview-…/repo. Purging the closed first PR recursively removes the second PR’s marked state, history and even a live lock. Round 1 examined the linked-worktree deletion path; the--freshcheckout is deleted by this separatermpath.- Check all candidate run directories for nested state before deleting the first artifact. On a match, report the path and retain the inventory for retry.
-
[lib/gc.sh:222] — A different Git worktree nested inside the review worktree is not protected. For example, a developer can have a linked dependency checkout with uncommitted work under the review checkout. The outer worktree passes
owned_worktree, and the new scan looks for review state, not nested checkouts. Force-removing the outer directory removes the inner files while leaving their registration behind. Round 1 checked sibling and offline worktrees, not descendants.- Refuse removal when the target contains another worktree; exclude the target’s own
.gitentry from that check. Test that both the nested checkout’s dirty file and its registration survive.
- Refuse removal when the target contains another worktree; exclude the target’s own
⚠️ Important (Should Fix)
-
F4 · [lib/gc.sh:385] — A root marker still authorizes purging an unrelated PR-shaped directory. With
GH_PR_REVIEW_STATE=., one genuine review marks the shared root. A siblinggithub.com/org/repo/7with no review evidence then qualifies: GC can remove it and its empty parents, or delete a user’sloop-check.mdthere.tests/gc.sh:500currently expects the empty sibling to be deleted.- Require evidence in the candidate PR directory. Keep the root marker as a reason to protect a tree, not permission to purge its descendants. Reverse the marked-sibling test and assert that no GitHub lookup occurs.
-
F8 · [lib/gc.sh:55] — Preview still approves locks execution cannot take on an unchanged filesystem. I checked an empty mode-
0500PR lock:gc_lock_checkaccepts it because the listing is empty, butlock_claimcannot createpid. The clone equivalent atlib/gc.sh:301skips the creation check altogether when the lock is absent, including when its nearest existing parent is read-only.- Share a read-only lock feasibility check with acquisition and cover both cases in the paired test. Neither discrepancy requires predicting a race or a Git failure.
-
[lib/gc.sh:634] — Discovery treats an unreadable directory as an empty one. With a real
h/o/r/7/pr.jsonbelow a non-listabler/,gc --dry-runprintedNo PRsand exited 0. A batch can therefore report success while omitting an entire repository.- Distinguish a missing state root from a directory that cannot be enumerated. Name the unreadable path, continue with readable siblings, and retain exit 1 even when the number of discovered PRs is zero.
💡 Minor (Nice to Have)
- [lib/gc.sh:274] — A nonempty worktree ancestor now returns from all of
gc_tidy, rather than just ending that ancestor walk. If an open PR remains in the same repo, GC can leave the closed PR’s empty.lockshierarchy behind. End the worktree walk withbreak, then tidy the independent lock path. - [lib/gc.sh:139] — Any regular file named
pidcontaining a live PID is reported as a held lock. A tracked test fixture containing1is enough to prevent cleanup, despite no process holding a lock there. Check a recognizable lock layout and bound the amount read from a candidate PID file.
Fixed since the last round (5)
- F2 — Ref deletion no longer dereferences a symbolic ref into a user branch.
- F5 — A registered missing worktree behind a changed symlink or
.gitancestor is refused, withpr.jsonretained. - F6 — Discovery includes dot-prefixed repositories, with
.githubcovered through preview, cleanup and purge. - F7 — Unexpected
rmdirfailures are reported, and an earlier artifact-removal failure preservespr.json. - F9 —
--doctorchecks search as well as write permission on the state directory or nearest existing parent.
Recommendations
Use the existing paired-test pattern to check what survives, not just whether preview and execution agree. In particular, put one unrelated directory beside a real PR under a marked root, and one independently owned checkout or state root inside each kind of recursive deletion target.
Assessment
Ready to merge? No
Reasoning: The ref and missing-registration fixes protect the clone in the cases they target. The remaining deletion paths can still erase user backups, another PR’s history, or uncommitted files in another worktree; a successful dry run does not rule those out.
Review generated by gh pr-review · model: azure-openai-direct/gpt-6.2-astra
… remove without --force, and keeps the PR's refs when it leaves the worktree
…d gc --purge removes a PR's folder only with evidence in it: that marker, pr.json or a run folder, never the state folder's marker
….json.tmp.<pid>, .loop-check.md.tmp.XXXXXX), and gc --purge deletes only those and the run folders' exact suffixes; earlier versions' temporary files stay, named
…anything in a PR's folder: a --fresh checkout must be clean, and no other checkout or state folder may be in one
…cide what a lock is and what lock_take would do, lock_take decides by lock_state, and gc --dry-run uses lock_check and clone_lock_check (lib/worktree.sh) instead of repeating them
…he others, and exits 1, even when it found no PR; a state folder that is not there still holds no PR
… ends that walk only, and the PR's emptied .locks folders are still removed
|
Thanks for round 2. Your two design points are adopted as you proposed them. Most of the remaining findings had one shape: something that isn't the tool's sits inside a folder gc deletes recursively. So this round closes that class instead of the listed cases. gc now deletes only what it can prove is the tool's and clean, and leaves the rest with the command to remove it by hand. Seven commits, Approach
Critical
Important
Minor
Recommendation: in. The paired tests now also check what survives. They cover an unrelated folder beside a real PR under a marked root, and an independently owned checkout and state root inside each kind of recursive deletion target (the review worktree, and a Checks on
|
catalan-adobe
left a comment
There was a problem hiding this comment.
Round 3 · since round 2
6 fixed · 3 still open · 4 new (4 in the new commits) · open blocking: 6 (was 7) · loop: churning
Next: Split the PR: each part converges on its own
Approach
What it does: Adds gh pr-review gc to remove merged or closed PRs’ review worktrees and private refs. Local history stays unless --purge is passed.
Fit with the repo: lib/gc.sh is where docs/superpowers/plans/2026-11-26-review-tracking-pr3-local-worktrees.md puts this command. Both round-2 concerns are resolved: preview and acquisition share lock_state in lib/state.sh and clone_lock_path in lib/worktree.sh. Purge now requires evidence inside the PR directory; a marked state root no longer authorizes deleting a sibling.
Strongest case for the approach as built: As the author says, “a closed PR’s worktree with build output in it is now left for you, not deleted.” Checking ignored files and removing without --force makes that trade-off explicit. The refs and pr.json stay so cleanup can be retried.
Alternatives: Requiring .gh-pr-review-pr for every purge would leave older runs for manual cleanup. I’d choose that stricter rule if existing run names proved ambiguous in practice.
Questions for the author: None.
Missing context: None for this decision.
Approach: Sound
Strengths
- [lib/gc.sh:265] — When GC leaves a worktree, it now keeps the PR’s refs as well as
pr.json. That makes the failure retryable without losing the round pins. - [tests/gc.sh:555] — The marked-root test checks three outcomes for an unrelated sibling: no GitHub lookup, no cleanup report, and the directory still exists. That directly verifies the ownership boundary from round 2.
- [tests/gc.sh:802] — The unreadable-directory test verifies that GC names the failure, continues with a readable sibling, and returns a nonzero batch result.
Issues
🚨 Critical (Must Fix Before Merge)
-
F10 · [lib/gc.sh:313] — Purge still misses another PR’s state inside a
--freshcheckout’s.gitdirectory. For example, a second review can useGH_PR_REVIEW_STATE=.git/review-stateto keep its history out of the working tree.git statuscannot see that history, and the newfindexplicitly prunes./repo/.git. Purging the outer PR can therefore delete the second review’s history and live lock.- Check for state markers and legacy state below the Git directory too, before removing any artifact. The Git directory itself is expected; an independent review state root inside it is not.
-
F11 · [lib/gc.sh:138] — A nested checkout is not always visible in the outer worktree’s status. If a developer checks out a vendored dependency over the same files the PR already tracks, the only additional entry can be
vendor/.git. I checked the status command against an unchanged tracked directory containing an extra.gitentry: it produced zero bytes. Removing the outer worktree can then erase a nested clone’s unpublished history or leave a linked checkout registered at a path that no longer exists.- Check for descendant
.gitentries independently of status, excluding only the review worktree’s own.git. The--freshpath already makes this distinction.
- Check for descendant
-
[lib/gc.sh:302] — The
repo/exception accepts an unrelated clone as the run’s disposable checkout. A local-worktree review never creates<run>/repo, but if a developer later puts a clean clone there, GC accepts it without checking even the PR’s private refs. Purge then deletes the entire clone, including any local-only branches and stash. The success fixture attests/gc.sh:578actually uses an ordinarygit clone, notfresh_checkout. Conversely, a nonemptyrepo/whose.gitis missing falls through without a cleanliness check at all.- Establish that a nonempty
repo/belongs to this run before deleting it. Record ownership for new fresh checkouts, use the expected PR refs where they provide evidence for older ones, and leave ambiguous directories for manual cleanup. Usefresh_checkoutfor the positive test.
- Establish that a nonempty
-
[lib/gc.sh:78] —
gc_statuscan miss a changed tracked file marked assume-unchanged in the index. Git deliberately omits the content check for that file;--ignoredand--untracked-files=alldo not override the bit. A local edit can therefore pass the new cleanliness test and be deleted. The same helper guards both review worktrees and archived checkouts.- Refuse automatic removal when index flags hide changes, or verify those entries independently without modifying the real index. Add a preservation test for an edited, assume-unchanged file.
⚠️ Important (Should Fix)
-
F8 · [lib/state.sh:198] — Preview now handles an empty read-only lock, but still approves takeover of a stale read-only lock. With a writable parent and a mode-
0500lock directory containing only a dead PID, I observedlock_checkreturn 0 andlock_takereturn 1: the parent permits removing the directory, but the lock directory does not permit unlinkingpid.- Check permission to remove the PID file as well as the lock directory, and add this case to the paired probe/acquisition tests.
-
[lib/gc.sh:349] — GC writes the PR key into
.gh-pr-review-prbut never checks it. If a--freshstate directory for open PR 8 is moved or restored under closed PR 7, its marker still says…/8. GC asks about PR 7 and purges PR 8’s history despite that explicit contradiction.- When a marker exists, compare its contents with the candidate key before cleanup. Refuse a mismatch and name both keys; the existing fallback can still serve legacy directories without markers.
💡 Minor (Nice to Have)
- [lib/worktree.sh:300] —
${lock%/.locks/*}strips the shortest matching suffix. For the valid repo name.locks, a lock atr.reviews/.locks/h/o/.locks/1yieldsr.reviews/.locks/h/oas the directory to chmod, notr.reviews. An existing.reviewscan retain its old permissions. Strip the known/.locks/<pr-key>suffix literally instead.
Fixed since the last round (6)
- F1 — Purge preserves the ambiguous legacy temp names and rejects collision suffixes the writer does not use, including
-1and-02. - F3 — In the reported worktree layouts, nested review files are now detected as untracked or ignored regardless of directory depth or the location of the state-root marker.
- F4 — A marked state root no longer qualifies an unrelated sibling for purge; evidence must be in the candidate PR directory.
- F12 — Discovery reports non-listable state directories, processes readable siblings, and retains exit 1 even when no PR was found.
- F13 — A nonempty worktree ancestor now ends only that walk; cleanup still visits the independent
.lockshierarchy. - F14 — GC no longer interprets arbitrary worktree files named
pidas live locks.
Recommendations
Keep the paired preview/execution tests, but distinguish ownership from cleanliness in their fixtures. Use a real run-created checkout as the positive control, then test an unrelated clean clone, a damaged checkout, and Git metadata that porcelain does not report. For each refusal, assert that the underlying history or edited file survives, not just that the output lines agree.
Assessment
Ready to merge? No
Reasoning: The retry behavior and batch reporting are substantially better. The remaining blockers are deletion decisions: an empty Git status does not establish ownership or prove that all local data is disposable, and the fresh-checkout scan skips a location that can hold another active review.
Review generated by gh pr-review · model: azure-openai-direct/gpt-6.2-astra
…PR), with the code, tests and docs only it used: gc_purge and its checks, the handling of PR folders without pr.json, and the state folder and PR markers
… own, which git status never lists (a clone or worktree of yours checked out over files the PR tracks), or that find can't search for one; the status and .git checks are one helper, gc_disposable
…lagged assume-unchanged (core.ignoreStat=true flags them all) or skip-worktree (gc_flagged, git ls-files -v), and reads its status with each file's stat data checked in full (core.checkStat, core.trustctime) and the untracked cache off
… lock_take finds it: one it can't remove (its pid file can't be deleted), so gc --dry-run says the run fails, with its error; the probe/acquisition table covers it and its siblings
…<pr-key> from the lock's path, not the shortest /.locks/*, which a repo named .locks matches too
|
Thanks for round 3. Following its loop check ("churning", too big; split the PR), this PR is now split. Removed in
The four findings that remain in #18 are fixed, one commit each, with tests that failed on the commit before. A worktree is now removed only when the new Critical
Important
Minor
Checks on
|
catalan-adobe
left a comment
There was a problem hiding this comment.
Round 4 · since round 3
3 fixed · 1 still open · 4 new (2 in the new commits) · 3 declined · open blocking: 3 (was 6) · loop: converging
Approach
Unchanged since round 3: Splitting out --purge keeps lib/gc.sh focused on removing a closed PR’s review worktree and private refs under the existing locks, without having to infer which history files it owns.
Approach: Sound
Strengths
- [lib/gc.sh:322] — A refused worktree keeps its private refs as well as
pr.json. That makes cleanup retryable without losing the round pins. - [tests/gc.sh:586] — The nested-clone test checks that the unpublished commit is still readable, not just that GC printed a refusal. That is the right assertion for a deletion command.
- [lib/state.sh:184] — The stale-lock probe now checks whether the PID file can be unlinked. The paired test covers both PR and clone locks; I also ran
tests/state.sh: 207 checks passed.
Issues
🚨 Critical (Must Fix Before Merge)
-
F11 · [lib/gc.sh:121] — The new nested-checkout scan still misses a
.gitdirectory stored as.GITon a case-insensitive volume. With the usualcore.ignoreCase=true, Git excludes that spelling from status, butfind -name .gitcompares the directory entry’s spelling. I confirmed on the review machine that.gitresolved to a directory named.GITwhile thisfindpredicate returned nothing. A nested clone over trackedvendor/files can therefore still lose its unpublished history.- Match descendant
.gitnames case-insensitively, excluding only the review worktree’s own entry. Extend the existing unpublished-commit fixture with the case variant.
- Match descendant
-
[lib/gc.sh:105] — A nonempty uninitialized submodule can pass all three disposal checks. For example, a review checkout contains the gitlink
deps/sdk, and a developer copiesnotes.txtinto that directory without initializing the submodule. Git does not list its contents as untracked, the gitlink need not have either index flag, and there is no descendant.gitto find. Git’s own non-forced removal check skips unpopulated submodules, so the note is deleted. Earlier rounds tested nested checkouts, not files under a gitlink with no checkout.- Inspect mode-
160000index entries and refuse removal when the corresponding directory contains anything. Test both a nonempty directory that survives and an empty one that can be collected.
- Inspect mode-
-
[lib/gc.sh:208] — Removing a clean review worktree can discard the only reference to a local commit. The run itself has a concrete path to this state:
tests/flow.sh:1807checks that a commit made on the review worktree’s detachedHEADstops the run with exit 4. If the PR then closes, status is clean against that new commit. GC removes the worktree’sHEADand reflog, leaving the commit unreachable and eligible for pruning. Earlier GC tests checked dirty files and commits in a nested clone, not a commit on the review worktree’s ownHEAD.- Before removal, verify that the detached
HEADis a commit the tool recorded for this PR. On a mismatch, retain the worktree and refs and print the unexpected commit ID so the user can save it.
- Before removal, verify that the detached
⚠️ Important (Should Fix)
(none found)
💡 Minor (Nice to Have)
- [tests/gc.sh:259] —
line 'h/x/y#'searches for the literalh/x/y#:becauselineappends:. It cannot detect an unexpected report forh/x/y#7orh/x/y#8. Check both complete labels; keep the separate assertion that GitHub was not queried. - [README.md:290] — The manual history-deletion instructions say to check the lock, but not to finish GC first. Removing
pr.jsonafter a dirty-worktree refusal or an offline-clone skip loses the inventory a retry needs. Tell users to confirm cleanup for that PR before deleting its state folder.
Fixed since the last round (6)
- F8 —
lock_probenow refuses a stale read-only lock whosepidcannot be unlinked. - F10 — declined for this PR: “Deleting history moves to its own PR, designed so a run records what it creates.” GC no longer deletes a fresh checkout’s
.git. - F15 — declined for this PR: “Deleting history moves to its own PR, designed so a run records what it creates.” GC no longer decides whether
<run>/repois disposable. - F16 —
gc_flaggedchecks the index independently of status and retains worktrees with assume-unchanged or skip-worktree entries. - F17 — declined for this PR: “Deleting history moves to its own PR, designed so a run records what it creates.” No marker authorizes history deletion in this version.
- F18 —
clone_lockstrips the literal/.locks/<pr-key>suffix, including when the repo is named.locks.
Recommendations
Keep the preview/execution pairs. For each remaining deletion case, assert that the local file or commit is still accessible at its original path or ref after execution. Preview and execution can agree and still both make the wrong disposal decision.
Assessment
Ready to merge? No
Reasoning: Removing --purge resolves the history-deletion concerns for this PR, and the lock and index-flag fixes address their reported cases. Worktree removal can still erase user files or leave an unpublished commit without a reference, so the remaining fixes belong in GC before merge.
Review generated by gh pr-review · model: azure-openai-direct/gpt-6.2-astra
…ow the review worktree, whether <folder>/.git is there, asked of the file system (gc_nested, one sh per batch of folders), not find -name .git, so a .GIT on a case-insensitive volume is found too
…hat is not checked out, or something other than a folder there, which neither git status nor git worktree remove looks at (gc_gitlinks: each gitlink in the index must be an empty folder, or not there)
…s has (its HEAD, its HEAD's reflog, refs/worktree, refs/bisect, refs/rewritten and their reflogs: gc_commits), naming their IDs, or with a rebase, merge, cherry-pick, revert or bisect in progress (gc_operations); the run marks the PR heads it checks out in the worktree's reflog (REVIEW_REFLOG), so a head force-pushed away is not taken for a commit of yours
…l labels: line 'h/x/y#' looked for 'h/x/y#: ', which no line has
…rktree and refs (its line said removed, or gc --dry-run says nothing to remove), since pr.json is what a later gc needs, and while no review of it runs
|
Thanks for round 4. The three critical findings and both minors are fixed, one commit each, with tests that failed on the commit before (controls that pass on both are labelled). Each fix covers the whole class the example belongs to. As you recommended, every refusal test checks that the file or commit is still at its original path or ref after the real run, and that the PR's refs and Critical
Minor
The PR description is updated. Checks on
|
catalan-adobe
left a comment
There was a problem hiding this comment.
Round 5 · since round 4
3 fixed · 2 still open · 5 new (4 in the new commits) · open blocking: 5 (was 3) · loop: churning
Next: Split the PR: each part converges on its own
Approach
Unchanged since round 4: Preview and cleanup share the stricter gc_disposable checks in lib/gc.sh, which now protect worktree-only commits and files in uninitialized submodules while leaving review history untouched.
Approach: Sound
Strengths
- [lib/gc.sh:105] — Asking the filesystem whether each directory contains
.gitfixes the case-alias problem without following symlinks or guessing which spellings a volume treats as equivalent. - [tests/gc.sh:758] — The commit-preservation tests check that the commit is still accessible through its original
HEAD, reflog, or worktree ref after cleanup. That verifies more than a refusal message or an object that happens not to have been pruned yet.
Issues
🚨 Critical (Must Fix Before Merge)
-
F19 · [lib/gc.sh:124] — A nonempty submodule directory can still be mistaken for an empty one. Bash strips trailing newlines from
names=$(ls -A ...). I checkedgc_gitlinkswith a gitlink index record and a directory containing a six-byte file whose name was a single newline: the helper returned success with no output. Git's status and non-forced removal do not protect that file.- Test for the presence of an entry, not for nonempty filename text. Carry the refusal separately from the pathname used for display, and add this case to the preservation test.
-
F20 · [lib/gc.sh:193] — The reachability check counts refs that the same GC is about to delete. If a local commit is on the detached
HEADand the PR's privatebaseref was moved to it,for-each-refsupplies the commit as an exclusion. GC can then remove the worktree and the private ref, leaving no reference to the commit. This is not just a hypothetical ref namespace:tests/flow.sh:1846explicitly exercises a reviewer moving the privatebaseref.- Exclude the refs scheduled for deletion from the surviving roots. Recognize genuine run-owned commits separately; the current value of a mutable private ref is not proof that it came from GitHub.
-
[lib/gc.sh:322] — A missing worktree folder bypasses the new commit check. Deleting the checkout outside Git does not delete its administrative
HEAD, reflogs, or private refs. If the developer made a detached commit before deleting the folder, GC removes the registration at line 352 and with it the last reference to that commit. Earlier rounds checked the path of a missing registration and the commits of a present checkout, not the combination.- Resolve the recorded registration to its administrative directory and check its commits and operation state before unregistering it. Retain the registration and name the commit if it is the only reference.
-
[lib/gc.sh:160] — An empty-message first reflog entry proves that Git created a worktree, not that the review run checked out a PR head. For example, a developer can recreate a worktree at the saved path from a temporary local branch, detached, then delete the branch. The replacement passes the path and registration checks; its initial local commit is classified as exempt, even though the run never checked it out.
- Record the initial checkout SHA when the run creates the worktree, as well as identifying subsequent checkouts. Treat an unlabelled legacy entry as unknown unless its commit is otherwise accounted for.
-
[lib/gc.sh:191] — Two collectible worktrees can each count the other's
HEADas the surviving reference to the same unpublished commit. On an unchanged filesystem, preview approves both, while sequential execution removes the first and refuses the second. More seriously, two GC processes handling different PRs can both finish the check before either removes its worktree; their per-PR locks do not conflict, and neither reference survives.- Do not count another collectible review worktree as a durable root. Add a two-PR fixture with the same detached local commit and no branch, and check that preview agrees with execution and that a reference survives.
⚠️ Important (Should Fix)
(none found)
💡 Minor (Nice to Have)
- [lib/gc.sh:270] — Lost commit IDs go through
gc_entries, which prints only three values and “N more.” If several independent commits need saving, the user cannot identify all of them from the refusal before using the suggested force command. Print all at-risk IDs, or provide a read-only command that lists them. - [README.md:299] — The new history-deletion prerequisite is impossible to satisfy for a
--fresh-only PR: the preceding sentence correctly says GC prints no line for it. Distinguish that case from a PR withpr.json; the latter must finish GC first.
Fixed since the last round (3)
- F11 — The descendant check now uses filesystem lookup, and the case-insensitive fixture verifies that the nested clone's unpublished commit survives.
- F21 — The test checks both complete PR labels and independently verifies that GitHub was not queried.
- F22 — The README now tells users to retain
pr.jsonafter a refusal or offline-clone skip until cleanup finishes.
Recommendations
Build the reachability check around what will still name a commit after cleanup, and use that check for both present and missing worktrees. Keep the paired preview/execution tests, but include a pair of PRs whose cleanup decisions depend on each other.
I checked the filename edge case independently. The full tests/gc.sh suite could not start in this review environment because the read-only Git wrapper refused the fixture's git init.
Assessment
Ready to merge? No
Reasoning: The common dirty-file and detached-commit cases are now covered, but GC can still delete a file or remove the last reference to an unpublished commit while reporting successful cleanup. Those failures belong in the automatic disposal checks, not in manual recovery instructions.
Review generated by gh pr-review · model: azure-openai-direct/gpt-6.2-astra
…file alone, by find (dir_holds), never from ls's names as text, which drop a name's trailing newlines: a submodule folder holding only a file named a newline is no longer taken for empty; gc_gitlinks's verdict is whether it printed anything, its paths shell-quoted
…(worktree_sha, empty when it reuses one pr.json does not name), and gc takes that commit, and the new values of entries with the run's label, for the run's PR heads: no longer the first reflog entry git worktree add writes, which a worktree of yours made again at that path from a deleted branch also has; a worktree an earlier version made is removed only when its commits are in a ref that stays
…private refs of any PR (this gc deletes this PR's, a gc of another PR may be deleting theirs) and symbolic refs, the main worktree's HEAD, and the HEADs of worktrees outside .reviews (gc_kept_worktree: a review worktree's may be going too): a commit that this PR's base ref was moved to, another PR's ref alone has, or two review worktrees' HEADs share, leaves the worktree
…de git before it removes its registration (gc_gone): found in worktrees/<id> by its gitdir file, it holds the worktree's HEAD, reflogs and own refs, so a commit only it names, or an operation in progress there, leaves the registration, its refs and pr.json, named; gc_commits reads through --git-dir
…y more (gc_all); README: a PR folder without pr.json (--fresh only, no gc line) can be deleted while no review of it runs, one with pr.json only once gc has removed its worktree and refs
|
Thanks for round 5. All five critical findings were in round 4's new code, and each fix tightens the same rules rather than changing the design. As agreed before this round, this is the last one: after these fixes and a green CI, the PR is merged. The fixes are one commit each, with tests that failed on the commit before (controls that pass on both are labelled). Every refusal test checks that the file or commit is still at its path or ref after the real run, and that preview and run agree. Critical
Minor
Not in this PR: a review run that remakes a deleted review worktree with The PR description is updated. Checks on
|
PR 3d of review tracking:
gh pr-review gc, the--doctorpaths, and one README section on where reviews run. This is Task 5 and steps 1–2 of Task 6 ofdocs/superpowers/plans/2026-11-26-review-tracking-pr3-local-worktrees.md. The plan predates #16's six review rounds, so it follows #16's code: the refs, worktree and lock paths keyed by<host>/<owner>/<repo>/<N>, the locks, and the path checks. Two plan steps are left out on purpose: the real run and its timings (Task 6 steps 3–4) come in a follow-up, because they call the model.After round 3 flagged this PR as churning and too big, it was split:
gchere removes review worktrees and refs only and keeps the review history. Deleting history (--purge) moves to a separate PR.gh pr-review gc [--dry-run] [-u <login>]pr.json, including dot-named repos such as.github. Folders without one are passed over, and GitHub isn't asked about them.gcasks GitHub for each PR's state with this account:-u, else the one inpr.json, elseGH_PR_REVIEW_USER, else the active one, chosen as a review run chooses it. Open PRs are kept.The review worktree is removed only when it is clean, with
git worktree removeand no--force. Clean means all of these:git statuswith untracked and ignored files and submodule changes prints nothing. The fsmonitor and untracked cache are off, and the stat data is checked in full..gitis below it other than its own. For each folder, the check asks the file system for<folder>/.git, as git does, so.GITon a case-insensitive volume counts.HEAD, its reflogs or its own refs (refs/worktree,refs/bisect,refs/rewritten) is either a PR head the run checked out or reachable from a ref that stays.worktree_shainpr.json), and the new values of the reflog entries it labels.refs/pr-review/*and symbolic refs, plus the main worktree'sHEADand theHEADs of worktrees outside.reviews. Nothinggcmay delete counts.It must also pass the run's path checks:
owned_worktree, the exact<clone>.reviews/<host>/<owner>/<repo>/<branch>/<N>layout,reviews_check, and no overlap with the state folder or the PR's folder.When the worktree is left: the line names what was found (for lost commits, all their IDs) and the command that removes it anyway (
git -C <clone> worktree remove --force <path>). The PR keeps its refs andpr.json, so a latergccan finish.A worktree whose folder was deleted outside git: that one registration is removed when its recorded path still leads where the run puts it and its leftover git folder (
worktrees/<id>) passes the same commit and operation checks.gcnever runsgit worktree prune, which would drop the registrations of your offline worktrees.Refs:
refs/pr-review/<host>/<owner>/<repo>/<N>/*(head, base and round pins) are deleted in oneupdate-ref --no-deref --stdintransaction, with old values checked.Empty folders: those left in
.reviewsand.locksare removed withrmdironly, and so is.reviewsitself when it is empty.pr.json,loop-check.md) is kept. The README says how to delete it by hand.--dry-runprints whatgcwould do and changes nothing. It runs the same checks, including the locks, through the read-only lock check that the run's lock code also uses (lock_state/lock_probeinlib/state.sh,clone_lock_path/clone_lock_checkinlib/worktree.sh).gccan't list are named, and the folders beside them are still checked.HEAD, index, stash, config and other worktrees, and the cache clones.State and lock changes
lock_takedecides bylock_stateafter each failed atomic claim.lock_probeandlock_checkgive the same verdict and message without changing anything.clone_lockis split into path checks, a read-only check, and the take.<clone>.reviews0700 by stripping the known/.locks/<pr-key>suffix..pr.json.tmp.<pid>and.loop-check.md.tmp.XXXXXX.pr.json(worktree_sha). When it checks out the PR head in a reused worktree, it labels the reflog entrygh-pr-review: checkout of the PR head. Both letgctell the PR heads the run checked out from commits made there.lock_claim,lock_remove,lock_stateandlock_probetell "empty" and "onlypid" withfind, so names that end in a newline can't fool them.--doctorIt now also prints the state folder (with a note when it isn't writable or searchable), the config file (or "none"), and the clone roots (or "none" for
[]), without scanning. An invalid config file fails the check, since every run that looks up a clone stops on it.clone_roots(inlib/clones.sh) now reads the roots for both--doctorandfind_clone.README
The parts that grew over #16's rounds are now one "Where reviews run" section:
--clone/--fresh;gcis in Usage, and Troubleshooting covers:.reviews;rm -rfcommand;Tests
tests/gc.sh: 211 checks, with real git and stubgh. Worktrees are made by the run's own code. Preview/run pairs compare the lines and the exit code, and check what survives. Cases:--dry-run;-uand an unknown login; open, merged and closed PRs; a state that can't be read..reviewssymlink..git(or.GIT) worktree; assume-unchanged, skip-worktree andcore.ignoreStatfiles; files in an unpopulated submodule's folder; a stopped rebase; a commit on itsHEAD, only in its reflog, or onrefs/worktree/*; a commit kept only by a PR's private ref, or shared by two review worktrees; a worktree remade at the saved path from a local branch; a deleted folder whose registration still holds a commit or a stopped rebase; a file named with a newline. Each check confirms the file or commit is still there afterwards.--no-postheads, are removed. So are an earlier version's worktree whose heads were merged, and a run-made worktree whose folder was deleted.rmdirfailures; unlistable folders; tidying beside an open PR.tests/state.sh: a table of lock kinds, including names that end in a newline. Each is checked for the probe verdict, that nothing changed, and that it matches a reallock_take.tests/flow.sh: the--doctorlines.