Inline comment fails with 400 when OCR line range partially exceeds diff hunk
OpenCodeReview Version
v1.12.1
Operating System
Linux (x86_64)
Installation Method
npm (global)
LLM Provider
Other OpenAI-compatible endpoint
Bug Description
When ocr review produces an inline comment whose line range partially exceeds a GitLab diff hunk, the inline comment fails with HTTP 400. The review result still contains the finding, but it cannot be posted as an inline discussion.
Steps to Reproduce
- Create a GitLab MR where a file's diff contains hunks covering, for example, lines 11-26 and 120-123 (but NOT lines 27-28).
- Run
ocr reviewagainst this MR. - OCR produces a comment with start_line=21, end_line=28 (the method body range).
- Run
post_review.pyto publish the result. - Observe: 10 of 11 inline comments post successfully; the comment at lines 21-28 fails with HTTP 400.
Expected Behavior
The inline comment should be published successfully. Ideally post_review.py should clamp the comment's start_line/end_line to the diff hunk coverage (e.g. 21-28 → 21-26) before posting. Alternatively, it should fall back to a file-level comment or summary note, rather than failing silently.
Logs / Error Output
[400-fallback] MR diff list came back empty; treating inventory as incomplete.
Successfully posted 10/11 inline comments.AI/LLM Disclosure
- I didn't use AI/LLM to assist or generate the content above.
Additional Context
Environment:
- open-code-review: v1.12.1 (npm global install, running inside node:20 Docker container)
- GitLab: 15.4.3-jh (self-hosted)
- LLM: GLM-5.2 via OpenAI-compatible endpoint
Root cause analysis:
The diff hunks for the affected file cover lines 11-26 and 120-123. OCR's comment range is 21-28. Lines 27-28 are outside any hunk. GitLab rejects inline comments whose end_line falls outside the diff range. post_review.py's fallback logic (get_mr_diffs) returned an empty inventory in this case, so it could not downgrade the comment either.
Suggested fix:
In post_review.py (or the underlying resolver), clamp the comment range to the intersection with the diff hunk before posting. E.g., 21-28 → 21-26. If the intersection is empty, fall back to a file-level comment.
Source: alibaba/open-code-review