fix(diff): decline ambiguous same-file existing_code matches #1368
All Vouch review confidence checks passed
Residual risk 0.06 = Change Risk (0.44) × (1 − Review Confidence (0.87)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.44 · 94 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.89 · 2 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.272
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
4 items
 <br/>All committers have signed the CLA.
<!-- ocr-summary -->
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).
Approved
Clean refactoring, reuses matchConsecutive properly, drops blind first-match guessing for ambiguous duplicates. Solid tests. LGTM, pending CLA clearance
Bangkah
alter
Description
Fixes #991. When a review comment's
existing_codematches more than one identical location within the same file,matchConsecutive(andresolveFromFileContent's own separate copy of the same scan) returned the first occurrence, so the comment could be anchored to the wrong line. For example, the model's comment about the second occurrence of a duplicated line would land on the first one instead.This is the minimal fix the issue reporter proposed themselves: when a same-file match is ambiguous, decline instead of guessing, the same way
RelocateAcrossFilesalready declines when the same snippet shows up in more than one file. Callers already treat a decline as "still unresolved" and fall through to cross-file relocation and then LLM-based re-location (internal/llmloop/loop.go), so an ambiguous match now gets a real shot at disambiguation instead of landing on a silently wrong line number.resolveFromFileContenthad its own separate first-match-wins loop instead of callingmatchConsecutive. It now builds an[]indexedLineand reusesmatchConsecutive, so the hunk-based and whole-file-fallback paths share one matching rule.Type of Change
How Has This Been Tested?
TestMatchConsecutive_AmbiguousMatchDeclines,TestResolveLineNumbers_FallbackToFileContent_AmbiguousMatchKeepsZero) to assert the corrected decline instead, and addedTestResolveFromHunk_AmbiguousDuplicateDeclinesfor the hunk-level path andTestMatchConsecutive_OverlappingDuplicateDeclinesfor overlapping duplicate windows. All were confirmed failing against the pre-fix code before landing.resolveFromFileContentrefactor were each introduced on purpose and confirmed caught by the suite, then reverted.make test: no new failures vs. main (one pre-existing, environment-specific failure ininternal/diff.TestCommitDiffMergeCommitReviewsFirstParentDiff, unrelated to this change, root-caused to a localmerge.ff=onlygit config, not a code defect).make vet,make build,gofmt -s -l .,go run scripts/verify-english-only.goall pass. Coverage floor independently confirmed above 90% (91.6% total / 94.3% forinternal/diff) with that one pre-existing failing test skipped.AI/LLM Disclosure
I used an AI coding assistant (Claude Code, Claude Sonnet 5) to research open issues, identify this one as a well-scoped, uncontested fix, draft the fix and its tests, and run the verification commands above. I reviewed and understand every line of the change before opening this PR.