ISSUE DESCRIPTION [BUG][auto] duplicate-overlapping-clone-groups: same duplication…
- User
ISSUE DESCRIPTION
[BUG][auto] duplicate-overlapping-clone-groups: same duplication emitted as two separate near-identical clone groups
Bug
pyscn's clone detector emits two separate clone groups that describe the same duplication relationship between the same two code fragments, with member windows shifted by exactly one line (the enclosing
with/header line). The result is a redundant clone group that inflatesclone_groupscount and the duplication percentage.This is related to but distinct from the (closed) #416
clone-overlapping-window-self-clone: #416 was about strict-subset members within a single group; here the redundancy is across two whole groups that are near-duplicates of each other.Reproducer
Repo:
Instagram/Fixit@bf8e1f55f8a606eae0f0c64bab575e84a2a608b3pyscn:v1.22.9curl -fsSL "https://codeload.github.com/Instagram/Fixit/tar.gz/HEAD" | tar -xz pyscn analyze --json --no-open Fixit-*/In the resulting
analyze.json,clone.clone_groupscontains two groups that cover the same pair of fragments insrc/fixit/tests/smoke.py:{ "id": 6, "type": 2, "similarity": 0.9692, "clones": [ {"location": {"file_path": ".../smoke.py", "start_line": 299, "end_line": 315}}, {"location": {"file_path": ".../smoke.py", "start_line": 318, "end_line": 334}} ] }, { "id": 14, "type": 2, "similarity": 0.9613, "clones": [ {"location": {"file_path": ".../smoke.py", "start_line": 298, "end_line": 315}}, {"location": {"file_path": ".../smoke.py", "start_line": 317, "end_line": 334}} ] }Both groups describe the duplication between the
subTest("lint")block and thesubTest("fix")block. Group 14's members each start exactly one line earlier than group 6's — that line is thewith self.subTest("lint"):/with self.subTest("fix"):header:with self.subTest("lint"): # line 298 (grp14 member start) with TemporaryDirectory() as td: # line 299 (grp6 member start) ... with self.subTest("fix"): # line 317 (grp14 member start) with TemporaryDirectory() as td: # line 318 (grp6 member start)Both groups end on the same lines (315 / 334). The two groups are the same logical clone reported twice at slightly different window boundaries.
Expected behavior
The clone-grouping/dedup stage should merge (or suppress) clone groups whose members are overlapping windows of the same underlying fragments, so each duplication relationship is reported once. As-is, the count (10 here) and the duplication score over-count by one redundant group.
Assistant
Let me start by understanding the repository structure and the issue. The bug is about duplicate overlapping clone groups in pyscn - the same duplication is emitted as two separate near-identical clone groups where one group's members start exactly one line earlier than the other's.
Let me explore the repository first.
Assistant
This seems to be a Go project. Let me explore the structure more, particularly the
internaldirectory where the clone detection logic likely resides.Assistant
Let me look at the clone-related files. The issue is about clone groups being duplicated. Let me find the core clone
Assistant
The key files are likely
group_dedup.go,clone_detector.go, and their tests. Let me examine them.Assistant
Now let me look at the clone_detector.go and the group_dedup_test.go:
Assistant
Let me also look at the grouping strategies and the connected grouping implementation
Assistant
Let me look at the connected_grouping.go and complete_linkage_grouping.go:
Assistant
Now let me look at the complete_linkage_grouping.go and the other grouping strategies:
Assistant
Now let me look at the group_dedup_test.go to understand what tests exist:
Assistant
Let me look at the
groupClonesmethod in the clone detector:Assistant
Let me look at the full clone detection flow:
Assistant
Let me just use grep to find the relevant code.
Assistant
Let me look at the full detect clones flow:
Assistant
Let me look at the DetectClonesWithContext method, which calls groupClonesWithStrategy:
Assistant
Let me now look at
groupClonesWithStrategyagainAssistant
Let me look at helper functions used throughout:
Assistant
Let me look at the star_medoid_grouping.go for these helper functions:
Assistant
Let me look at the grouping strategies test:
Assistant
Now let me look at the
grouping_mode.goto understand the groupingAssistant
Now I have a thorough understanding of the issue and the codebase. Let me implement the fix. The problem is in
group_dedup.go— it only handles within-group dedup but doesn't handle cross-group dedup where two separate groups describe the same duplication with slightly different window boundaries.Let me first check if I can build/run the existing tests:
Assistant
Let me set up the Go environment.
Assistant
Let me set up GOPATH and run tests.
Assistant
Let me set up the full Go environment.
Assistant
Good, all existing tests pass. Now let me implement the fix. I'll add cross-group dedup to
group_dedup.goand call it fromgroupClonesWithStrategyin `clone_detectorAssistant
Let me read the full file and then edit it.
Assistant
Now I'll modify
group_dedup.goto add the cross-group dedup function. Let me add it right before the `sortCloneGroupsAssistant
I see there's an unused struct
fileIdxin the code. Let me clean that up.Assistant
I see two issues: an unused struct and a duplicate function signature. Let me fix both
Assistant
Now let me fix the duplicate function signature:
Assistant
Let me verify the whole file looks good
Assistant
I see a bug - the
return outstatement is missing fromfilterClonePairsWithSuppressedMembers. Let me fix that:Assistant
There's a duplicate comment. Let me remove it
Assistant
Now let me modify
groupClonesWithStrategyinclone_detector.goto call the new cross-group dedupAssistant
Now I need to edit the
groupClonesWithStrategyfunction to add the cross-group dedup call.Assistant
Let me check the exact content of the relevant section in clone_detector.go
Assistant
I see the issue - the current file is showing
group_dedup.gobut we need to editclone_detector.go. Let me use the--fileoption explicitly.Assistant
Let me try using the
editcommand with line numbers instead:Assistant
Good. Now let me build and run the tests
Assistant
Build passes. Now let me run the existing tests:
Assistant
All existing dedup tests pass. Now let me run all the analyzer tests to make sure nothing is broken:
Assistant
All analyzer tests pass. Let me also run all tests in the project:
Assistant
All tests pass. Let me now also write a quick verification script to confirm the fix handles the exact scenario described in the bug report:
Assistant
Let me also verify that the
DetectClonesWithLSHmethod also goes through the samegroupClonesWithStrategypath:Assistant
Let me verify that all three detect methods go through the same
groupClonesWithStrategy:Assistant
All three detection methods go through
groupClonesWithStrategy, so the fix is applied to all paths. Let me do a final check on both modified files:Assistant
I see the diff has a missing blank line. Let me check the actual file state:
Assistant
Let me add the missing blank line for proper formatting:
Assistant
I need to add a proper blank line after the closing brace. Let me fix that:
Assistant
There's a duplicate comment. Let me fix it:
Assistant
Now let me verify the build and tests still pass:
Assistant
Let me run the full test suite one final time:
Assistant
All tests pass. Let me clean up the temp file:
Assistant
Let me do a final review of the changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.