fix(diff): stop emitting comments whose quote matches no reviewed file - #1099
Open
nitishagar wants to merge 1 commit into
Open
fix(diff): stop emitting comments whose quote matches no reviewed file#1099nitishagar wants to merge 1 commit into
nitishagar wants to merge 1 commit into
Conversation
Contributor
|
🔍 OpenCodeReview found 1 issue(s) in this PR.
|
Comment on lines
+312
to
+315
| targets := make([]string, len(targetLines)) | ||
| for i, t := range targetLines { | ||
| targets[i] = xform(t) | ||
| } |
Contributor
There was a problem hiding this comment.
When matchConsecutiveWith is called from resolveFromHunk, the same targetLines are transformed by xform on every invocation (once per hunk × per side × per xform pass). Since targetLines is invariant within each xform pass, the transformation is redundant after the first call.
Consider hoisting the target transformation out of matchConsecutiveWith and accepting pre-transformed targets, or computing them once in resolveFromHunk before the inner hunk loop. For diffs with many hunks, this avoids repeated allocations and transformations of the same slice.
nitishagar
force-pushed
the
fix/746-comment-anchor-integrity
branch
from
August 28, 2026 13:33
4bff89d to
3e7cd1f
Compare
A comment whose existing_code matches no file in the run was still emitted verbatim under its claimed path at start_line 0 / end_line 0, so advice about one file rendered on an unrelated file (pom.xml carrying Java findings, .gitignore carrying security findings). Three changes in the comment resolution chain: - Deterministic matching gains a whitespace-eliding second-chance tier (exact passes on both sides still outrank loose ones), so quotes that drift from the file only in internal spacing resolve and re-file instead of falling through every stage. - The LLM re-location rescue now runs only when the quote plausibly belongs to the claimed file (shares at least one non-trivial line with its diff). The step sees only that file's diff; when the quote shares nothing with it, the model can at best fabricate a location, which is how a wrong-file comment could end up looking located. - In review runs, a comment that ends resolution unlocated while carrying an anchorable quote is dropped with a comment_unresolved warning instead of being emitted under a path it does not belong to. Path-less comments bound to a grouped review's comma-joined key are dropped the same way. Comments without an anchorable quote on a reviewed file keep today's behavior, and scan keeps its collection behavior unchanged. Fixes alibaba#746
nitishagar
force-pushed
the
fix/746-comment-anchor-integrity
branch
from
August 31, 2026 16:14
3e7cd1f to
c28b044
Compare
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
ocr reviewcan emit a comment anchored to the wrong file: the reported cases are JavatoString()advice rendered onpom.xmland a Java@RequestMappingsecurity finding rendered on.gitignore, both withstart_line: 0, end_line: 0(#746).Root cause
When the model files a comment against path P while quoting code from another file, the resolution chain declines at every stage:
After all three, the comment was still collected and emitted verbatim under the claimed path at 0/0 (
internal/llmloop/loop.go, the unconditionalCommentCollector.Add). Nothing ever flagged or dropped it. Quote matching is also exact per line after trimming, so a quote drifting only in internal spacing (id )vsid)) defeats even the stages that could have saved it.Fix
Three targeted changes in the comment resolution chain:
internal/diff/resolver.go): after the exact passes fail on both sides of a hunk (and in the full-content scan), lines are compared with all whitespace elided. Exact matches always outrank loose ones, so existing anchors are unchanged; only quotes that differ purely in internal spacing gain resolution.pom.xmlshares none, and the step that could only fabricate a location is skipped.comment_unresolvedrun warning (same channel as the existingcomment_refiled) instead of being emitted under a path it does not belong to. Path-less comments silently bound to a grouped review's comma-joined key are dropped the same way. Comments with no anchorable quote on a reviewed file keep today's behavior (general advice), and scan keeps its collection behavior unchanged (the gate is scoped to review wiring).Trade-off
A comment whose quote matches nothing in the run is now dropped rather than emitted mis-anchored. The dropped path/summary is visible in the run's warnings, so nothing disappears silently — but the finding itself no longer appears in the report. I took the view that a wrong-file comment is worse than a dropped one (it was reported as a bug twice); if you prefer emission with an explicit
unresolvedmarker instead, the gate is one branch to change.Tests
-race; touched packages at 89.3% / 95.1% coverage.Fixes #746