← Back to Pull requests

fix(diff): decline ambiguous same-file existing_code matches #1368

Open
alter opened this pull request with 94 lines diff across 2 files
View on GitHub
alter alter commented on Sep 17, 2026 09:45 UTC
Author

Description

Fixes #991. When a review comment's existing_code matches more than one identical location within the same file, matchConsecutive (and resolveFromFileContent'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 RelocateAcrossFiles already 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.

resolveFromFileContent had its own separate first-match-wins loop instead of calling matchConsecutive. It now builds an []indexedLine and reuses matchConsecutive, so the hunk-based and whole-file-fallback paths share one matching rule.

Type of Change


  • Bug fix (non-breaking change that fixes an issue)
  • How Has This Been Tested?


  • Renamed/rewrote the two existing tests that asserted the old "first match wins" behavior (TestMatchConsecutive_AmbiguousMatchDeclines, TestResolveLineNumbers_FallbackToFileContent_AmbiguousMatchKeepsZero) to assert the corrected decline instead, and added TestResolveFromHunk_AmbiguousDuplicateDeclines for the hunk-level path and TestMatchConsecutive_OverlappingDuplicateDeclines for overlapping duplicate windows. All were confirmed failing against the pre-fix code before landing.

  • Manual mutation testing (reverse control): dropping the ambiguity guard, an off-by-one on the guard's boundary, and reverting only the resolveFromFileContent refactor 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 in internal/diff.TestCommitDiffMergeCommitReviewsFirstParentDiff, unrelated to this change, root-caused to a local merge.ff=only git config, not a code defect).

  • make vet, make build, gofmt -s -l ., go run scripts/verify-english-only.go all pass. Coverage floor independently confirmed above 90% (91.6% total / 94.3% for internal/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.

    Diff: 94 lines (+62 / -32) across 2 files Reviewer: Bangkah Review duration: 73835m
    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
    0.44
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.89 · 2 substantive comment(s)
    0.89
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    87%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    CLAassistant CLAassistant commented on Sep 17, 2026 09:45 UTC
    Contributor
    github-actions[bot] github-actions[bot] commented on Sep 17, 2026 09:46 UTC
    Bot

    <!-- ocr-summary -->
    ✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).

    Bangkah Bangkah approved these changes on Sep 17, 2026 10:29 UTC
    Approved Reviewer

    Clean refactoring, reuses matchConsecutive properly, drops blind first-match guessing for ambiguous duplicates. Solid tests. LGTM, pending CLA clearance

    Reviewers
    Assignees
    alter alter
    Labels
    risk: low confidence: 87.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.7% (MEDIUM) · Higher = larger blast radius
    43.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 87.1% · Lower = rushed or shallow review
    87.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 5.6% · Safe to merge
    5.6%