alibaba / alibaba/open-code-review

Review comment attaches to the first same-file existing_code match when duplicates exist

Open
#991 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
24.4k
Forks
1.8k
Avg merge
2d 4m
Merged PRs (30d)
102

Description

### OpenCodeReview Version

open-code-review v1.9.5 (ea1de41a) darwin/arm64 built at: 2026-08-17T03:52:37Z https://github.com/alibaba/open-code-review

### Operating System

macOS (Apple Silicon)

### Installation Method

npm (global)

### LLM Provider

Other OpenAI-compatible endpoint

### Bug Description

When the same `existing_code` appears multiple times in the same file, OCR may attach the review comment to the first matching location instead of the location the model actually commented on.

I noticed that PR #921 fixed a related duplicate matching issue for cross-file relocation, where the same code snippet may appear in multiple files. This issue is slightly different: the duplicate candidates are in the same file.

In this case, the file contains two identical lines:

```go
ev.ErrorClass = ArgosRuntimeStatusTimeout
```

The model commented on the second occurrence in the `Analyze` branch, where a non-timeout error was incorrectly marked as timeout. However, OCR attached the final review comment to the first identical occurrence at line 286.

Image

### Steps to Reproduce

1. Run `ocr review` on a diff where the same `existing_code` appears multiple times in the same file.
2. Make the model produce a `code_comment` whose `existing_code` matches those repeated snippets.
3. Open the generated review result.
4. Observe that the comment is attached to the first matching location instead of the later location that the comment content refers to.

### Expected Behavior

When `existing_code` matches multiple candidate locations within the same file, OCR should not directly choose the first match.

If the target code block can be determined from the comment content, surrounding context, or candidate locations, OCR should attach the comment to the corresponding location.

If OCR cannot determine the target location reliably, it should avoid outputting an incorrect precise line number and keep the comment unlocated instead.

### Additional Context

I have a #992 ready to address the ambiguous location resolution when `existing_code` has multiple candidate matches.

Contributor guide

Open the contributing guide

Research direction

Start with the ocr review flow that resolves code_comment existing_code matches, using PR #921's related cross-file matching change as context. Reproduce the case with repeated same-file snippets and verify that ambiguous candidates are not assigned the first line, while an unresolved comment remains unlocated.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.