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 analyze this issue. The bug is about duplicate-overlapping-clone-groups in the pyscn clone detector. Two separate clone groups are being emitted that describe the same duplication relationship, with member windows shifted by exactly one line.
Let me start by exploring the repository structure to understand how the code works.
Assistant
I need to understand the repository structure better, particularly the clone detection module.
Assistant
This is a Go project. Let me explore the Go source code, particularly the clone detection module.
Assistant
The issue is about duplicate clone groups being emitted. Let me look at the clone detector and related files to understand how clone groups are generated and how they could be deduplicated.
Assistant
Let me explore the clone detector module, which is where the clone groups are generated.
Assistant
Now let me look at the clone grouping logic, which is where duplicate groups are likely generated:
Assistant
Let me look at the grouping strategies:
Assistant
The user wants me to fix a bug where duplicate-overlapping-clone-groups are emitted. Let me continue exploring the grouping logic to understand how clone groups are created and how they could be deduplicated.
Let me look at the grouping strategy file and any deduplication logic.
Assistant
Let me continue exploring. I need to find where clone groups are actually created and look at the dedup test file that's already there.
Assistant
Let me look at the deduplication implementation:
Assistant
Now I need to look at the deduplication implementation. Let me read the
group_dedup.gofile to understand how deduplication works.Assistant
Now I understand the issue better. The existing deduplication handles overlapping members within a single group, but the bug is about TWO SEPARATE clone groups that describe the same duplication relationship. Let me look at how groups are generated and find where this cross-group deduplication should happen.
Assistant
Now let me look at the connected grouping implementation:
Assistant
The user wants me to fix a bug where duplicate clone groups are being emitted. The issue is that two separate clone groups describe the same duplication relationship with member windows shifted by exactly one line. Let me continue exploring the connected grouping code to understand how clone groups are created, then figure out where to add deduplication.
Assistant
Now I understand the problem better. The issue is that the clone detector can produce clone pairs that result in two separate clone groups that describe essentially the same duplication, but with slightly different window boundaries (shifted by one line). Let me look at where the clone pairs are created to understand why this might happen.
The key insight from the issue is:
- Group 6: fragments at lines 299-315 and 318-334
- Group 14: fragments at lines 298-315 and 317-334
The difference is exactly 1 line - the
with self.subTest(...)header line is included in group 14 but not in group 6.Let me look at how fragments are generated to understand why two different fragment sets are being created.
Assistant
Let me continue exploring to understand where the deduplication should be added:
Assistant
Let me look at the domain clone structure:
Assistant
Let me look at the flow of clone detection more carefully to understand where deduplication happens:
Assistant
Now I understand the issue. The deduplication currently only handles overlapping members within a single group, but not duplicate groups across multiple groups. Let me look at the existing test files to understand the helper functions better, then I'll create a reproducer and implement the fix.
Assistant
Now let me find where the helper functions
gfandgpare defined:Assistant
Now let me look at the helper functions and understand the test structure:
Assistant
Let me look at how the clone pairs are generated to understand why two separate groups with near-duplicate members are created:
Assistant
Now I have a good understanding of the issue. Let me look at the fragment extraction to understand how overlapping fragments get created:
Assistant
Now I have a good understanding of the issue. Let me first run the existing tests to ensure everything works, then create a reproducer for the bug.
Assistant
The user wants me to continue fixing the bug about duplicate-overlapping-clone-groups. Let me continue with my plan. I need to:
- Set up Go environment
- Run existing tests to confirm they pass
- Create a reproducer for the bug
- Implement the fix
- Verify the fix
Let me first set up the Go environment and run the tests.
Assistant
The user wants me to continue fixing the bug about duplicate-overlapping-clone-groups. Let me continue with my plan - I need to set up Go environment and run tests.
Assistant
I need to understand the bug better. The issue is that two separate clone groups are being emitted that describe the same duplication relationship, but with member windows shifted by exactly one line.
Let me look at how the issue happens. The problem is:
- Group 6: fragments at lines 299-315 and 318-334
- Group 14: fragments at lines 298-315 and 317-334
Both groups describe the same pair of duplicated fragments (the subTest blocks), but one group includes the
with self.subTest(...)header line in each fragment, and the other doesn't.The existing deduplication only handles overlapping members within a single group. But the bug is about two SEPARATE groups that are near-duplicates of each other.
I need to:
- Run the tests to understand what's happening
- Write a reproducer test for this specific issue
- Implement a fix that detects and deduplicates these near-identical groups
Let me first look at how the clone groups are created and understand why two groups are being emitted.
Assistant
Now I understand the issue clearly. The existing deduplication (
dedupeStrictSubsetGroupMembers) only handles overlapping members WITHIN a single group, but not duplicate groups ACROSS multiple groups. When two groups describe the same duplication relationship with members that are subsets/supersets of each other across groups, they're both kept.Let me first write a test that reproduces this issue:
Assistant
Now I understand the issue. Let me create a test that reproduces the bug first, then implement the fix.
Assistant
Let me fix the test file - the import statement is in the wrong place:
Assistant
The user wants me to continue fixing the bug about duplicate-overlapping-clone-groups. I've created a test file that reproduces the issue. Let me run the tests to confirm they fail, then implement the fix.
Assistant
The tests fail as expected (3 out of 4), confirming the bug. The partial overlap test passes correctly - we should keep both groups when they describe different duplications.
Now let me implement the fix. The approach is to add a cross-group deduplication pass that detects when two groups describe the same duplication relationship (same files, overlapping windows) and removes the duplicate.
Assistant
I've added the new deduplication functions, but I need to integrate them into the existing
dedupeStrictSubsetGroupMembersfunction. Let me also check thatisOverlappingLocationisn't already defined elsewhere to avoid a redeclaration error.Assistant
There's already
isOverlappingLocationas a method onCloneDetector. Let me check for naming conflicts and fix the approach. I need to update the dedup logic to also call the new cross-group dedup function:Assistant
The command had a typo - it used
-n "func isOverlappingLocation"with-nwhich is a flag for grep but the directory is a directory, not a file. Let me fix this.Assistant
There's a naming conflict - I've added a standalone function
isOverlappingLocationingroup_dedup.go, but there's already a methodisOverlappingLocationonCloneDetectorinclone_detector.go. Since they're in the same package, this will cause a redeclaration error. Let me fix this.Assistant
Let me run the tests to see if the fix works:
Assistant
I see - the new deduplication functions are defined but not being called. I need to integrate
dedupeDuplicateGroupsinto the existingdedupeStrictSubsetGroupMembersfunction. Let me update the code:Assistant
I see the problem. The
dedupeDuplicateGroupsfunction is defined but not being called bydedupeStrictSubsetGroupMembers. I need to integrate it. Let me update the code to calldedupeDuplicateGroupsafter the initial intra-group filtering:Assistant
Let me open the file first and then make the edit.
Assistant
I need to use bash to edit the file since the open command didn't work. Let me use sed or a different approach:
Assistant
The user wants me to continue fixing the bug about duplicate-overlapping-clone-groups. I've added the new deduplication functions but I need to integrate
dedupeDuplicateGroupsinto thededupeStrictSubsetGroupMembersfunction. The edit command didn't work because no file was open. Let me use a different approach to modify the file.Assistant
Let me check if the sed worked correctly by looking at the file:
Assistant
The sed command corrupted the file. I need to rewrite it properly. Let me recreate the entire file correctly.
Assistant
Now let me verify the build and run the tests:
Assistant
Build succeeded. Now let me run the tests to see if the cross-group deduplication is working:
Assistant
All 4 new tests pass. Now let me run all existing dedup tests to make sure the fix doesn't break them:
Assistant
All dedup and grouping tests pass. Now let me run the full analyzer test suite to make sure nothing is broken:
Assistant
All tests pass. Now let me run the broader test suite to make sure the changes don't break anything else:
Assistant
All tests pass. Let me verify the fix handles edge cases correctly by adding a few more tests:
Assistant
The user wants me to continue fixing the bug about duplicate-overlapping-clone-groups. I've added new test cases and need to run them to verify the fix works correctly.
Assistant
All 7 cross-group deduplication tests pass. Now let me run the full test suite to make sure nothing is broken:
Assistant
All tests pass. Let me verify the complete fix by running the full test suite one final time and checking the diff:
Assistant
The user wants me to verify the complete fix. Let me check the git diff to see the full changes, then verify everything is correct before submitting.
Assistant
The user wants me to verify the complete fix before submitting. Let me check what files have been modified and ensure everything is correct. I need to also check if there are any untracked test files.
Assistant
The fix is complete and verified. Let me summarize what was done:
Summary of Changes
Problem
The clone detector was emitting two separate clone groups that described the same duplication relationship between the same two code fragments, with member windows shifted by exactly one line (the enclosing
with/header line). This resulted in redundant clone groups inflatingclone_groupscount and the duplication percentage.Root Cause
The existing deduplication (
dedupeStrictSubsetGroupMembers) only handled overlapping members within a single group, but did not handle duplicate groups across multiple groups.Fix
Assistant
All tests pass. Let me submit the changes.
Assistant
Let me use the correct syntax for the submit command.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.