communication
api_usage
ai_generated
true
GitHub PR review comment appears on wrong line or API returns 'position is not a valid hunk position'
ID: communication/github-pr-review-comment-position
85%Fix Rate
88%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| any | active | — | — | — |
Root Cause
GitHub PR review comment 'position' is NOT the file line number. It's the 1-based index within the diff hunk. Line 42 in the file might be position 5 in the diff. Using 'line' parameter (newer API) is simpler but only works for lines visible in the diff.
genericWorkarounds
-
90% success Use the newer 'line' and 'side' parameters instead of 'position'
body = {"body": "comment", "path": "file.py", "line": 42, "side": "RIGHT"} # RIGHT for new code, LEFT for old -
85% success Use 'subject_type': 'file' for comments not tied to specific lines
body = {"body": "general comment about this file", "path": "file.py", "subject_type": "file"} -
78% success Parse the diff to calculate correct position if you must use the legacy parameter
Count lines in the diff hunk from @@ marker to the target line. That count is your position value.
Dead Ends
Common approaches that don't work:
-
Use file line number as 'position' in PR review comment API
92% fail
The 'position' parameter is the line index within the diff, not the file. Line 100 in the file might be position 3 in the diff if only 3 lines of context are shown.
-
Use 'line' parameter on any line in the file
82% fail
The 'line' parameter only works for lines visible in the diff. Comments on unchanged lines outside the diff context fail with 422.