fix(codex-review): fetch PR head/base from the gh-resolved repo, not literal origin - #58
Conversation
…literal origin In a fork workflow (origin = your fork, upstream = the canonical repo PRs target), `gh` resolves the PR on the canonical repo while the fetch used the literal `origin` remote — which lacks the PR ref (fetch fails) or resolves a same-numbered unrelated PR (wrong diff). Point the fetch at the canonical URL `https://github.com/$repo.git`, where `$repo` is the nameWithOwner `gh` resolved, so the source is provably the repo the review is bound to. Both PR head and base now land in private, review-owned refs under `refs/codex-review/` instead of a remote-tracking ref tied to a remote name: keeps destinations independent of which remote `origin` is and avoids clobbering the operator's `origin/<base>`. The base ref is dropped in the cleanup trap once `--base` has read it (the head ref is deleted immediately after its SHA is captured, as before). Preserves: read-only sandbox, comments-only, verbatim posting, the real Reviewed-head:/Reviewed-base: SHAs, --no-tags, and the narrow destination refspecs. Doc note added to reviewer/codex-review.md. Closes #56 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codex reviewer (cross-vendor, read-only)Reviewed-head: 8c2e373 Posted verbatim by The patch introduces a synthesized github.com fetch URL that breaks gh-recognized repositories on other hosts, and the new shared temporary base ref is unsafe for concurrent reviews. These issues can prevent or invalidate the review workflow in supported scenarios. Full review comments:
|
…que fetch refs Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Round-1 review fixes applied (head 1. gh-resolved, host-correct clone URL (GHE-safe). The fork-safe fetch now sources from the clone URL 2. Per-run-unique fetch refs (no concurrent-review collisions). The fetch destinations are now namespaced per run: CI green locally: |
Codex reviewer (cross-vendor, read-only)Reviewed-head: 9ece0d0 Posted verbatim by The updated fetch path can break the reviewer for common private-repo or SSH-authenticated setups despite valid gh authentication. That makes the patch unsafe as-is. Review comment:
|
Codex round-1 [P2]: the fetch synthesized gh's HTTPS web URL
(`git fetch "${repo_url}.git"`), which carries no credentials — so on
private repos or SSH-only-authenticated checkouts the fetch failed even
though `gh auth status` passed and `origin` worked, aborting the review
before Codex ran.
Replace the synthesized-URL fetch with remote-matching: resolve gh's
canonical host + owner/repo, normalize each configured git remote's URL
(scp-style SSH, ssh://, https; trailing `.git` stripped; case-insensitive)
and fetch from whichever remote name matches (preferring `origin`). This
uses the operator's own authenticated transport (fork-safe + host-correct
on GHE + auth-correct). If no configured remote matches the gh-resolved
repo, refuse with an actionable error and non-zero exit — never fall back
to an unauthenticated synthesized URL.
Per-run-unique refs, cleanup trap, `--no-tags`, fully-qualified refspecs,
forced read-only sandbox, comments-only, and the Reviewed-head/base markers
are all preserved. Doc updated to match. Live behavior unchanged until the
operator re-runs the script (no install.sh sync needed for the reviewer
harness).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Coder — round-1 fix (now round-2), head
|
Codex reviewer (cross-vendor, read-only)Reviewed-head: ee75ac8 Posted verbatim by The changes appear consistent with the stated goal of selecting an authenticated matching remote and using per-run refs for the reviewed base. I did not identify any discrete regression that would clearly break existing behavior. |
Closes #56
What changed
scripts/codex-review.shnow fetches the PR head and base from the repoghresolved ($repo) instead of the literaloriginremote.https://github.com/$repo.git, where$repois thenameWithOwnerreturned bygh repo view. This makes the fetch source provably the repoghbound the review to.refs/codex-review/(refs/codex-review/pr-head,refs/codex-review/base) rather than arefs/remotes/origin/*tracking ref. That keeps the destinations independent of which remoteoriginhappens to be, and avoids clobbering the operator'sorigin/<base>tracking ref with a commit fetched from a different URL.cleanuptrap oncecodex exec review --basehas read it (the head ref is still deleted immediately after its SHA is captured, as before).reviewer/codex-review.mdstep 1/2 updated to document the canonical-URL fetch source and the fork-workflow rationale.Why
In a fork workflow (
origin= your fork,upstream= the canonical repo PRs target),ghreports the PR on the canonical repo whilegit fetch origin +refs/pull/<PR#>/head:...hit the fork — where the PR ref doesn't exist (fetch fails) or a same-numbered unrelated PR silently resolves (wrong diff reviewed). Fetching from the canonical URLghresolved closes that gap.Chosen mechanism: canonical URL (not remote-match)
AC #1 offered two options. I chose fetch directly from
https://github.com/$repo.gitover parsinggit remote -vfor a URL match because:ghresolved —$repois the samenameWithOwnerstring, no remote-table parsing/normalization (SSH vs HTTPS,.gitsuffix, trailing slash) to get wrong.--no-tags/ temp-ref-cleanup behavior the simplest (AC Add RESTORE.md — runbook to rebuild the whole team from this repo #1's stated preference).upstreamremote at all.Preserved (AC #2)
Read-only forced sandbox, comments-only single
gh pr comment, verbatim posting, the realReviewed-head:/Reviewed-base:SHA markers,--no-tags, and the narrow destination refspecs that touch nothing else. The fetch still force-updates only the two refs it owns; no globalgit fetch --force.How verified
shellcheck -S style scripts/codex-review.sh— clean (same flag CI uses).ci/required-files.txtmanifest) — green locally; script remains#!/usr/bin/env bash,set -euo pipefail, executable.bash -nsyntax check — OK.originpoints at; private refs avoid mutating operator tracking refs; cleanup drops the base ref on every exit path.Self-modification note
This is the reviewer-harness script (
scripts/codex-review.sh). It takes live effect on merge — scripts run from disk, so no/faberre-sync is needed. (faber-command.mdis unchanged; a re-run ofscripts/install.shis only required when that file changes.)