GitHub: why a comment on lines was refused
A comment on lines of a pull request goes to POST /repos/OWNER/REPO/pulls/NUMBER/comments with body, commit_id, path, line and side, and for a range of lines also start_line and start_side. GitHub's documentation names the statuses: 201 when the comment is created, 403 when you may not, and 422 when the request fails validation or the endpoint has been spammed. It does not list the 422 messages; the ones below are quoted from public reports, with GitHub's documented rules behind them (checked October 25, 2026).
HTTP/1.1 422 Unprocessable Entity
{"message":"Validation Failed","errors":[{"resource":"PullRequestReviewComment","code":"custom","field":"pull_request_review_thread.line","message":"pull_request_review_thread.line must be part of the diff"},{"resource":"PullRequestReviewComment","code":"missing_field","field":"pull_request_review_thread.diff_hunk"}],"documentation_url":"https://docs.github.com/rest/pulls/comments#create-a-review-comment-for-a-pull-request","status":"422"}
422: what GitHub says, and why
pull_request_review_thread.line must be part of the diff(withpull_request_review_thread.diff_hunkmissing_field): the line is in none of the hunks of the file's diff. GitHub takes a comment only on the lines the diff shows, the changed lines and the few unchanged lines around them, as Files changed shows them. A line further away is refused, although the file is in the pull request.sidepicks which file the line number counts in: GitHub's documentation says to useLEFTfor deleted lines, andRIGHTfor added lines and the unchanged lines around them. WithLEFT,lineis a line of the file before the change; a number that is only right on the new side lands outside the diff.pull_request_review_thread.pathinvalid(withdiff_hunkmissing_field): GitHub did not takepathas a file of the pull request's diff.Pull request review thread start line must be part of the same hunk as the line: the range's first line (start_line) and last line (line) are in two different hunks. A range must sit inside one hunk.pull_request_review_thread.start_line must precede the end line.:start_lineis the same asline, or after it; a comment on one line goes withlinealone. A public report got the same words for a range of deleted lines (sideLEFT) sent withoutstart_side, which GitHub's documentation requires for a comment on several lines.- In a review (
POST /repos/OWNER/REPO/pulls/NUMBER/reviewswithcomments), the same rule has been reported asUnprocessable EntitywithPull request review thread line must be part of the diff and Pull request review thread diff hunk can't be blank, and one such comment fails the whole review.
403, 404
- 403
Resource not accessible by personal access token(orby integration): the token may read the pull request but not comment on it; a fine-grained token needs Pull requests read and write (see which permission to add). - 403 or 429 for comments sent too fast: GitHub's documentation says that creating content too quickly with this endpoint may hit a secondary rate limit (see "API rate limit exceeded").
- 404: the repository or pull request is not there for this token, which is also how GitHub answers a private repository the token cannot see.
- A reply to a line comment while you have a pending review answers
user_id can only have one pending review per pull request(see why GitHub refused the review).
Taken, but outdated
commit_id is the commit the comment is about. GitHub's documentation says that a comment not on the latest commit may show as outdated when a later commit changes the line. position, the older way to name a line by its place in the diff, is closing down; line and side replace it.
What to do
- Find the hunks: each file in
GET /repos/OWNER/REPO/pulls/NUMBER/fileshas itspatch. Every@@ -A,B +C,D @@starts a hunk: B lines of the old file from line A, D lines of the new file from line C. - A line outside the diff: pick a line in or next to a change. To say something about the file as a whole, send
subject_typefilewithpathand noline; for the whole pull request, a conversation comment (POST /repos/OWNER/REPO/issues/NUMBER/comments). - A range across hunks: one comment for each hunk.
- One line:
linealone, withoutstart_line. Deleted lines:sideandstart_sideLEFT, with the old file's line numbers. path: the path from the repository's root, asfilenamein the list of files gives it.
In IntelliJ IDEA: a comment only on the lines the diff carries, sent with GraphQL
How the GitHub support built into IntelliJ IDEA comments on lines of a pull request, in its source (checked October 31, 2026; IntelliJ IDEA: GHPRReviewDiffExtension.kt, GHPRReviewEditorGutterControlsState.kt, GHPRDiffReviewViewModel.kt, GHPRReviewNewCommentEditorViewModel.kt, GHPRReviewDataProviderImpl.kt, GHPRReviewServiceImpl.kt, createReview.graphql, addPullRequestReviewThread.graphql, GithubBundle.properties, CodeReviewSubmittableTextViewModel.kt):
- Where it lets you comment: in the pull request's diff, the gutter offers a comment only on the lines of the diff's hunks (the changed lines and the unchanged lines around them that the diff carries), and only if your account has read permission or above on the repository, as GitHub reported when the IDE connected. A range of lines can be chosen only when both its ends are on such lines and on the same side, both in the old file or both in the new.
- It does not use the REST endpoint above. With no pending review of yours, the comment box offers Add Single Comment and Start Review, the one you used last as the main button. Both send GitHub's GraphQL
addPullRequestReviewwith the thread:path,lineandside, for a range alsostartLineandstartSide, and ascommitOIDthe commit on the new side of the diff. Add Single Comment posts it at once as a review withCOMMENT; Start Review keeps it in a pending review. - With a pending review of yours, Add Review Comment adds the thread to it with
addPullRequestReviewThread. When the diff shows one commit rather than the whole pull request, it sends instead the line's old-stylepositionin the diff between the merge base and that commit: as its source notes, the GraphQL threads cannot name a commit, and the REST endpoint cannot name the review and fails while a draft review exists. - When GitHub refuses, the comment box stays open with your text: it closes only after GitHub accepts the comment. The source also writes the error to the IDE's log.
GitHub pull requests in IntelliJ IDEA
Pull Request Inbox for GitHub, a plugin by Lesstep for JetBrains IDEs 2024.1 or later, comments on the lines you select in the IDE's diff. Before you type, it checks them against the hunks of the file's patch from GitHub, both ends of a range in one hunk on one side, and says so when they are outside. It sends line and side, and for a range also start_line and start_side on the same side; one line goes without start_line. commit_id is the head commit you had on screen. For a file without a patch, GitHub decides; when GitHub refuses, the plugin shows GitHub's words and puts your comment on the clipboard. The review inbox, diffs and conversations are free; approving, commenting and merging are Pro (US$1.50 a month, with a 30-day trial).
GitHub is a trademark of GitHub, Inc.; IntelliJ IDEA is a trademark of JetBrains s.r.o. This page is not affiliated with or endorsed by GitHub, Inc. or JetBrains.
More: GitHub merge refused (405, 409) · GitHub review refused (422) · GitHub search 422 "Validation Failed" · "Resource not accessible by personal access token" · 401 "Bad credentials" · "Resource protected by organization SAML enforcement" · "API rate limit exceeded" · GitHub diff 406 "too_large", 3,000 files · GitHub branch update refused (422) · GitHub pull request not created (422, 403) · GitHub auto-merge refused · GitHub draft, ready for review or close refused · GitHub conversation not resolved · GitHub checks not shown (check runs 403) · GitHub file contents not read · GitHub compare refused (404, 422) · GitHub comment or reply refused (403 locked, archived) · GitHub merge method not allowed (405) · GitHub branch not found (404, 301) · GitHub Enterprise Server not reached · GitHub review request not shown · GitHub pull request list incomplete · GitHub 404 Not Found, renamed repositories (301, 307) · GitHub line comment outdated or not on the diff · GitHub pull requests not updating, notifications late · GitHub suggested change cannot be applied · GitHub required check stuck at "Expected" · GitHub code owner review required · GitHub merge blocked by unresolved conversations · GitHub merge blocked by unsigned commits · GitHub branch that merges through a merge queue · GitHub merge waiting for an approval of the most recent push · GitHub merge waiting for code scanning results · GitHub merge waiting for code quality results · GitHub merge blocked by a code coverage threshold · GitHub merge blocked by license compliance results · GitHub branch locked or its updates restricted · GitHub branch not deleted after merging · GitHub merge waiting for a team's approval (Required reviewers) · GitHub merge blocked by secret scanning alerts · GitHub stacked pull request not merging · GitHub push blocked by push rules · GitHub merge blocked by commit metadata rules · GitHub force push blocked · GitHub issue not closed by a merged pull request · GitHub pull request not checked out locally · GitHub pull request has merge conflicts · GitHub changes requested and dismissing a review · GitHub co-author not credited for a commit · GitHub dependency review check failed · GitHub Dependabot not rebasing its pull request · GitHub fork not syncing with upstream · GitHub pull request base branch not changing · GitHub pull request not reverting · GitHub pull request template not showing · GitHub pull request labels or assignees not added · GitHub pull request not closing or reopening · GitHub push blocked by push protection · GitHub pull request comment hidden · GitHub pull request blocked until deployments succeed · GitHub team review request replaced by members · GitHub pull request file no longer marked Viewed · GitHub pull request marked merged without being merged · GitHub Copilot review does not count as an approval · GitHub checks not running on a pull request a workflow created · GitHub Update branch button not shown on a pull request · GitHub checks failing on a Dependabot pull request · GitHub checks failing on a pull request from a fork · GitHub checks skipped by [skip ci] in a commit message · GitHub checks gone after the retention period · GitHub code review limits in a public repository · GitHub pull requests turned off or limited in a repository · GitHub checks run on every pull request in a stack · GitHub pull request showing commits already squash merged · GitHub pull request not showing a file diff · GitHub push to a pull request branch from a fork refused · GitHub check cancelled on a pull request · GitHub Rebase and merge not available · GitHub merge commit message not what you expected · GitHub pull request shows every line changed · GitHub API request timed out · GitHub pull request image or document diff not shown · GitHub review request refused (422) · GitHub pull request from Copilot: checks not running, approval not counted · GitHub push refused: GH006 and GH013 on a protected branch · GitHub "At least 1 approving review is required", approvals that do not count · GitHub pull request plugins for IntelliJ IDEA, compared · 日本語