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 understand the issue:
- pyscn's clone detector is producing duplicate clone groups that describe the same duplication relationship between the same two code fragments.
- The two groups differ only by whether the enclosing
with/header line is included, shifting the window by exactly one line. - This is related to but distinct from issue #416 about overlapping window self-clones.
Let me start by exploring the repository structure to understand how it's organized and find the relevant code.
Assistant
This is a Go project. Let me explore the structure more to understand the codebase.
Assistant
Let me explore the domain/ and service/ directories, as those likely contain the clone detection logic.
Assistant
Let me look for clone-related files to understand the clone detection and grouping logic.
Assistant
The key file seems to be
./internal/analyzer/group_dedup.gowhich likely contains the deduplication logic for clone groups. Let me look at the relevant files.Assistant
Now let me look at the grouping strategies and the clone detector to understand how groups are formed
Assistant
Let me look at complete_linkage_grouping.go and centroid_grouping.go.
Assistant
Now let me look at the centroid grouping and the clone detector to understand how groups are formed and deduped.
Assistant
Now let me look at the clone detector to understand how pairs are generated and how groups are formed and deduped after grouping
Assistant
Let me see the full clone_detector.go file including the groupClones method:
Assistant
Let me look at
connected_grouping.goto understand how groups are formed:Assistant
Let me look at the group_dedup_test.go to understand what's already tested:
Assistant
Let me understand how fragments are extracted and how clone pairs are generated:
Assistant
Let me look at the ExtractFragmentsWithSource method and the LSH path:
Assistant
Let me look at
isFragmentCandidateandshouldIncludeFragment:Assistant
Let me see these functions:
Assistant
Let me look at the grouping mode and understand how groups are created:
Assistant
Let me look at helper functions used in group_dedup.go:
Assistant
Let me look for helper functions like
pairKey,averageGroupSimilarity,fragmentLess,almostEqual:Assistant
Let me look at the star_medoid_grouping.go for the helper functions:
Assistant
Now I have a good understanding of the codebase. Let me look at the
group_dedup_test.goone more time to see the test helpergf:Assistant
Let me see the gf function:
Assistant
Now I have a thorough understanding of the problem and the codebase. Let me now implement the fix.
The issue is that
dedupeStrictSubsetGroupMembersonly handles strict-subset members within a single group, but the bug is about two separate groups that are near-duplicates. I need to add a cross-group dedup pass that merges groups whose members are overlapping windows of the same underlying fragments.Assistant
Let me open the file properly
Assistant
Let me see the rest of the file:
Assistant
Now I'll implement the fix. The approach is to add a cross-group dedup pass that merges groups whose members are overlapping windows (same file, overlapping line ranges) and where every fragment in one group has an overlapping counterpart in the
Assistant
I made a mess with duplicate code. Let me see the full file and fix
Assistant
I need to revert and start fresh. Let me restore the original
Assistant
Good. Now let me verify the original file
Assistant
Now let me write the complete new file. I'll use the replace command to add the cross-group dedup functionality
Assistant
Let me use the proper format:
Assistant
Good, now I need to add the
dedupeOverlappingGroupsfunction and its helpers. Let me add them beforesortCloneGroupsAssistant
Let me navigate to the right line:
Assistant
Now let me edit to add the new functions before
sortCloneGroups:Assistant
Let me verify the complete file looks correct
Assistant
Now let me check if it compiles:
Assistant
Let me check Go environment:
Assistant
Let me set up Go environment properly:
Assistant
Let me set up all needed Go environment variables:
Assistant
Build succeeded. Now let me run the existing tests:
Assistant
All existing dedupe tests pass. Let me run the full analyzer test suite:
Assistant
All analyzer tests pass. Let me also run the clone service and
Assistant
Let me also run the integration tests
Assistant
All tests pass. Let me also run the tests for the complete project to make sure nothing is broken:
Assistant
All tests pass. Let me verify my changes with
git diffAssistant
Now let me write a quick test to validate the fix handles the reported scenario. Let me create a temporary test:
Assistant
Let me add a test case for the reported scenario to the test file temporarily to verify:
Assistant
Let me write a quick ad-hoc test to confirm the fix works for the exact scenario from the issue
Assistant
All three custom tests pass. Let me remove the temporary test file:
Assistant
Let me run all tests one final time to confirm everything is clean:
Assistant
All tests pass. Let me verify the final state of my changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.