Repository navigation
Review in a worktree of the local clone, with private refs per PR - #16
Conversation
…rlier local-worktrees branch
catalan-adobe
left a comment
There was a problem hiding this comment.
Approach
What it does: Reuses a detached worktree across review rounds and pins each posted round’s head and base, so lib/delta.sh can compare against the reviewed commits after a force-push. --fresh keeps the throwaway checkout.
Fit with the repo: lib/clones.sh and lib/worktree.sh follow the base commit’s PR 3 plan. Two issues matter before making this the default. First, docs/superpowers/specs/2026-11-26-review-tracking-design.md calls for read-only Git and a tripwire around both passes. gh-pr-review still runs pi with --approve and neither guard. The PR says “Whichever of the two merges second,” but #14 is still open. Second, lib/state.sh locks by host/owner/repo/PR, while the private refs use only the PR number within a clone. A fork and its upstream can both match that clone: their two PRs numbered 7 take different locks but write the same refs, and reuse the same worktree if their branch slugs match.
Strongest case for the approach as built: Private refs solve a Git history problem in Git. The existing round records and comparison logic stay useful without a second review pipeline.
Alternatives: Land #14 first, then use the existing host/owner/repo/PR key for refs and worktree paths. That costs merge ordering and longer names, not a redesign of either review pass.
Questions for the author: Can shared-clone discovery become the default only once both passes have the guards and distinct PRs cannot claim the same checkout? That would make this Sound.
Missing context: None.
Approach: Questionable
Strengths
- [lib/worktree.sh:15] — Fetching by the PR repository’s URL with explicit destination refs, no tags, no
FETCH_HEADwrite and no submodule recursion handles the common fork setup without movingorigin/*. - [gh-pr-review:1597] — Round refs are written only after a confirmed post, using the posted record’s round when available. A preview or failed post does not become a baseline.
- [tests/worktree.sh:105] — The force-push tests exercise real Git objects, including garbage collection, rather than mocking ancestry. I ran
tests/clones.shandtests/worktree.sh; both passed.
Issues
🚨 Critical (Must Fix Before Merge)
-
[lib/worktree.sh:50] — A registered pathname is treated as proof that the directory currently there is the registered worktree. If a review directory is removed outside Git and an independent clone of the same repository is later placed there, the stale registration still matches. Lines 90–91 can then detach that independent clone, discard tracked edits and delete untracked files.
- Fix: Before a destructive reuse, verify from the candidate directory that it is the exact worktree root, its common Git directory belongs to the selected clone, and its worktree-specific Git directory matches the registration. On any mismatch, leave the directory untouched.
-
[lib/worktree.sh:17] — The fetch destinations use only the PR number, and line 67 adds only the branch slug to the worktree path. A clone with both upstream and fork remotes can therefore give two distinct PRs numbered 7 the same refs and checkout. Their state locks are distinct. With the same head branch name, one run can replace the files pi is reading while the other still posts against its originally captured SHA.
- Fix: Use the canonical host/owner/repo/PR identity for both the ref namespace and the worktree path. Test two PRs with the same number and slug against one clone; each checkout and each posted pin should remain independent.
-
[gh-pr-review:525] — The default now puts both model passes in a checkout that shares the user’s refs and stash, but pi still runs with
--approveat line 1172 and neither pass checks for mutations. For example, a model that stashes a scratch edit changes the user’s stash, and the run can still post normally.- Fix: Wire the read-only runner and before/after checks for both passes, with
CLONE_DIRandREVIEW_DIRas distinct inputs, before enabling the shared checkout by default. Until then, keep the throwaway checkout as the default.
- Fix: Wire the read-only runner and before/after checks for both passes, with
⚠️ Important (Should Fix)
-
[lib/clones.sh:52] —
rev-parse --git-dirsucceeds in any subdirectory of a repository. Passing--clone /repos/r/srctherefore setsCLONE_DIRtosrcand creates/repos/r/src.reviews/...inside the user’s working tree. The same validation also accepts a linked worktree through the config or override, despite the main-clone restriction applied during scanning.- Fix: Resolve candidates to the main clone root or reject non-root and linked-worktree paths with a diagnostic. Validate bare repositories separately.
-
[lib/clones.sh:8] —
-Cdoes not override inheritedGIT_DIR,GIT_WORK_TREEorGIT_INDEX_FILE. When launched from automation that exports these, commands nominally targeting the review worktree can instead operate on the caller’s checkout or index. The test fixtures explicitly unset repository-routing variables, so they cannot catch this.- Fix: Clear repository-routing environment variables before clone discovery and keep them cleared for checkout, delta calculation and pi. Preserve the intended credential and URL configuration separately.
-
[lib/worktree.sh:77] — Creating one review runs
git worktree pruneacross the entire clone, even before checking whether the destination is occupied. This follows the plan literally, but conflicts with its isolation guarantee: an unrelated, unlocked worktree on a temporarily unmounted volume can lose its registration and worktree-specific index during an otherwise unrelated review.- Fix: Check the destination first and recover only a stale registration for that exact review path. Leave general worktree pruning to explicit maintenance.
-
[lib/worktree.sh:84] — A new linked worktree can inherit sparse-checkout patterns. I checked this with a full, non-partial clone containing directories
aandb: with onlyaselected, the detached worktree also contained onlya. A PR changingbtherefore gets a review checkout missing the very files the prompt asks pi to read in full.- Fix: Materialize a full checkout using worktree-specific settings, or skip sparse candidates with a reason and use the cache. Test that an excluded changed file exists in the review tree while the original clone remains sparse.
-
[lib/clones.sh:112] — An existing config file that omits
rootsdisables the documented~/reposscan. Thearraysfilter emits no value for a missing key, soconfig_getnever applies its default; line 153 then substitutes[]. A user who configures one explicit clone gets cache clones for other repositories on their first lookup, even when those repositories are under~/repos.- Fix: Default missing or null
rootsbefore filtering by type, while preserving an explicitly empty array. Add a lookup test with a config containing onlyclonesand no remembered pick.
- Fix: Default missing or null
-
[lib/worktree.sh:124] — A matching pinned head makes the pinned base authoritative even when the record supplies a different base. A deleted round can be reposted on the same head after a retarget, for example from
--fresh, leaving the old local pin pair intact. The next round can then miss the retarget and review only an increment. The two independentupdate-refcalls at lines 112–113 can also leave a new head paired with an old base if the second write fails.- Fix: Check agreement with both known record SHAs before accepting a pin pair, and update the two refs in one
git update-ref --stdintransaction.
- Fix: Check agreement with both known record SHAs before accepting a pin pair, and update the two refs in one
💡 Minor (Nice to Have)
- [lib/worktree.sh:87] — The dirty-worktree warning goes only to stderr. Task 3 also calls for recording it with the run; after a reset there is no durable indication in the run artifacts that local edits were discarded.
- Fix: Save the warning in the run’s local metadata as well as printing it.
Recommendations
Extend the real-Git flow test without clearing PR state between its two rounds. run_local calls fresh at tests/flow.sh:1445, which deletes pr.json; the second round consequently tests rediscovery of the default path rather than reuse of the saved path. Changing the head branch name between rounds would make that distinction observable.
Assessment
Ready to merge? No
Reasoning: The ordinary fetch-and-pin flow works, but the default checkout can modify a directory the tool does not own, and concurrent reviews can share files despite holding separate locks. Those failures need to be closed before users can rely on the promise that their clone stays untouched.
Review generated by gh pr-review · model: azure-openai-direct/gpt-6.2-astra
…inside a working tree
…ne's registered worktree
… every worktree of the clone
…em in one transaction
…ds and rename the branch
…-worktrees # Conflicts: # README.md # gh-pr-review
|
Thanks for the review. Ten of the eleven items are addressed, each with a test that failed on the code before its fix (the recommendation is a test change). The third Critical waits for #14, as explained below. This branch also merges #13's round-1 fixes ( Approach question (shared clones as the default only once both passes are guarded and distinct PRs can't share a checkout): yes to both. Distinct PRs are now kept apart (second Critical below). For the guards, #13's plan now makes 3c depend on 3a and 3b ( Critical
Important
Minor
Recommendation ( All test files pass on macOS (bash 5) and ubuntu:24.04; |
Conflicts: - README.md: #13's lock description and #14's tripwire/ entry, with this branch's review-worktree paragraph, pr.json facts, repo/ (--fresh only) and warnings.txt (a reset dirty worktree, or a change in the clone only). - tests/flow.sh: the stub pi keeps both pi.pwd and #14's pi.evil; run, run_no_y and run_tty run $ext_bash (#15) with --fresh; run_local runs $ext_bash too; the local-clone cases come before #14's real-git --fresh cases.
…top on a stash made in the worktree run_pi snapshots CLONE_DIR (the user's clone, or the --fresh clone) and REVIEW_DIR separately, so a change to the user's clone is compared from the clone itself (its HEAD included) and only warns, as before. The review worktree's snapshot also takes its own refs (refs/worktree/, refs/bisect/, refs/rewritten/) and the PR's own refs/pr-review/<key>/*, which nothing else writes while pi runs: a change is exit 4. The stash is shared with the clone: a new entry made on the review worktree's detached HEAD (its commit's first parent and "(no branch)" subject) is exit 4 too. Tests: local-clone flow cases for both passes in the worktree with the read-only git, a commit, a stash and a pi/review ref change past the wrapper (exit 4, the user's clone unchanged), and a branch, a detached HEAD and a stash in the user's clone (a warning, posted); a --fresh stash case; tripwire unit cases.
…s exit 4, what is a warning
|
#13, #14 and #15 are merged, so this PR now targets Wiring (
Tests, in local-clone mode with real git: both passes run in the review worktree with the read-only git ( Docs ( All 13 test files pass on macOS (bash 5) and ubuntu:24.04; |
catalan-adobe
left a comment
There was a problem hiding this comment.
Round 2 · since round 1
6 fixed · 4 still open · 7 new (7 in the new commits) · open blocking: 9 (was 9) · loop: early · full review (the base branch was merged in with conflicts)
Approach
What it does: Reuses a detached review worktree across rounds and pins each posted round’s head and base so lib/delta.sh can still compare them after a force-push.
Fit with the repo: Both round‑1 concerns are resolved. The base plan (docs/superpowers/plans/2026-11-26-review-tracking-pr3-local-worktrees.md) requires #13’s lock and #14’s read-only runner before shared clones become the default. Both are merged. Both passes use the same run_pi, which applies read-only Git and snapshots the clone and review worktree separately. lib/worktree.sh now keys refs and checkout paths by the same host/owner/repo/PR identity as the lock, so a fork’s PR #7 and its upstream’s PR #7 no longer collide.
Strongest case for the approach as built: Private Git refs keep the reviewed commits alive without creating a second source of truth for what was posted. The existing round records and comparison logic still serve both checkout modes.
Alternatives: Keep --fresh as the default. That avoids sharing a clone, but repeats the clone each round and loses the local pins. It remains available per run.
Questions for the author: None.
Missing context: None.
Approach: Sound
Strengths
- [lib/worktree.sh:195] — The posted head and base now move in one ref transaction.
tests/worktree.sh:141locks the second ref and checks that both old values survive the failed update. - [gh-pr-review:278] — Both model passes use the same guarded runner, with the clone and review worktree snapshotted separately.
tests/flow.sh:1675checks the clone snapshot’s actualHEAD, so passing the worktree twice would fail the test. - [tests/flow.sh:1606] — Round 2 now preserves
pr.jsonand renames the head branch. That distinguishes reuse of the saved worktree from accidentally rediscovering the same default path.
I ran tests/clones.sh and tests/worktree.sh in isolated temporary directories; all 64 and 98 checks passed, respectively.
Issues
🚨 Critical (Must Fix Before Merge)
(none found)
⚠️ Important (Should Fix)
-
F4 · [lib/worktree.sh:130] — A symlinked clone can still put the review inside a user’s working tree. The subfolder and linked-worktree cases are fixed, but validation uses the physical clone root while path construction uses logical
pwd. With--clonepointing to a symlink inside another checkout, I got a newdep.reviews/in that checkout’sgit status. Build the path from the canonical clone root and validate the actual destination parent before creating it. -
F6 · [lib/worktree.sh:50] — A review fetch can still prune unrelated worktrees. The explicit
worktree pruneis gone, butgit fetchenables auto-maintenance by default. In a temporary clone above its auto-GC threshold, I tracedfetch_prinvokinggit worktree prune --expire 3.months.ago; it removed the registration of an unrelated, offline worktree with an old index. Pass--no-auto-maintenanceon shared-clone fetches, including the fetch-by-SHA fallback. -
F7 · [lib/clones.sh:111] — Discovery can still accept a sparse clone and omit files from the review. The new check works normally, but inherited
GIT_CONFIGredirectsgit configwithout redirecting checkout. WithGIT_CONFIG=/dev/nulland an explicit sparse clone,find_cloneaccepted it and the review worktree lacked a tracked directory. RemoveGIT_CONFIGfor discovery queries, asgit_env_configalready does for its probe, and keep credential and URL settings separate. -
[lib/worktree.sh:163] — A local replacement object can change the code reviewed without changing the reported commit. In a clone with a replacement for the PR head, the new worktree’s
HEADwas the requested SHA, but its file contained the replacement commit’s contents. The pre-post SHA check cannot catch that. Disable replacement objects for checkout, comparisons and both pi passes, or skip such clones. -
[lib/worktree.sh:162] — The review copy can expose a private clone’s files to other local users. With umask
022, the sibling worktree is created0755. A clone protected by its own0700directory under a traversable parent therefore gets a readable copy outside that protection. Create tool-owned worktree and cache directories under a restrictive umask, with a private ancestor in place before checkout starts. -
[gh-pr-review:588] — Different state roots can claim the same live review worktree. Two runs using the supported relative
GH_PR_REVIEW_STATE=./statefrom different directories take different locks at line 543, but can discover the same clone and use identical refs and worktree paths. If one resets the checkout between the other’s model passes, neither before/after comparison has to see a change. Hold a lock keyed by the physical clone and PR across fetch, both passes and pinning, independently of the artifacts directory. -
[lib/worktree.sh:113] — Relative worktree links break reuse and can change the clone’s config. With
worktree.useRelativePaths=true, I saw the firstworktree addupgradecore.repositoryformatversionand setextensions.relativeWorktrees. Round 2 then rejected its own worktree as “in the way”: the relativegitdirbacklink was resolved against the process’s current directory, not the administrative directory containing it. Prevent the implicit format upgrade when adding a worktree, and resolve existing relative backlinks from their containing directory. -
[lib/clones.sh:8] — The clone’s filesystem-monitor hook still runs during checkout preparation.
core.hooksPath=/dev/nulldoes not disable a hook configured throughcore.fsmonitor. I observed that hook run during worktree creation and reuse, before pi’s guard applies. Apply the samecore.fsmonitor=falseoverride used by the snapshots to the script’s own Git operations. -
[tests/worktree.sh:17] — The new Git fixtures can write to the caller’s index. The test clears
GIT_DIRandGIT_WORK_TREEbut leavesGIT_INDEX_FILEset. If a hook or task launches it with an absolute index path, even the first fixturegit addat line 56 targets that index.tests/clones.sh:16has the same omission. Clear repository-routing variables before the first fixture Git command, as the real-Git flow setup does.
💡 Minor (Nice to Have)
-
F10 · [lib/worktree.sh:166] — A dirty reset can still leave no warning. The warning is now saved when emitted. With
status.showUntrackedFiles=no, however, I saw an untracked file deleted byclean -fdqwith neither a console warning nor awarnings.txtentry. Request untracked files explicitly and checkstatus’s exit code before proceeding with a destructive reset. -
[lib/clones.sh:230] — Two first-time reviews can race to initialize the cache clone. Different PRs of one repository have different locks. Both can see a missing cache and try to clone to the same destination, or one can see the directory before the other has finished initializing it. Serialize initialization per cache repository and verify that an existing destination is a usable bare clone before returning it.
Fixed since the last round (6)
- F1 — Reuse now verifies the worktree root, common Git directory, administrative directory and backlink; an independent clone at a stale registration is left untouched.
- F2 — Fork and upstream PRs with the same number and branch slug now have distinct ref namespaces and checkout paths.
- F3 — Both passes run through read-only Git and before/after snapshots of the selected clone and review worktree.
- F5 — Startup clears the caller’s repository, worktree, index and object-store routing variables before operating on the clone.
- F8 — Missing or null
rootsretains the~/reposscan; an explicit[]disables it. - F9 — Pin selection checks both known record SHAs, and the head/base pair is updated atomically.
Recommendations
Extend the real-Git isolation tests with two assertions beyond ordinary git status: the materialized files match the unreplaced commit, and unrelated worktree registrations survive the fetch, not just worktree add. Both caught failures that a clean status and matching HEAD did not.
Assessment
Ready to merge? No
Reasoning: The ordinary two-round flow and six earlier findings are fixed. The default shared-clone path can still review different contents than the SHA posted to GitHub, expose a private checkout, or remove another worktree’s registration; those are merge blockers for this feature.
Review generated by gh pr-review · model: azure-openai-direct/gpt-6.2-astra
… in it: no symlink, checkout or other's folder
…eave it as it is lock_claim took any folder without a pid file, and lock_remove deletes a lock folder with all it holds: a folder that was not a lock (a PR's state folder that the clone lock path points at, with its rounds, pr.json and lock/) was claimed, then deleted on release. A lock folder holds its pid file only, made before anything could go in it, so a folder without one is claimed only when the pid file just made is all it holds; one that holds other files is refused at once, with an error that names it, and left as it is. A lock with a pid file (live, dead or empty) is handled as before. cache_clone_make no longer removes a clone from a claimed lock folder: such a folder is now refused.
lock_remove ignored a failed rename, so a lock that stayed (its parent folder read-only…) was reported as released. A lock that is already gone is still removed; any other failure is an error that names the lock, and a failure. A takeover that can't remove the dead run's lock is refused at once instead of retried a hundred times. The PR lock released on exit and the cache lock released once the cache clone is in place report it without changing the run's status.
The key of a GitHub Enterprise host with a port (ghe.local:8443/o/r) keeps the port, and the cache clone is made from https://ghe.local:8443/o/r.git, but normalize_remote dropped the port, so the cache clone the run had just made was refused as one with no remote of the repo, and a user's clone was never found. An http(s) remote now keeps its port (not the default 443 or 80), and must have the key's; an ssh or scp-style remote, whose port is the SSH server's, matches the key's host without its port.
…ock folder The cache clone was made in the lock folder (under locks/), then moved to clones/: when clones/ is on another file system, mv copies, and a lookup that sees the destination could inspect a half-copied repository. It is now made in <repo>~clone.<random> beside its place (a ~ is in no repo name: never a cache clone or a scan's pick), renamed in once complete, removed when the clone fails, and one left by a killed run is removed by the next run that makes the cache clone, under the lock. The lock folder holds its pid file only.
…orktree, before either is made or reset
…; leave one elsewhere, with a warning
…ree outside .reviews, a .reviews that is a checkout
# Conflicts: # README.md
|
Thanks for round 3. All seven items are fixed, one commit each. Each comes with tests that failed on the code before its fix; the exceptions are named below. The recommendation is in too: Important
Minor
Recommendation:
Before the fixes, all six new flow cases failed (328 ok, 6 FAIL), and no others. Both halves were made in parallel and merged in
|
catalan-adobe
left a comment
There was a problem hiding this comment.
Round 4 · since round 3
3 fixed · 4 still open · 1 new (1 in the new commits) · open blocking: 4 (was 4) · loop: converging
Approach
Unchanged since round 3: the stricter ownership checks stay in lib/state.sh and lib/worktree.sh, cache creation stays in lib/clones.sh, and both review passes still use the same guarded runner.
Approach: Sound
Strengths
- [lib/clones.sh:294] — The cache clone is now staged beside its final destination. Publishing it by rename no longer depends on
locks/andclones/sharing a filesystem. - [tests/flow.sh:1833] — The migration test checks the directory pi actually enters, the updated
pr.json, and the old worktree’s contents and permissions. That verifies both sides of the migration: the new checkout is private, and the old one is untouched.
I ran tests/clones.sh, tests/state.sh, and tests/worktree.sh in isolated temporary directories on macOS. All 386 checks passed, including the worktree suite with GIT_NO_REPLACE_OBJECTS=1 inherited.
Issues
🚨 Critical (Must Fix Before Merge)
(none found)
⚠️ Important (Should Fix)
-
F4 · [lib/worktree.sh:154] — The clone lock can still write into an unrelated checkout when Git cannot read its metadata. The new check refuses a healthy checkout, but treats failed Git probes as evidence that the folder is not a repository. I checked a
.reviewsdirectory whose.gitfile points to an offline linked-worktree administration directory:reviews_checkaccepted it.clone_lockthen creates.locks/in that checkout and changes its root permissions to0700.- Refuse a destination with a
.gitentry even when Git cannot resolve it. Test that an unavailable backlink leaves both the directory contents and its permissions unchanged.
- Refuse a destination with a
-
F18 · [lib/state.sh:176] — Stale-lock takeover can still delete a PR’s saved rounds. The new contents check protects a directory without a PID. If a local run is killed, its clone lock already has a PID. A subsequent
--freshrun withGH_PR_REVIEW_STATE=<clone>.reviews/.lockscan save its round in that directory: it takes the child PR lock but never callsclone_lock. The next local run using the normal state root sees the dead PID and recursively removes the directory, including the saved round.- On takeover and release, remove only known lock-owned entries; preserve and report unexpected contents. Test a dead clone lock containing both
pidand a completed round, not just the PID-less case.
- On takeover and release, remove only known lock-owned entries; preserve and report unexpected contents. Test a dead clone lock containing both
-
F19 · [lib/clones.sh:80] — Cache validation still rejects its own HTTPS remote when the target explicitly specifies port 443. The
:8443case is fixed. Forhttps://ghe.local:443/o/r.git, however,normalize_remoteremoves:443while the lookup key retains it.clone_matchesreturns false, so a successful cache clone fails validation on this and subsequent runs.- Apply the same default-port normalization to the target and the remote. Test cache creation and reuse with an explicit
:443target, while keeping distinct non-default ports separate.
- Apply the same default-port normalization to the target and the remote. Test cache creation and reuse with an explicit
-
[lib/worktree.sh:109] — The new overlap check can miss a state directory inside the worktree on case-insensitive filesystems. On macOS,
paths_overlapreported no overlap between a worktree ending inBugFix/7and an existing state directory reached throughbugfix/7/.state/….pwd -Ppreserved the supplied spelling. On reuse, the check at line 256 therefore permitsgit clean -fdqto delete the untracked state directory, including earlier rounds.- Compare existing directories and their ancestors by filesystem identity, not just by path strings. Add a case-insensitive-volume test that checks the saved round survives; lowercasing paths globally would be incorrect on case-sensitive volumes.
💡 Minor (Nice to Have)
- F20 · [lib/state.sh:201] — Lock release still reports success when it cannot inspect the PID. A readable but unwritable parent now produces the intended rename error. With search permission removed from the parent, I got status 0, no diagnostic, and the lock still present after restoring permissions. The failed PID read is treated as “not our lock.”
- Distinguish a confirmed absent or differently owned lock from an unreadable one. Report the latter without deleting it; the exit trap can still preserve the review’s original status.
Fixed since the last round (3)
- F12 — Reuse now requires the worktree to be under the verified private
.reviewsdirectory; a saved checkout outside it is left alone and named in the warning. - F17 — Cache staging and publication now happen in the same parent directory, so a lookup cannot observe a cross-filesystem copy in progress.
- F21 — Both replacement-object fixtures clear the inherited setting before establishing the plain-Git control.
Recommendations
Extend the existing filesystem tests with a stale lock containing review artifacts and a state path that aliases the worktree. For both, the key assertion is that the saved round remains readable at its original path after the run—not just that the command returns an error.
Assessment
Ready to merge? No
Reasoning: Cache publication and private-worktree migration are fixed, but lock takeover and worktree cleanup can still delete saved rounds. Those failures need to be closed before shared worktrees become the default.
Review generated by gh pr-review · model: azure-openai-direct/gpt-6.2-astra
…ne's folder, or on the way to a lock or worktree reviews_check found checkouts and repositories by running git, and took a failed probe for none: a .reviews whose .git file leads to a linked worktree's admin folder that is gone (an offline volume, a deleted clone), or whose .git is an empty or broken folder or a broken symlink, was accepted, and clone_lock made .locks/ in it and its top folder 0700. A .git of any kind (has_dotgit) is now refused too, whether or not git can resolve it: in .reviews, in the folder it is in (the clone's parent), and in the folders on the way from .reviews to the lock or the worktree, a reused one included. The git-based checks stay.
…as folders, not as path strings paths_overlap compared the paths missing_path printed, and pwd -P keeps the spelling it is given: on a case-insensitive file system (APFS's default) a worktree at …/BugFix/7 and a state folder reached through …/bugfix/7/.state were not seen to overlap, so the reuse's git clean could delete the state folder with its rounds. The folders that are there are now compared by identity (-ef, dir_within), the string comparison kept where it says they overlap. A path's missing last parts cannot hide existing data: the path is inside an existing folder when its nearest existing folder is; two missing paths are compared by the names below the same nearest folder.
…der holds; refuse to take over a dead lock that holds other files A lock folder is the tool's only while it holds its pid file alone. A release or takeover deleted the whole folder (renamed, then rm -rf), so a dead clone lock in a folder that a --fresh run with GH_PR_REVIEW_STATE=<clone>.reviews/.locks used as the PR's state folder lost its saved rounds to the next local run. Now the pid file is deleted, then the folder with rmdir: a release that finds other files leaves them with a warning; a takeover of such a lock is refused, naming the folder, and the next run is refused by the round-3 rule (no pid file, other files).
…instead of taking it for another run's lock_release read <lock>/pid and treated any failure as "not our lock": with the parent folder's search permission gone, it returned 0 silently and the lock stayed. Now a pid file that is confirmed absent (path_absent: the folder it would be in is searchable) or holds another PID is still a silent success; one that can't be read is an error that names the lock, a failure, and nothing is deleted. The exit handlers keep the run's status (|| true).
…cache clone of https://ghe.local:443/o/r.git passes its own check normalize_remote drops :443 from an https remote, but the key kept it (GH_HOST_NAME=ghe.local:443 gave ghe.local:443/o/r), so clone_matches failed on the cache clone just made, on this and every later run. repo_key now gives the key as normalize_remote gives https://<key>: clone_matches normalizes its target with it, and find_clone its key, so the scan, the cache check, the cache folder's name, clones.json and the config's clones map (its keys too) all use the key without :443. Other ports stay distinct (:8443, :9443, none).
# Conflicts: # README.md
|
Thanks for round 4. All five items are fixed, one commit each, each with tests that failed on the code before its fix (controls that pass on both are labelled). Both recommendations are in: a stale lock holding review artifacts, and a state path that aliases the worktree. In each case the key assertion is that the saved round is still readable at its original path after the run. Each fix closes its category, not just the reported case. Important
Minor
Both halves were made in parallel and merged in
|
catalan-adobe
left a comment
There was a problem hiding this comment.
Round 5 · since round 4
3 fixed · 2 still open · 1 new (1 in the new commits) · open blocking: 3 (was 4) · loop: nit loop
Next: Approve, and file the remaining findings as follow-ups
Approach
Unchanged since round 4: lib/state.sh handles lock cleanup, lib/worktree.sh checks for overlapping directories, and lib/clones.sh normalizes repository names for clone lookup without changing how either review pass runs.
Approach: Sound
Strengths
- [lib/state.sh:91] — Lock cleanup now removes only
pidand usesrmdirfor the directory. That protects saved rounds even if another file appears during cleanup. The flow test attests/flow.sh:1827verifies that the saved review remains readable at its original path. - [tests/flow.sh:1926] — The case-alias test checks what matters on refusal: no model call, no reset of the dirty file, and no loss of the saved round. The case-sensitive control also verifies that distinct directories remain usable.
I ran tests/state.sh; all 129 checks passed. I also checked the two remaining path cases below in temporary directories without modifying this checkout.
Issues
🚨 Critical (Must Fix Before Merge)
(none found)
⚠️ Important (Should Fix)
-
F4 · [lib/worktree.sh:200] — An offline outer checkout is still accepted when the clone is nested one directory deeper. The new
.gitcheck protects.reviewsand its immediate parent. With the clone atouter/vendor/randouter/.gitpointing to unavailable worktree metadata, however, Git reported no top level fromouter/vendor, andreviews_checkacceptedouter/vendor/r.reviews/.locks/h/o/r/1. The discussion saysclone_problemcatches higher ancestors, but it relies on that same failed Git probe. The run can therefore create.locksand the review checkout insideouter.- Walk the physical ancestors above the clone’s parent for
.gitentries before creating.reviews. Extend the existing offline-worktree test by putting the clone undervendor/and asserting that no.reviewsdirectory appears.
- Walk the physical ancestors above the clone’s parent for
-
F22 · [lib/worktree.sh:139] — The overlap check can still compare the wrong state directory before a destructive reset. The case-only alias from round 4 is fixed. A symlink followed by
..still defeats the identity check:missing_pathuses logicalcdand only then callspwd -P. In a temporary fixture,currentpointed toworktree/sub, and both the outer directory and the worktree hadstate/h/o/r/7. The shell’s-eftest confirmed thatcurrent/../state/h/o/r/7was the state directory inside the worktree, butpaths_overlapreturned false. Theclean -fdqat line 359 can then delete the saved rounds.- Use
cd -Pwhen entering the existing path, and propagate a failedcdrather than masking it withprintf. Test with both possiblestatedirectories present; that is what makes logical traversal succeed at the wrong one.
- Use
-
[lib/clones.sh:203] — The two supported spellings of the HTTPS host share a cache but not the PR lock or round pins. The cache fix makes both
ghe.local:443andghe.localusable for the same repository. Yetgh-pr-review:423andgh-pr-review:571derive the state directory andPR_KEYfrom the original host. I checked that the lookup keys are identical and the lock keys differ. Two invocations for the same GitHub PR can therefore both enter review; even sequentially, switching spellings misses the earlier worktree andround-<K>-basepin.- Use one canonical host for local PR identity as well as clone lookup, while retaining the requested authority for network calls if needed. A two-round test that switches spellings should reuse the same worktree and pin; a concurrent run should see the held lock.
💡 Minor (Nice to Have)
(none found)
Fixed since the last round (3)
- F18 — Stale-lock takeover no longer recursively deletes the lock directory; unexpected contents, including completed rounds, stay in place.
- F19 — The cache lookup key and its HTTPS remote now agree on explicit
:443, while distinct non-default ports retain distinct cache paths. - F20 — A failed PID read through an unsearchable parent is now reported, and the lock is left untouched.
Recommendations
Keep the existing preservation assertions when adding the two path fixtures. For the host-alias case, exercise two invocations rather than only comparing normalized strings: the behavior to preserve is one lock, one worktree, and one posted-round baseline per PR.
Assessment
Ready to merge? No
Reasoning: Lock cleanup and default-port cache validation are fixed. The remaining path checks can still write into an unrelated checkout or let cleanup delete saved rounds, and the newly supported host alias can split one PR across two locks.
Review generated by gh pr-review · model: azure-openai-direct/gpt-6.2-astra
…th, not only in the clone's folder reviews_check looked for a .git of any kind (has_dotgit) in .reviews and in the folder it is in only. Git, run below a checkout whose .git it cannot read (a linked worktree whose clone is gone), sees no checkout, so with the clone at outer/vendor/r and outer/.git such a file, the lock and the review worktree were made inside outer. dotgit_above now walks every folder above .reviews, up to /, and the check names the one with the .git, before anything is made.
…ymlink>/.." is above the symlink's target missing_path entered the existing part of a path with a logical cd, which takes "<symlink>/.." as the folder the symlink is in, and cut missing parts by name. With current -> worktree/sub and a state folder both beside current and in the worktree, current/../state was taken for the outer one: no overlap, and the reset's clean deleted the saved rounds. missing_path now takes the path part by part from /, entering symlinks with cd -P and ".." as the physical parent, and fails (a refusal for its callers) when a symlink cannot be entered or ".." follows a part that is not a folder, instead of printing half a path. Every cd that resolves a path in lib/worktree.sh is now cd -P.
…nd ghe.local share its state folder, lock, refs and worktree host_key (lib/clones.sh) gives the host as repo_key does: lowercase, without https's default port, other ports kept. The run computes PR_HOST once from the URL's host and names the PR's state folder, PR_KEY (the clone's lock, refs and review worktree) and the clone lookup with it, so a run given either spelling finds the other's lock, worktree and round pins. GH_HOST_NAME, as given, stays for gh, the URL git fetches from (find_clone takes it for a cache clone) and the links the run prints.
…s one in a working tree: the cache clone instead Round 5's F4 fix refuses a .reviews folder below such a .git (reviews_check), but the lookup still picked that clone from the scan, the config or clones.json, so the run stopped with an error where a working tree git can read gives a note and the cache clone. clone_problem now asks dotgit_above too; has_dotgit and dotgit_above move to lib/clones.sh, which lib/worktree.sh already uses.
|
Thanks for round 5. All three items are fixed, each with tests that failed on the code before its fix (controls that pass on both are labelled), and the recommendations are in: both path fixtures keep the preservation assertions, and the host alias is tested with two invocations, not only with normalized strings. Important
Both halves were made in parallel and merged in
|
catalan-adobe
left a comment
There was a problem hiding this comment.
Round 6 · since round 5
2 fixed · 1 still open · 3 new (3 in the new commits) · open blocking: 2 (was 3) · loop: converging
Approach
Unchanged since round 5: gh-pr-review now uses one canonical host for each PR’s state, locks, worktree and round pins, while the stricter path checks stay in lib/clones.sh and lib/worktree.sh without changing either review pass.
Approach: Sound
Strengths
- [lib/clones.sh:184] — Clone discovery and worktree creation now use the same ancestor check. The tests at
tests/worktree.sh:526–538verify not just that an offline outer checkout is refused, but that its files and permissions stay unchanged. - [tests/flow.sh:1710–1729] — Removing the previous base SHA from the round marker makes the alias test meaningful: round 2 can be incremental only if it finds round 1’s pin. The assertions also check the actual worktree and refs, not just two normalized strings.
Issues
🚨 Critical (Must Fix Before Merge)
(none found)
⚠️ Important (Should Fix)
-
F23 · [gh-pr-review:465] — An explicit
:443URL still cannot complete a review with the realghCLI. The on-disk keys now agree, butoperator_loginpasses the original authority togh api --hostnameatlib/rounds.sh:142. I checked withgh2.97.0:gh api --hostname ghe.local:443 userreturnserror parsing '--hostname': invalid hostnamebefore making a request. The run therefore exits before it can take or observe the shared lock. The flow stub accepts an argument the real CLI rejects.- Use the canonical host for
ghcalls on the default HTTPS port; the original Git fetch URL can stay unchanged. For non-default ports, preserve the port through a mechanismghaccepts, such asGH_HOSTforgh api. Make the stub reject port-bearing--hostnamevalues so the two-round test covers this boundary.
- Use the canonical host for
-
[lib/worktree.sh:334] — A reset can remove the route to an active state directory even when its final location is outside the worktree. Consider the reverse of the new F22 fixture: an untracked
currentsymlink inside the review worktree points to an externalreleases/one, andGH_PR_REVIEW_STATEis<worktree>/current/../state. With both possiblestatedirectories present, I verified that the old logical lookup selected the inner directory while the new check reports the physical paths as disjoint. That physical result is correct, but the run still uses the original pathname.clean -fdqat line 380 removescurrent; subsequent state writes and lock release no longer address the directory where the run took its lock.- Before resetting, refuse a state path that depends on an entry the reset can remove, even if its final target is outside. Add the reverse fixture and assert that both the configured path to the saved round and the original lock lifecycle survive.
💡 Minor (Nice to Have)
-
[lib/worktree.sh:111] —
missing_pathtreats a dangling symlink as a missing directory because it checks! -dbefore-L. I verified that it returns success fordangling/foo, contrary to its fail-closed contract. This can defer refusal until afterprivate_mkdirhas created parents or changed.reviewspermissions. Check for a symlink before classifying the component as missing, and add a dangling-link case alongside the permission-denied test. -
[lib/clones.sh:87] — The new host validator rejects a fully qualified DNS name ending in a root dot, such as
ghe.local.. The earlier PR-key code accepted it, and the realgh api --hostnameparser accepts it too. Accept one terminal dot and normalize it for local identity; continue rejecting empty interior labels such asghe..local.
Fixed since the last round (2)
- F4 — Both discovery and destination validation now detect an unreadable
.gitat any ancestor depth before creating the review lock or worktree there. - F22 — The reported outside-in
current/../statealias now resolves to the state directory inside the worktree, and the overlap check refuses the reset.
Recommendations
Keep the real-Git fixtures, but add a small offline check of the real gh argument parser for the host forms the README promises. It catches the --hostname failure without credentials or a live Enterprise server.
Assessment
Ready to merge? No
Reasoning: The original ancestor and overlap cases are fixed, and the local host keys now agree. The documented explicit-port invocation still fails before locking, and cleanup can invalidate the pathname of a lock the run already holds.
Review generated by gh pr-review · model: azure-openai-direct/gpt-6.2-astra
|
Thanks for round 6. As agreed, this was the last round: it has no critical findings, so the four items left are in #17, each with a suggested fix and the test that would cover it.
The head is still |
PR 3c of review tracking: review in a worktree of your local clone, with private refs per PR. Tasks 2 and 3 of
docs/superpowers/plans/2026-11-26-review-tracking-pr3-local-worktrees.md(see the plan's "Changes after PRs #8, #9 and #10"). Stacked on #13 (3a), whose state folder andpr.jsonit uses. Once #13 merges, this PR will show only its own changes.lib/clones.shandlib/worktree.shstarted from an earlier, never-merged branch and were adapted to the current code.Where the review runs
Finding the clone, first match wins:
--clone <path>.clonesmap.clones.json), kept only while a remote still matches.roots(default~/repos). With several matching clones, the one fetched most recently (newestFETCH_HEAD) wins.~/.cache/gh-pr-review/clones/.Shallow and partial clones are skipped with the reason. The run prints
clone: <path> (<kind>).Fetching: the PR head and base go into private refs
refs/pr-review/<N>/head|base. Every git call against your clone runs with hooks off, and refs come after--end-of-options.The review worktree: pi runs in a detached worktree at
<clone>.reviews/<branch-slug>/<N>.pr.json. A dirty reused worktree is reset, with a warning.HEAD, index, stash, config, remote-tracking refs and working tree are never touched.After a post,
refs/pr-review/<N>/round-<K>and…-basekeep the reviewed commits, with K being the posted record's round. So a force-push between rounds givesrebased, notfull.full, and a missing SHA is fetched by SHA, now from the PR's URL rather thanorigin, which may be a fork.--freshkeeps today's behaviour: a depth-50 throwaway clone in the run folder, with the deepen-by-200 fallback in that mode only.When #14 lands
#14 (the read-only reviewer) snapshots
$REVIEW_DIRas both clone and worktree. With this PR, its twotripwire_snapshot "$REVIEW_DIR" "$REVIEW_DIR"calls becometripwire_snapshot "$CLONE_DIR" "$REVIEW_DIR". Whichever of the two merges second makes that one-line change.Tests
tests/clones.sh(40 checks, real git, no network):FETCH_HEADtie-break;origin;insteadOf.tests/worktree.sh(61 checks):main, names with/, 200 characters, spaces and unicode;rebasedwith the refs,fullwithout them;mark_roundrefusing bad input;tests/flow.sh: the stubbed runs use--fresh. A new real-git case scans~/repos, reviews inr.reviews/h/1, setsround-1and its base, runs round 2 after a force-push asrebased, and leaves the clone unchanged.All tests pass on macOS (bash 5 and 3.2) and Ubuntu 24.04, and shellcheck and shfmt are clean. This PR's own diff: 8 files, about +810 −34.