## TL;DR
GitHub rejects review comments anchored to a commit or hunk that is no longer the PR head. Fetch the PR's current head SHA, confirm your target line is inside the latest diff, and repost with the fresh commit id plus line and side instead of the deprecated position field. A 201 response with a comment id is the success signal.

```text
422 Unprocessable Entity
{
  "message": "Validation Failed",
  "errors": [
    { "resource": "PullRequestReviewComment", "code": "custom", "field": "position" }
  ]
}
```

1. Get the PR's current head SHA: `gh api repos/OWNER/REPO/pulls/123 --jq '.head.sha'`. Expected: a 40-character SHA. Use the real owner, repo, and PR number.
2. Confirm the target line is in the latest diff: `gh api repos/OWNER/REPO/pulls/123/files --jq '.[].patch' | grep -n "your changed line"`. Expected: the line appears in the current diff output.
3. Repost with the fresh anchor: `gh api repos/OWNER/REPO/pulls/123/comments -f commit_id=HEAD_SHA -f path=src/file.py -F line=42 -f side=RIGHT -f body="comment text"`. Expected: a 201 response with an `id` field for the new comment.
4. If it still 422s, the line moved again; re-fetch the SHA and diff and retry once, then fall back to a top-level PR comment naming the file and line.

## Use this when
- POSTing review comments or review replies returns 422 Validation Failed
- The PR received new pushes between fetching the diff and posting
- An agent posts comments computed from a cached diff

## Not for this skill when
- The 422 names a different field (body too long, missing path); fix that field instead
- The PR is closed or merged; comments on closed PRs are rejected for a different reason
- You are using the web UI, which re-anchors automatically

## Variant phrasings
- "github api 422 validation failed pull request review comment"
- "review comment position is outdated 422"
- "cannot post inline comment on old diff via api"

## Why it happens
Inline comments must anchor to a real position in the PR's latest diff. The deprecated `position` field counts from the diff of a specific commit; once the PR head moves, that position no longer exists and validation fails. `line` plus `side` against the current head SHA is the supported anchor.

## Edge cases
- Posting to a line outside any hunk of the latest diff always 422s; the comment must sit on a changed line or its immediate context.
- Race: another push between your SHA fetch and your POST re-stales the anchor; keep fetch and post back to back.
- Replies to existing review threads use the reply endpoint with `in_reply_to`, which needs no diff anchor at all.

## Provenance

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