Skip to content

fix(review): let offload-review review a PR from a fork - #979

Merged
amiddavid merged 2 commits into
mainfrom
fix/offload-review-fork-prs
Nov 9, 2026
Merged

amiddavid merged 2 commits into
mainfrom
fix/offload-review-fork-prs

Conversation

@amiddavid

Copy link
Copy Markdown
Collaborator

Summary

  • offload-review now works for a PR from a fork.
  • Same-repo PRs work as before.

What we found

  • PR feat(opencode): OpenCode plugin for context-guru #483 has head AIMikav:feat/opencode-plugin. That branch is not on origin.
  • The script ran git fetch origin <headRefName> <base>.
  • The fetch failed: fatal: couldn't find remote ref feat/opencode-plugin.
  • The script exited 128 before any reviewer started.

What changed

  • The script fetches refs/pull/$pr/head and the base branch. This ref exists for every PR.
  • origin/$base_ref stays current, as before.
  • The script checks that the head sha from gh exists locally. If not, it stops with a clear message. This covers a push that came in between.
  • The unused head_ref variable is gone.
  • No other place assumes a same-repo branch. The backends and the review prompts use only the sha and the worktree.

Behavior change

  • Same-repo PRs: no change.
  • Fork PRs: now work. They failed before.

How it was tested

🤖 Generated with Claude Code

The script fetched the PR's headRefName from origin. A fork PR branch is
not on origin, so the fetch failed with "couldn't find remote ref" and
the script exited 128 before any reviewer started.

Fetch refs/pull/<n>/head instead. It exists for same-repo and fork PRs.
Then check that the head sha from gh is present, and fail with a clear
message if the PR ref lags behind.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.319 offload-review skill, @amiddavid's session fresh 1 of 2 1 of 2 aa7401ba3a5d approve

Verdict: approve

Findings

None.

Non-blocking

  • scripts/offload-review.sh:130 — --json still asks for headRefName, but nothing uses it now. Drop it, or keep it; it costs one field.
  • scripts/offload-review.sh:173 — 2>/dev/null on cat-file hides every error behind the "not in refs/pull yet" message. A broken object store would print the same advice. Minor: the message could say "check git cat-file by hand" on failure.
  • The script has no test harness in the repo, so the fork-PR fetch path has no test. Earlier fixes to this script (#697, #699) shipped the same way. If a harness ever appears, the two cases worth a test are: a fork PR head, and a refs/pull/N/head that lags the gh-reported sha.

What I checked

  • Read the full diff (one file, scripts/offload-review.sh, +8/−2) and the whole script around it.
  • The bug is real: a fork PR's head branch is absent from origin, so the old git fetch origin "$head_ref" (line 171 before the change) failed before any reviewer ran. refs/pull/N/head exists on the base repo for every PR, fork or not, so the new refspec fixes both cases.
  • The lag guard is sound. gh pr view and git fetch can see different heads when a push lands in between. The guard at lines 173–176 runs before any worktree or session is touched, and every later step pins the exact $sha: worktree add --detach "$sha" (line 196), checkout --detach "$sha" (line 194), and the HEAD check (line 428). So the script cannot review a commit other than the one gh reported. A force-push in that window makes the guard exit 1 with a clear message; nothing is half-run.
  • The base fetch is unchanged. Fetching a plain branch name updates origin/$base_ref (git does this opportunistically since 1.8.4), so the merge base at line 307 stays correct. I grepped the repo: nothing else reads origin/<head ref>, so dropping the head-branch fetch breaks nothing.
  • The removed head_ref variable has no other user.
  • refs/pull/N/head points at the last head even when the head branch is deleted, so the new code handles that case too; the old code failed there.
  • Checked the repo rules that could apply: fail-open and data-dependence apply to the proxy and library, not to this dev script. The change alters repo tooling only, not user-facing behavior, so the "human permission for behavior change" rule does not apply.
  • Read CLAUDE.md and docs/design.md as the process requires. No Go tests were run; live tests are not approved.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.319 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 aa7401ba3a5d approve

Verdict: approve

Findings

None.

Non-blocking

  • scripts/offload-review.sh:130 — --json still asks for headRefName, but nothing reads it now. Drop it, or keep it as a comment on what the PR is. No effect on behavior.
  • scripts/offload-review.sh:43-46 — the header's exit-code list does not cover the new exit 1 ("head is not in refs/pull/N/head yet"). SKILL.md's exit table says exit 1 means "stop and report". The message itself says "Run again in a minute", so the operator gets the right action. A one-line note in the header would make the docs match.
  • No test covers the script. The repo has no shell test harness, and the PR says the fetch was checked by hand on PRs #483 and #976. Acceptable for this size.

What I checked

  • Read the full diff (one commit, scripts/offload-review.sh only) and the whole script around it.
  • The fix is correct. refs/pull/N/head exists on the base repo for every PR, fork or not. The old fetch of headRefName failed for a fork PR, because that branch lives on the fork, not on origin. The new fetch cannot fail that way.
  • origin/$base_ref still updates. git fetch origin <branch> also updates the tracking ref (git since 1.8.4). attempt uses git merge-base "origin/$base_ref" HEAD at line 307. The base branch is always on origin, fork or not. This behavior is unchanged by the diff.
  • The lag guard covers the right race. gh pr view reads the head at one moment; the fetch reads refs/pull/N/head at a later one.
    • PR ref older than the reported sha: cat-file -e fails, the script exits 1 before any reviewer or worktree runs. No wasted run, no wrong review.
    • PR ref newer (a push came in between): the reported sha is an ancestor, so it is present. The review runs on the sha that gh reported, and the marker names that sha. The review and the marker agree.
    • The sha present locally for another reason (an earlier round, a local branch): the guard passes, and the review still runs on the sha gh reported. Correct target either way.
  • Nothing else assumed a same-repo head branch. I grepped the script, the three backends, and SKILL.md. Only $sha, $base_ref and the worktree path are used downstream. The removed head_ref variable had no other reader.
  • Fail-open rules do not apply. The script is dev tooling, not the proxy or the library. No component, config or data dependence changes. components/all/datadep_test.go is untouched.
  • bash -n passes. shellcheck is not installed, same as in the PR.
  • Confirmed the commit topology: aa7401ba has parent 569c609b (the base). One commit, fast-forward.

Exit 1 also covers a PR head that is not in refs/pull/N/head yet.
Comment lines only.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

The comment note is fixed in 8e3a3fa. The header now lists the new exit 1 case.

headRefName stays in --json. Removing it is a code change after approval, and it costs one field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant