## TL;DR

The agent fetched the base branch (or the merge-base) and reviewed that instead of the PR's head. Resolve the head SHA from the PR API and diff `base...head` explicitly before reviewing.

## Error

```text
Agent review discusses code from main that the PR never touched; none of the PR's actual changes are mentioned.
```

## Steps

1. Confirm: compare the review's claims against the PR's files-changed list. Expected: the review describes base-branch code.
2. Fix the ref resolution: get `head.sha` from the PR API response and check out / fetch exactly that SHA. Expected: the agent sees the PR's code.
3. Compute the review diff as `base...head` (three-dot), not `base..head`  -  three-dot shows what the PR introduces. Expected: the diff matches the PR page.
4. Re-run the review. Expected: findings reference the PR's actual changes.

## When to use

- The agent's review discusses code the PR did not change.
- The agent checks out code itself.

## When not to use

- The review is on an old head SHA  -  that is staleness, not the wrong branch.
- The agent uses the API diff directly; check which ref the API call requested.

## Tool compatibility

- Any agent that clones/fetches PR code.
- GitHub / GitLab.

## Variant phrasings

### Agent reviewed the merge commit

The merge commit includes base changes; review the head diff instead.

### Fork PRs: agent fetched the wrong remote

Fork heads live on the fork remote  -  add it and fetch the PR ref explicitly.

## Why it happens

Default clones and naive fetches land on the base branch. Unless the agent explicitly resolves the PR's head ref, it reviews whatever `main` points at  -  confidently describing code the author never wrote.

## Edge cases

- Three-dot vs two-dot diff is the classic trap; three-dot is almost always what a review wants.
- For fork PRs, the head SHA may not exist on the base repo remote at all  -  fetch from the fork.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_jRbhhGhVGzxiGMjbg5e8uA
