Skip to content

fix: review PR head in reused workspace (stale pr-review branch)#40

Merged
AbirAbbas merged 1 commit into
mainfrom
fix/pr-af-stale-workspace-checkout
Jun 4, 2026
Merged

fix: review PR head in reused workspace (stale pr-review branch)#40
AbirAbbas merged 1 commit into
mainfrom
fix/pr-af-stale-workspace-checkout

Conversation

@AbirAbbas
Copy link
Copy Markdown
Contributor

Summary

pr-af reuses a persistent /workspaces/<repo> clone across reviews. _checkout_pr_branch fetched the PR head directly into the local pr-review branch:

git fetch --depth 1 origin pull/<N>/head:pr-review
git checkout pr-review

When the workspace is reused, the previous review leaves pr-review checked out, and git refuses to fetch into the currently checked-out branch (refusing to fetch into branch '...' checked out at ...). That failure was swallowed (capture_output=True, no return-code check), so:

  • every PR after the first in a container's lifetime was reviewed against the first PR's working tree;
  • the anatomy phase saw the diff not matching the tree and returned zero findings → github-buddy silently "passed" PRs without actually reviewing them.

On Railway, /workspaces is ephemeral (no volume attached), so the stale branch only resets on redeploy — meaning in steady state most PRs were getting rubber-stamped.

Fix

  • Fetch the PR head to FETCH_HEAD (always allowed, even with pr-review checked out), then point the branch at it with git checkout -B pr-review FETCH_HEAD.
  • Both git calls now check their return code and raise, so a failed fetch/checkout surfaces loudly instead of silently reviewing a stale tree.

Tests

New tests/test_resolve_repo.py — real-git behavior tests (no mocking of internals):

  • fresh workspace → working tree reflects the PR head
  • reused workspace → working tree updates to the new PR head, not the prior PR's tree (regression for the bug; verified failing on the pre-fix code)
  • unfetchable PR ref → raises instead of leaving a stale tree

Validation

  • ruff check src/ scripts/ — passes (CI lint gate)
  • New tests pass; full suite green except one pre-existing, unrelated flaky timeout test (test_create_request_fails_fast_when_hax_wedges), which fails identically on main.

🤖 Generated with Claude Code

pr-af reuses a persistent /workspaces clone across reviews. _checkout_pr_branch
fetched the PR head directly into the local `pr-review` branch:

    git fetch --depth 1 origin pull/<N>/head:pr-review
    git checkout pr-review

When the workspace is reused, the previous review leaves `pr-review` checked
out, and git *refuses* to fetch into the currently checked-out branch
("refusing to fetch into branch '...' checked out at ..."). The failure was
swallowed (capture_output, no return-code check), so every PR after the first
in a container's lifetime was reviewed against the first PR's working tree.
The anatomy phase then saw the diff not matching the tree and returned zero
findings — github-buddy silently "passed" PRs without reviewing them.

Fix: fetch the PR head to FETCH_HEAD (always allowed) and point the branch at
it with `git checkout -B pr-review FETCH_HEAD`, which works even when pr-review
is the current branch. Both git calls now check their return code and raise,
so a failed fetch/checkout surfaces instead of silently reviewing a stale tree.

Adds tests/test_resolve_repo.py with real-git behavior tests covering fresh
workspace, reused workspace (the regression), and unfetchable-ref failure.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@AbirAbbas AbirAbbas merged commit 0ed772c into main Jun 4, 2026
2 checks passed
@AbirAbbas AbirAbbas deleted the fix/pr-af-stale-workspace-checkout branch June 4, 2026 14:11
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