PR review comments sometimes land on the wrong line (e.g. line 5 instead of 6). The symptom surfaced via Check Run annotations using GitHub's "Check warning on line R633" UI notation.
Root cause hypothesis
Medium confidence. The hunk formatter (formatHunkForAnalysis in src/diff/context.ts) presents the diff to the LLM without per-line numbering. The LLM must infer absolute line numbers by counting from the newStart value in the @@ … @@ header. Context lines (unchanged lines prefixed with a space) make this counting ambiguous, especially across multi-hunk diffs or when the hunk contains a mix of context and changed lines.
The prompt instructs the LLM:
"location.startLine" MUST be within the hunk line range (shown in the "## Hunk" header).
But the diff content rendered to the LLM (via hunk.content) does not annotate individual line numbers inline — only the bounding range lines X–Y is stated. A mis-count of one context line produces an off-by-one in the returned startLine/endLine.
Secondary: the PR review comment renderer (src/output/renderer.ts) uses endLine ?? startLine as the GitHub comment anchor, while check annotations (src/output/github-checks.ts) use startLine as primary. These differ when endLine is set, which could surface as a one-line offset between the Check annotation and the PR review inline comment pointing at the same finding.
Reproduction
No minimal repro available, but this was observed when a PR review comment appeared on line N when the actual flagged line was N+1.
Suspected fix areas
src/diff/context.ts formatHunkForAnalysis: annotate each diff line with its absolute new-file line number (e.g. prefix each line with L{n}: ) so the LLM doesn't have to count from the hunk header.
src/output/renderer.ts: audit the inconsistency between using endLine as the PR comment anchor vs startLine for check annotations on the same finding.
Action taken on behalf of David Cramer.
PR review comments sometimes land on the wrong line (e.g. line 5 instead of 6). The symptom surfaced via Check Run annotations using GitHub's "Check warning on line R633" UI notation.
Root cause hypothesis
Medium confidence. The hunk formatter (
formatHunkForAnalysisinsrc/diff/context.ts) presents the diff to the LLM without per-line numbering. The LLM must infer absolute line numbers by counting from thenewStartvalue in the@@ … @@header. Context lines (unchanged lines prefixed with a space) make this counting ambiguous, especially across multi-hunk diffs or when the hunk contains a mix of context and changed lines.The prompt instructs the LLM:
But the diff content rendered to the LLM (via
hunk.content) does not annotate individual line numbers inline — only the bounding rangelines X–Yis stated. A mis-count of one context line produces an off-by-one in the returnedstartLine/endLine.Secondary: the PR review comment renderer (
src/output/renderer.ts) usesendLine ?? startLineas the GitHub comment anchor, while check annotations (src/output/github-checks.ts) usestartLineas primary. These differ whenendLineis set, which could surface as a one-line offset between the Check annotation and the PR review inline comment pointing at the same finding.Reproduction
No minimal repro available, but this was observed when a PR review comment appeared on line N when the actual flagged line was N+1.
Suspected fix areas
src/diff/context.tsformatHunkForAnalysis: annotate each diff line with its absolute new-file line number (e.g. prefix each line withL{n}:) so the LLM doesn't have to count from the hunk header.src/output/renderer.ts: audit the inconsistency between usingendLineas the PR comment anchor vsstartLinefor check annotations on the same finding.Action taken on behalf of David Cramer.