## TL;DR
Your review agent started writing while the PR was open and hit submit after it closed or merged. Check the PR state immediately before submitting the review, and if it closed mid-run, post the findings as regular comments instead. The fix is a state check plus a graceful fallback, not a retry loop.

## The query

```text
"HttpError: Pull request reviews may only be submitted on open pull requests"
```

## Use this when

- An automation or agent gets this HttpError posting a review via the API
- Long-running review jobs fail at the very last step
- The error appears intermittently on PRs that move fast

## Not for

- Draft review UI problems in the browser
- "review required before merging" branch protection errors
- Dismissing stale reviews

## Steps

### 1. Confirm the PR actually closed

```bash
gh pr view [number] --json state,mergedAt
```

Expected output: the real state, for example `state: MERGED`. If it says OPEN, keep reading - something else is wrong.

### 2. Add a state check right before the submit call

In your agent or script, fetch the PR state as the last step before POSTing the review payload. Never trust the state from when the review started.

Expected output: the submit path only runs when state is OPEN.

### 3. Fall back to issue comments when the PR is closed

Regular issue comments work on closed and merged PRs. Convert the review body into one comment (or a few) posted to the PR conversation instead of a formal review.

Expected output: findings still land on the PR even though the review could not be submitted.

### 4. Save the review draft locally before submitting

Write the full review body to disk or durable storage before the submit attempt.

Expected output: a failed submit never loses the agent's work.

### 5. Rule out the misleading-OPEN case

If the PR is genuinely open and you still get this error, check the token scope. The reviews endpoint needs pull-request write access; a token with only read scope can surface confusing errors.

Expected output: the token has the write scope the reviews endpoint requires.

## Variant phrasings

### GitHub API 422 pull request reviews may only be submitted on open pull requests

Same thing, one layer down. Octokit wraps the 422 in an HttpError. The state-check-plus-fallback fix is identical.

### agent's review failed because the PR merged while it was working

The race in its purest form. Shorten the window: fetch the diff once, write the review, and submit without long pauses between the last analysis step and the submit call.

## Why it happens

GitHub's pull-request reviews endpoint requires the PR to be open at submit time. Agents that spend minutes or hours analyzing a diff before submitting race the PR's own lifecycle. Someone merges, closes, or the PR auto-merges, and the submit call that was valid when the run started is now invalid.

## Edge cases

- Draft PRs: review submission on drafts behaves differently than on open PRs. Handle drafts as their own case in the state check.
- Reopened PRs: a PR closed then reopened accepts reviews again, but any review drafted against the closed state should be re-validated before submitting.
- Dont hammer the state endpoint per comment. One check before the final submit, plus graceful handling of the 422, is enough. Per-comment checks just burn rate limit.

## Provenance

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