Repository navigation
fix(gitlab): submit multi-line range comments without schema errors - #598
Merged
Merged
Conversation
GitLab rejects a range comment with
400 Bad request - Note {:position=>["must be a valid json schema"]}
because each `position.line_range` endpoint carried `new_line` / `old_line`
alongside `line_code`. The Grape API declares those nested params as String
while position.json requires an integer, so no value satisfies both
validators (gitlab-org/gitlab#572121). Endpoints now carry `line_code` and,
for changed lines only, `type` — a context line belongs to both sides, so
declaring a `type` for it is rejected too.
The endpoint line codes were also wrong. `line_code` is
`sha1(path)_<old>_<new>` built from the diff's running counters, so an added
line still carries the old-side counter it was inserted at. They were built
as `sha1(path)_0_<line>`, which anchors the range to the wrong lines even
when the note is accepted. `InlineComment` now carries `range_anchors` —
both endpoints in both counters, resolved from the parsed diff — and a range
ending on a context line fills in `counterpart_line` so the position names
both sides, matching what a single-line comment on that same line sends.
Fixes agavra#557
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
agavra
approved these changes
Aug 13, 2026
agavra
left a comment
Owner
There was a problem hiding this comment.
I don't have a gitlab account to test against, but I checked the non-GL parts of the patch and it LGTM.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Submitting a review to GitLab fails whenever the payload contains a multi-line / visual-range comment:
(or the draft-notes equivalent,
{"message":{"position":["must be a valid json schema"]}}). Single-line comments are unaffected, and the failure takes the whole:submitdown with it.Root cause
Two separate problems in
gl_range_endpoint:1. The endpoints carry line numbers. Each
position.line_range.{start,end}was built withtype+line_code+new_line/old_line. Grape declares the nestedold_line/new_lineparams as String whileposition.jsonrequires an integer — no value satisfies both validators, so the note is rejected outright (gitlab-org/gitlab#572121). Endpoints now carryline_codeplus, for changed lines only,type. A context line belongs to both sides, so declaring atypefor it is rejected as well and it is now omitted.2. The line codes were wrong.
line_codeissha1(path)_<old>_<new>built from the diff's running counters — an added line still carries the old-side counter it was inserted at, and a deleted line the new-side counter it sits before. They were built assha1(path)_0_<line>, so even an accepted note anchors the range to the wrong lines. Neither counter is recoverable from a single line number, soInlineCommentgainsrange_anchors: both endpoints in both counters, resolved from the parsed diff infind_diff_anchor. Other forges ignore the field.While anchoring the endpoints it became clear a range ending on a context line has the same problem a single-line comment on that line does — GitLab needs both
old_lineandnew_linein the position — somap_rangenow fills incounterpart_linefor ranges too, matching what the single-line path already sent.Tests
should_send_line_range_for_multi_line_range_comment— endpoints are exactlytype+line_code, no line numbersshould_omit_endpoint_type_for_context_line_in_range— a context endpoint carries onlyline_code, and the position names both sidesshould_anchor_range_endpoints_in_both_line_counters— an added line resolves to(old, new), not(0, new)should_populate_counterpart_line_for_range_ending_on_context_linecargo test(1364 passed),cargo fmt --checkandcargo clippy --all-targetsare clean.Notes
Fixes #557, which I filed and then closed while carrying this on a fork — it is a real upstream bug, verified against a self-hosted GitLab instance.
🤖 Generated with Claude Code