Skip to content

Review in a worktree of the local clone, with private refs per PR - #16

Merged
catalan-adobe merged 66 commits into
mainfrom
review-worktrees
Nov 29, 2026
Merged

catalan-adobe merged 66 commits into
mainfrom
review-worktrees

Conversation

@catalan-adobe

Copy link
Copy Markdown
Owner

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 and pr.json it uses. Once #13 merges, this PR will show only its own changes. lib/clones.sh and lib/worktree.sh started from an earlier, never-merged branch and were adapted to the current code.

Where the review runs

  • Finding the clone, first match wins:

    1. --clone <path>.
    2. The config file's clones map.
    3. A remembered pick (clones.json), kept only while a remote still matches.
    4. A scan of the config's roots (default ~/repos). With several matching clones, the one fetched most recently (newest FETCH_HEAD) wins.
    5. A bare cache clone under ~/.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>.

    • Later rounds reuse it through pr.json. A dirty reused worktree is reset, with a warning.
    • A folder already at that path that isn't a registered worktree is never deleted: the run fails and names it.
    • Your clone's branches, HEAD, index, stash, config, remote-tracking refs and working tree are never touched.
  • After a post, refs/pr-review/<N>/round-<K> and …-base keep the reviewed commits, with K being the posted record's round. So a force-push between rounds gives rebased, not full.

    • The next round reads the previous head and base from these refs first, then from the record.
    • Build round 2 and later on the last code review #9's rules still apply: an unknown base means full, and a missing SHA is fetched by SHA, now from the PR's URL rather than origin, which may be a fork.
  • --fresh keeps 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_DIR as both clone and worktree. With this PR, its two tripwire_snapshot "$REVIEW_DIR" "$REVIEW_DIR" calls become tripwire_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):
    • URL normalisation in all three forms;
    • the lookup order, and the FETCH_HEAD tie-break;
    • a matching remote not called origin;
    • shallow and partial clones skipped with the reason;
    • linked worktrees never picked;
    • the cache clone through insteadOf.
  • tests/worktree.sh (61 checks):
    • branch names: a fork whose head branch is main, names with /, 200 characters, spaces and unicode;
    • your own PR's branch checked out in the clone;
    • a folder in the way left in place;
    • a dirty reused worktree reset;
    • a clone hook that never runs;
    • after a force-push: rebased with the refs, full without them;
    • mark_round refusing bad input;
    • the clone unchanged after every step.
  • tests/flow.sh: the stubbed runs use --fresh. A new real-git case scans ~/repos, reviews in r.reviews/h/1, sets round-1 and its base, runs round 2 after a force-push as rebased, 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.

@catalan-adobe catalan-adobe left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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_HEAD write and no submodule recursion handles the common fork setup without moving origin/*.
  • [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.sh and tests/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 --approve at 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_DIR and REVIEW_DIR as distinct inputs, before enabling the shared checkout by default. Until then, keep the throwaway checkout as the default.

⚠️ Important (Should Fix)

  • [lib/clones.sh:52] — rev-parse --git-dir succeeds in any subdirectory of a repository. Passing --clone /repos/r/src therefore sets CLONE_DIR to src and 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] — -C does not override inherited GIT_DIR, GIT_WORK_TREE or GIT_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 prune across 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 a and b: with only a selected, the detached worktree also contained only a. A PR changing b therefore 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 roots disables the documented ~/repos scan. The arrays filter emits no value for a missing key, so config_get never 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 roots before filtering by type, while preserving an explicitly empty array. Add a lookup test with a config containing only clones and no remembered pick.
  • [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 independent update-ref calls 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 --stdin transaction.

💡 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

@catalan-adobe

Copy link
Copy Markdown
Owner Author

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 (22a0a2d).

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 (cfff879 on #13), and the merge order is #13 and #14 first; then this branch gets main merged in and wires tripwire_snapshot "$CLONE_DIR" "$REVIEW_DIR" and the read-only git around both passes before it merges.

Critical

Important

  • lib/clones.sh:52 (subfolder, linked worktree, bare repo accepted as the clone): 1ce77db. A --clone, config or clones.json path is resolved to its main clone, with a note; a path that is not a clone's top folder is rejected, and review_worktree refuses one too. A clone whose .reviews folder would land inside another working tree is skipped. Tests for each case.
  • lib/clones.sh:8 (inherited GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE): 23787b3. New git_env_clear runs once at startup and unsets the repository-routing variables (GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE, GIT_OBJECT_DIRECTORY, GIT_ALTERNATE_OBJECT_DIRECTORIES, GIT_COMMON_DIR, GIT_NAMESPACE, GIT_CEILING_DIRECTORIES); GIT_CONFIG_* and credentials stay. Flow test: with GIT_DIR/GIT_INDEX_FILE exported at another repo, that repo is untouched.
  • lib/worktree.sh:77 (clone-wide git worktree prune): 69a35ed. Gone. The destination is checked first; only a registration at exactly this missing path is replaced (worktree add --force), and a locked one is refused. Test: an unrelated missing worktree keeps its registration and works again once back.
  • lib/worktree.sh:84 (sparse checkout inherited): 9e748c0. A sparse clone is skipped with the reason "sparse checkout", which leads to the cache clone. Disabling sparse checkout in the new worktree could write the clone's shared config, so nothing is written: config is only read. Tests: skipped, stays sparse and unchanged; an explicit --clone to a sparse clone is an error.
  • lib/clones.sh:112 (config without roots disables the ~/repos scan): 7805b94. Missing, null or "" roots keep the default scan; [] turns it off. Tests with a config holding only clones.
  • lib/worktree.sh:124 (pinned base trusted over the record; two separate ref writes): 29958fb. A pin pair is used only when both refs agree with the record's head and base (an empty value in the record counts as agreeing), and both refs are written in one update-ref --stdin transaction. Tests: a retarget on the same head uses the record; a failed write leaves the old pair.

Minor

  • lib/worktree.sh:87 (dirty-worktree warning only on stderr): ec6a9de. Also appended to the run folder's warnings.txt (listed in the README).

Recommendation (tests/flow.sh:1445, state cleared between local rounds): e20b890. run_local no longer clears the PR state; round 2 renames the head branch (h-renamed) and must reuse the saved worktree. With the clearing put back, these tests fail.

All test files pass on macOS (bash 5) and ubuntu:24.04; clones, worktree and flow also under /bin/bash 3.2. shellcheck and shfmt are clean.

@catalan-adobe
catalan-adobe changed the base branch from review-state-folder to main November 28, 2026 18:34
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.
@catalan-adobe

Copy link
Copy Markdown
Owner Author

#13, #14 and #15 are merged, so this PR now targets main, has it merged in (9a9c0c8), and closes the third round-1 Critical (gh-pr-review:525, no read-only git or before/after checks around the passes in the shared checkout).

Wiring (d789e21): run_pi snapshots tripwire_snapshot "$CLONE_DIR" "$REVIEW_DIR" … "$PR_REFS" before and after each pi call, so both passes run in the review worktree inside pi_env (read-only git), with the user's clone and the review worktree as distinct inputs. With --fresh both are the same throwaway clone.

  • Exit 4, nothing posted, the run folder kept: the review worktree's HEAD and status; its own refs (refs/worktree/, refs/bisect/, refs/rewritten/); this PR's own refs/pr-review/<key>/* (nothing else writes them while pi runs: the run fetches before and pins after the passes, one run per PR at a time); and a new stash entry made in the review worktree. The stash is shared with the clone, so this is the round-1 example. Such an entry is told apart reliably: its commit's first parent is the review worktree's HEAD and its subject is WIP on (no branch): / On (no branch):, which git writes for a detached HEAD whatever message is given. On exit 4 the entry is left in place and named. One false positive, documented: the user stashing in their own clone while detached at exactly the PR head during a run.
  • Warning, posted, saved in warnings.txt: the clone's refs, its HEAD as seen from the clone, and its stash otherwise (a commit, branch or stash on a branch the user makes while pi runs). Other PRs' refs/pr-review/ folders are not watched.
  • The run itself writes nothing between a before and an after snapshot: fetch_pr, review_worktree and pick_delta run before the passes, mark_round after, and fetches use explicit refspecs with --no-write-fetch-head.

Tests, in local-clone mode with real git: both passes run in the review worktree with the read-only git (stash, checkout -b refused); both are snapshotted; a commit past the wrapper in the review worktree exits 4 and leaves the user's clone unchanged (refs, HEAD, index, stash, config, files); a branch, a detached HEAD on the same commit, or a stash on a branch in the user's clone only warns and posts; a stash entry made in the review worktree exits 4; the PR's own private refs moved exits 4; a control that the user's clone is unchanged after all of these. Also --fresh: a stash on its HEAD exits 4. Unit tests in tests/guard.sh for each rule (an entry stored from the worktree with any message, another PR's refs not watched, a refs/worktree/ ref). The ones marked in the commit failed before the wiring.

Docs (e4b91fb): README and design spec say both passes run with the read-only git and the tripwire in the review worktree, and list what is exit 4 and what is a warning in local-clone mode.

All 13 test files pass on macOS (bash 5) and ubuntu:24.04; flow, guard, passes, worktree and clones also with the extension under /bin/bash 3.2. shellcheck and shfmt are clean. Round 2 is next.

@catalan-adobe catalan-adobe left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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:141 locks 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:1675 checks the clone snapshot’s actual HEAD, so passing the worktree twice would fail the test.
  • [tests/flow.sh:1606] — Round 2 now preserves pr.json and 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 --clone pointing to a symlink inside another checkout, I got a new dep.reviews/ in that checkout’s git 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 prune is gone, but git fetch enables auto-maintenance by default. In a temporary clone above its auto-GC threshold, I traced fetch_pr invoking git worktree prune --expire 3.months.ago; it removed the registration of an unrelated, offline worktree with an old index. Pass --no-auto-maintenance on 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_CONFIG redirects git config without redirecting checkout. With GIT_CONFIG=/dev/null and an explicit sparse clone, find_clone accepted it and the review worktree lacked a tracked directory. Remove GIT_CONFIG for discovery queries, as git_env_config already 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 HEAD was 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 created 0755. A clone protected by its own 0700 directory 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=./state from 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 first worktree add upgrade core.repositoryformatversion and set extensions.relativeWorktrees. Round 2 then rejected its own worktree as “in the way”: the relative gitdir backlink 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/null does not disable a hook configured through core.fsmonitor. I observed that hook run during worktree creation and reuse, before pi’s guard applies. Apply the same core.fsmonitor=false override 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_DIR and GIT_WORK_TREE but leaves GIT_INDEX_FILE set. If a hook or task launches it with an absolute index path, even the first fixture git add at line 56 targets that index. tests/clones.sh:16 has 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 by clean -fdq with neither a console warning nor a warnings.txt entry. Request untracked files explicitly and check status’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 roots retains the ~/repos scan; 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.
…ree outside .reviews, a .reviews that is a checkout
@catalan-adobe

Copy link
Copy Markdown
Owner Author

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: tests/flow.sh now has whole runs that start from a layout an earlier version left behind.

Important

  • F18, lib/state.sh:67 (a lock claims and deletes the PR's state folder): two parts. 58a5fd8 introduced this when it made a folder without a pid file claimable.
    • 64e8a03: an existing folder counts as a lock only when the pid file the run just made (still with O_EXCL) is all it holds. A folder without a pid file that holds anything else is not a lock. The run removes the pid file it made, fails at once with an error that names the folder, and leaves the folder as it is. Locks that have a pid file work as before, including the takeover of a dead run's lock. The rm -rf "$lock/clone" that 58a5fd8 added to cache_clone_make is gone.
      • Tests: a fixture with round-1/, pr.json and lock/pid is refused, named, refused at once, and left exactly as it was, even after the run's own release. A cache lock without a pid file that holds a clone is refused and left untouched.
    • 2cc8a9f: clone_lock refuses, naming both paths, when the clone lock and PR_STATE_DIR overlap (the same folder, or one inside the other, compared by physical path). It does this before anything is made. review_worktree does the same for the worktree and the state folder: a state folder inside a reused worktree would have been deleted by its git clean.
      • Tests: equal, state inside the lock, lock inside the state folder, state inside the worktree, worktree inside the state folder. In each case the runs, pr.json and the lock survive. A flow case with GH_PR_REVIEW_STATE=<clone>.reviews/.locks stops before the fetch, with no model call, and keeps its rounds.
  • F19, lib/clones.sh:300 (cache clone of an HTTPS host with a port): c15e319.
    • normalize_remote keeps the port of an http(s) URL, except the scheme's default (:443, :80). ssh, git and scp-style remotes drop the port, as before, because it belongs to their transport.
    • clone_matches compares an http(s) remote with the whole key. It compares an ssh or scp-style remote with the key's host without its port, so git@ghe.local:o/r matches ghe.local:8443/o/r.
    • Tests: 9 normalize_remote cases and 8 clone_matches cases. A bare clone of https://ghe.local:8443/o/r.git passes cache_clone_problem. The cache clone for that host is made and then used again, and a user clone with that https remote is found by the scan.
  • F4, lib/worktree.sh:139 (the clone lock writes into another checkout): 1fb9dde.
    • A new reviews_check runs before any mkdir or chmod, in clone_lock and at the start of review_worktree (so before the reuse branch's chmod 700).
    • It refuses a <clone>.reviews that is a symlink, is not a folder, is not yours, or is (or is inside) a working tree or a repository. Given a path, it also refuses one that leads into a working tree or out of .reviews.
    • Tests go through clone_lock: a .reviews that is another checkout, and a symlink to one, are refused, naming it; that checkout's mode, files and status are unchanged, and no .locks is made. A .locks symlink out of .reviews is refused, and nothing is made where it leads. A plain .reviews at 0755 still works and becomes 0700 (a control; it passes on the old code too).
  • F12, lib/worktree.sh:218 (a reused worktree outside the private folder): 0b68d82.
    • A saved worktree, and the default one, are reused only when their physical path is under the checked .reviews.
    • A saved worktree elsewhere is left as it is and not used. A warning names it and gives the git -C <clone> worktree remove <path> command; the warning goes to stderr and the run's warnings.txt. A private worktree is then used or made under .reviews.
    • Tests: a worktree made beside a symlink to the clone under umask 022 (0755 folders, 0644 files, an untracked file) is not reused, keeps its contents and modes, and is named in the warning. The folder the review works in has a 0700 ancestor.

Minor

  • F17, lib/clones.sh:281 (publishing across file systems): fc4c7cf.
    • The cache clone is made in mktemp -d "<path>~clone.XXXXXX", beside its place and still under the lock, then renamed in. A ~ is in no repo name, and a bare clone has no .git, so the scan never picks the staging folder up.
    • A failed clone removes the staging folder. One left by a killed run is removed by the next run that makes the cache clone, under the lock. The lock folder now holds only its pid file.
    • Tests: with a git stub that records where it clones, the clone is made beside its place under a ~ name with nothing left beside it, a killed run's staging folder is removed, and a failed clone leaves nothing.
  • F20, lib/state.sh:75 (a failed removal reported as success): 42de466.
    • lock_remove counts an already-absent lock as removed. Any other failure gives Error: could not remove the lock: <path> and returns 1.
    • A takeover that can't remove the dead run's lock now stops at once, where it used to retry 100 times. The release on exit (pr_unlock, the clone lock in run_exit) and after a cache clone reports the failure, and the run's exit status stays the same.
    • Tests: with a read-only parent, the release names the lock, the lock is still there, and the run keeps its exit status. With mv stubbed, a takeover is refused once and leaves the dead run's lock and no takeover lock.
  • F21, tests/worktree.sh:420 (the replacement control inherits GIT_NO_REPLACE_OBJECTS): 0f06df4. The fixtures of tests/worktree.sh and the flow's real-git setup unset it. I also added a matching control to flow, which didn't have one. With GIT_NO_REPLACE_OBJECTS=1 exported, worktree.sh gave 130 ok and 1 FAIL before; both files pass with it exported now.

Recommendation: 4da43c0. Two flow cases start from layouts an earlier version would have left.

  • A saved worktree outside .reviews with a 0755 .reviews: pi works in a new worktree under .reviews, which is made 0700. The old worktree keeps its contents and modes, and the warning is kept.
  • A .reviews that is another checkout: refused before the fetch, naming it, with no model call; its mode, files and status are unchanged.

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 8ebdb14.
Results on 8ebdb14:

  • CI (run, ubuntu-26.04): passes, 1501 checks, 0 FAIL, none skipped.
  • Ubuntu 26.04 (git 2.53, uutils mkdir 0.10, shellcheck 0.11): every test file passes, 1501 checks; lint is clean. The lock stress test (300 rounds of 3 processes) gave 900 entered with 0 overlaps, and tests/clones.sh passed 20 of 20 runs.
  • macOS bash 5.3 (git 2.55): the same 1501 checks pass, with none skipped.
  • macOS /bin/bash 3.2: state 115, clones 122, worktree 149, guard 119 and flow 334 all pass.
  • ubuntu:24.04 (git 2.43): every file passes; worktree.sh has 147 checks there, because the 2 relative-path checks need git 2.48.

@catalan-adobe catalan-adobe left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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/ and clones/ 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 .reviews directory whose .git file points to an offline linked-worktree administration directory: reviews_check accepted it. clone_lock then creates .locks/ in that checkout and changes its root permissions to 0700.

    • Refuse a destination with a .git entry even when Git cannot resolve it. Test that an unavailable backlink leaves both the directory contents and its permissions unchanged.
  • 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 --fresh run with GH_PR_REVIEW_STATE=<clone>.reviews/.locks can save its round in that directory: it takes the child PR lock but never calls clone_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 pid and a completed round, not just the PID-less case.
  • F19 · [lib/clones.sh:80] — Cache validation still rejects its own HTTPS remote when the target explicitly specifies port 443. The :8443 case is fixed. For https://ghe.local:443/o/r.git, however, normalize_remote removes :443 while the lookup key retains it. clone_matches returns 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 :443 target, while keeping distinct non-default ports separate.
  • [lib/worktree.sh:109] — The new overlap check can miss a state directory inside the worktree on case-insensitive filesystems. On macOS, paths_overlap reported no overlap between a worktree ending in BugFix/7 and an existing state directory reached through bugfix/7/.state/…. pwd -P preserved the supplied spelling. On reuse, the check at line 256 therefore permits git clean -fdq to 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 .reviews directory; 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).
@catalan-adobe

Copy link
Copy Markdown
Owner Author

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

  • F18, lib/state.sh:176 (takeover deletes what a lock folder holds): 860f150.
    • lock_remove no longer renames and rm -rfs. It deletes the pid file, then the folder with rmdir, which only works on an empty folder. Nothing else in a lock folder is ever deleted.
    • This is safe without a rename. No run can create a pid file while one is there (O_EXCL). Once it is gone, a run that claims before the rmdir keeps the lock, because rmdir fails on its pid file; a run that claims after finds no folder and tries again.
    • A dead run's lock that holds anything else is not taken over. Its dead pid is removed, the rest is left, and the run is refused, naming the folder. Later runs are refused by the round-3 rule.
    • On release of a lock that holds other files, the run's own pid is removed and a warning names the folder.
    • Tests:
      • Unit: a dead lock with pid, round-1/ and pr.json is not taken over, and its files are readable at their paths. A release with an extra file removes only pid and warns. Controls: normal release and takeover still remove the folder.
      • Flow, reached as you described: a dead clone lock, then a --fresh run with GH_PR_REVIEW_STATE=<clone>.reviews/.locks saves its run there, then a normal local run. That run is refused with no fetch and no model call, and the saved run is still readable.
      • tests/clones.sh: a killed run's cache lock holding a leftover clone is now refused and left as it is, as intended.
  • F4, lib/worktree.sh:154 (failed git probes taken as "not a repository"): 3f7df1b.
    • New has_dotgit: a .git of any kind (file, folder or symlink, broken or not) counts as a checkout, whether or not git can read it.
    • reviews_check refuses one in .reviews, in the folder .reviews is in (the clone's parent), and in every existing folder on the way to the lock or worktree path. The reuse branch checks the way to the saved worktree before it resets it.
    • Nothing above the clone's parent is checked: a .git there would put the clone itself in that checkout, which clone_problem reports.
    • Tests: a .git file pointing to a missing admin folder, an empty .git folder, a broken .git folder and a broken .git symlink, each through clone_lock and review_worktree. Each is refused with the folder named, its mode and files unchanged, and no .locks. Also tested: a .git on the way inside .reviews, and in the clone's folder. A flow case is refused before the fetch. Control: a .reviews holding .github and .gitignore still works.
  • lib/worktree.sh:109 (overlap missed on case-insensitive file systems): 6a76a80.
    • paths_overlap keeps the exact string match, then compares existing folders by identity (-ef, walking up from the nearest existing folder) instead of by spelling. There is no lowercasing.
    • A path whose last parts don't exist can't hide existing data. If the other path exists, the missing one is inside it exactly when its nearest existing folder is. If neither exists, they overlap only through the same nearest existing folder and the same missing names.
    • The other path comparisons in lib/worktree.sh (owned_worktree, is_worktree_of, the "inside .reviews" reuse check, the "leads out of" check) can only refuse or skip reuse on a spelling mismatch, never reset or delete, so they stay as they are.
    • Tests:
      • On a case-insensitive volume, detected with a probe file:
        • A state folder inside the worktree through another spelling: refused, with no reset, and the saved round still at its path.
        • A state folder equal to the clone lock through another spelling: refused.
        • A worktree inside the state folder through another spelling: refused.
      • The flow case: …/H/1/.state against the worktree …/h/1. It is refused, with no model call, and the saved round is kept.
      • On a case-sensitive volume (Linux CI): case-sensitive controls run instead (both spellings are distinct folders, and nothing is refused). The alias checks print skip.
  • F19, lib/clones.sh:80 (explicit :443 in the key): 039e52c.
    • New repo_key runs the key through the same normalize_remote as the remotes. clone_matches, find_clone's scan, the clones.json lookup (both the clones config map and the remembered clones) and the cache check all use it.
    • :443 and no port are now one host, so they share one cache clone, and :8443, :9443 and no port stay distinct. PR_KEY (the state folder and the refs/pr-review/… refs) keeps the host as given, since it is never compared with a remote.
    • Tests: a cache clone is made with an explicit :443 target, reused, and reused for plain ghe.local. The scan finds a clone and remembers it under the normalised key, and a clones-map key GHE.local:443/o/r works. Controls: separate :8443/:9443 cache clones, and ssh mismatches.

Minor

  • F20, lib/state.sh:201 (a release that can't read the pid): 2ce696a. A pid file counts as confirmed absent only when its folder exists and can be searched. Otherwise lock_release reports that it could not read the lock's pid file, returns 1, and deletes nothing; the exit handlers keep the run's status. Tests: a lock under a folder that can't be searched gives an error and is still there, and a run in that situation keeps exit 3. Controls: a missing lock, or one whose folder is missing, is released silently.

Both halves were made in parallel and merged in 84ed25d.
Results on 84ed25d:

  • CI (run, ubuntu-26.04): passes, 1565 checks, 0 FAIL, and the 2 case-alias checks skipped on its case-sensitive volume.
  • Ubuntu 26.04 (git 2.53, uutils mkdir 0.10, shellcheck 0.11): every file passes, 1565 checks, with 2 case-alias checks skipped (case-sensitive volume). Lint is clean. The lock stress test (300 rounds of 3 processes) gave 900 entered, 0 overlaps and nothing left, and tests/clones.sh passed 20 of 20 runs.
  • macOS bash 5.3 (git 2.55, case-insensitive APFS): every file passes, 1566 checks, with the 2 case-sensitive controls skipped.
  • macOS /bin/bash 3.2: state 129, clones 142, worktree 174, guard 119 and flow 340 pass.
  • ubuntu:24.04 (git 2.43): every file passes; worktree.sh has 171 checks there, since its 2 relative-path checks need git 2.48.

@catalan-adobe catalan-adobe left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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 pid and uses rmdir for the directory. That protects saved rounds even if another file appears during cleanup. The flow test at tests/flow.sh:1827 verifies 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 .git check protects .reviews and its immediate parent. With the clone at outer/vendor/r and outer/.git pointing to unavailable worktree metadata, however, Git reported no top level from outer/vendor, and reviews_check accepted outer/vendor/r.reviews/.locks/h/o/r/1. The discussion says clone_problem catches higher ancestors, but it relies on that same failed Git probe. The run can therefore create .locks and the review checkout inside outer.

    • Walk the physical ancestors above the clone’s parent for .git entries before creating .reviews. Extend the existing offline-worktree test by putting the clone under vendor/ and asserting that no .reviews directory appears.
  • 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_path uses logical cd and only then calls pwd -P. In a temporary fixture, current pointed to worktree/sub, and both the outer directory and the worktree had state/h/o/r/7. The shell’s -ef test confirmed that current/../state/h/o/r/7 was the state directory inside the worktree, but paths_overlap returned false. The clean -fdq at line 359 can then delete the saved rounds.

    • Use cd -P when entering the existing path, and propagate a failed cd rather than masking it with printf. Test with both possible state directories present; that is what makes logical traversal succeed at the wrong one.
  • [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:443 and ghe.local usable for the same repository. Yet gh-pr-review:423 and gh-pr-review:571 derive the state directory and PR_KEY from 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 and round-<K>-base pin.

    • 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.
@catalan-adobe

Copy link
Copy Markdown
Owner Author

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

  • F4, lib/worktree.sh:200 (an outer checkout git can't read, more than one folder up): a0733fe, and ca5074f for the lookup.
    • New dotgit_above walks every folder above .reviews, from the clone's folder up to /, for a .git of any kind (file, folder or symlink, broken or not). reviews_check refuses before anything is made and names that folder.
    • clone_problem asks the same question (ca5074f; has_dotgit and dotgit_above moved to lib/clones.sh). So a clone found by the scan, the config or clones.json below such a .git is skipped with a note, and the run uses the cache clone, just as when git can read the outer checkout. An explicit --clone is an error naming the folder and suggesting --fresh.
    • Tests: the clone at outer/vendor/r with outer/.git a file pointing to a missing admin folder, and with a broken .git symlink two folders up. clone_lock and review_worktree are refused, naming the folder, and no .reviews is made; outer keeps its files and modes. The scan skips such a clone, with a note naming outer, and uses the cache clone. Controls: a fixture where git sees no checkout above (your case), and a deep clone with no .git above it, which still works.
  • F22, lib/worktree.sh:139 (a symlink followed by ..): fac5a1b.
    • missing_path now resolves a path one part at a time from /. It enters symlinks with cd -P, takes .. as the parent of the real folder reached, and keeps parts that don't exist yet as names.
    • It fails, printing nothing, when a symlink can't be entered or .. follows a part that doesn't exist; it used to print half a path with status 0. paths_overlap takes that failure as an overlap, reviews_check refuses, and review_worktree checks it before its --force lookup.
    • Every cd that resolves a path in lib/worktree.sh is now cd -P.
    • Tests, with both state folders present and current pointing to worktree/sub:
      • paths_overlap reports the overlap.
      • review_worktree with PR_STATE_DIR=current/../state/h/o/r/7 is refused, naming both. Nothing is reset: the dirty file stays, and the saved round is still at its path.
      • The same through the clone lock is refused, and the round is kept.
      • A missing folder followed by .. is not compared by name.
      • Control: a .. that leaves the worktree without a symlink is not an overlap, and the worktree is reused.
  • lib/clones.sh:203 (two spellings of one host): 774ae49. This came from round 4's :443 change.
    • New host_key gives the host as repo_key does: lowercase, :443 dropped, other ports kept. It refuses anything that isn't a host with an optional port.
    • gh-pr-review computes PR_HOST once and uses it for the state folder (and so the PR lock), PR_KEY (the clone lock, the refs/pr-review/… refs and the worktree path) and the clone lookup.
    • The host as given stays for the network: gh --hostname, --repo, the clone URL, and the links the run prints. git hands host:port to the credential helper, so changing it could change which login is used. A cache clone is still made from the URL as given.
    • Nothing compares a stored host with the current one. The marker's pr.host is written, never matched, and pr.json has no host. So :443 against no port splits no rounds.
    • Tests:
      • host_key: ghe.local:443, GHE.local:443 and ghe.local are one host, :8443 is another, and github.com/GitHub.com are one; 10 malformed hosts are rejected.
      • Flow, two invocations: round 1 given ghe.local:443, round 2 given ghe.local. They share one state folder with both rounds, one pr.json, one worktree, one lock folder and one set of refs. Round 2 is incremental from the round-1 pin; the marker's base_sha is removed, so only round-1-base can supply the base.
      • Concurrent: while a run given ghe.local is held inside pi, a run given GHE.local:443 is refused, with no fetch and no model call.

Both halves were made in parallel and merged in 207d684; ca5074f is on top.
Results on ca5074f:

  • CI (run, ubuntu-26.04): passes, 1620 checks, 0 FAIL; the case-alias checks are skipped on its case-sensitive volume.
  • Ubuntu 26.04 (git 2.53, uutils mkdir, shellcheck 0.11): every file passes, 1620 checks, with the case-alias checks skipped on its case-sensitive volume. Lint is clean, the lock stress test gave 900 entered with 0 overlaps, and tests/clones.sh passed 20 of 20 runs.
  • macOS bash 5.3 (git 2.55, case-insensitive APFS): every file passes, 1621 checks.
  • macOS /bin/bash 3.2: state 129, clones 169, worktree 194, guard 119 and flow 348 pass.
  • ubuntu:24.04 (git 2.43): every file passes; worktree.sh has 191 checks there, with 2 skipped (relative paths need git 2.48, and the case-alias check needs a case-insensitive volume).

@catalan-adobe catalan-adobe left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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–538 verify 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 :443 URL still cannot complete a review with the real gh CLI. The on-disk keys now agree, but operator_login passes the original authority to gh api --hostname at lib/rounds.sh:142. I checked with gh 2.97.0: gh api --hostname ghe.local:443 user returns error parsing '--hostname': invalid hostname before 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 gh calls on the default HTTPS port; the original Git fetch URL can stay unchanged. For non-default ports, preserve the port through a mechanism gh accepts, such as GH_HOST for gh api. Make the stub reject port-bearing --hostname values so the two-round test covers this boundary.
  • [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 current symlink inside the review worktree points to an external releases/one, and GH_PR_REVIEW_STATE is <worktree>/current/../state. With both possible state directories 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 -fdq at line 380 removes current; 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_path treats a dangling symlink as a missing directory because it checks ! -d before -L. I verified that it returns success for dangling/foo, contrary to its fail-closed contract. This can defer refusal until after private_mkdir has created parents or changed .reviews permissions. 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 real gh api --hostname parser accepts it too. Accept one terminal dot and normalize it for local identity; continue rejecting empty interior labels such as ghe..local.

Fixed since the last round (2)
  • F4 — Both discovery and destination validation now detect an unreadable .git at any ancestor depth before creating the review lock or worktree there.
  • F22 — The reported outside-in current/../state alias 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

@catalan-adobe

Copy link
Copy Markdown
Owner Author

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 explicit :443 URL with the real gh (its --hostname rejects a port, as it already did on main; the flow stub hid it);
  • a state path that passes through an entry the worktree reset removes;
  • missing_path and a dangling symlink;
  • host_key and a host ending in a dot.

The head is still ca5074f, and CI is green on it (1620 checks).

@catalan-adobe
catalan-adobe merged commit c3ca004 into main Nov 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant