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 clone groups being emitted by the pyscn clone detector. Two separate clone groups describe the same duplication relationship between the same two code fragments, with member windows shifted by exactly one line.
Let me start by exploring the repository structure to understand how it's organized.
Assistant
Let me look at the project structure more broadly and find the clone detection code.
Assistant
This is a Go project. Let me explore the internal clone detection code.
Assistant
Let me explore the clone-related files more closely:
Assistant
Let me look at the clone detection and grouping code. The issue is about duplicate clone groups being emitted, so I should focus on the grouping/dedup stage.
Assistant
Let me look at the grouping and dedup code more closely:
Assistant
Let me examine the group dedup file first:
Assistant
Now let me look at the clone grouping files and see how groups are created:
Assistant
Let me look at the different grouping strategies:
Assistant
Now let me look at the clone detector to understand how clone pairs are found:
Assistant
Let me understand how clone pairs are generated and look at the test files:
Assistant
Let me understand the full analysis pipeline and how clone groups flow through:
Assistant
Let me look at the grouping mode and how the analysis pipeline works:
Assistant
Let me understand how clone groups flow through the system. I need to see where groups are finalized and if there's any cross-group deduplication:
Assistant
Now I understand the issue better. Let me look at the DetectClones function and the flow:
- Clone pairs are detected (pairs of fragments that are similar)
- Clone groups are built from pairs using a grouping strategy
- The
dedupeStrictSubsetGroupMembersfunction only deduplicates within a single group (removing subset members from the same file)
But the bug is about TWO SEPARATE CLONE GROUPS that describe the same duplication. This is a cross-group dedup issue, not an intra-group dedup issue.
Assistant
Let me search for how clone groups are created and look for any deduplication logic between groups:
Assistant
Now I understand the issue. Let me look at the flow more carefully:
Assistant
Now I need to understand the full DetectClonesWithContext function to see the flow from fragments to clone pairs to clone groups.
Assistant
Let me look at the existing tests and understand the clone detection flow better:
Assistant
Now I understand the issue. The bug is about cross-group deduplication - two separate clone groups describe the same duplication relationship between the same pairs of code fragments, just with slightly different window boundaries (one line shifted). The current
dedupeStrictSubsetGroupMembersonly handles intra-group deduplication (removing subset members within a single group).Let me look more at how groups can overlap:
Assistant
Let me examine how clone pairs are generated and look at the clone detector test:
Assistant
Now I understand the issue clearly. The bug is about cross-group deduplication - two separate clone groups describe the same duplication relationship between the same pairs of code fragments, with member windows shifted by exactly one line. The current
dedupeStrictSubsetGroupMembersonly handles intra-group deduplication.Let me look at the full structure of the group_dedup.go file to understand how to add cross-group deduplication:
Assistant
Let me examine the clone detector test file to see if there are any existing tests for cross-group deduplication:
Assistant
Now I have a clear understanding of the issue. The bug is about cross-group deduplication: two separate clone groups describe the same duplication relationship with member windows shifted by one line. The current
dedupeStrictSubsetGroupMembersonly handles intra-group deduplication.Let me examine how the
groupClonesWithStrategyfunction works and understand the full flow:Assistant
Let me look for the helper functions used in the dedup:
Assistant
Let me look at the test file to see how
gfandgpare defined for tests:Assistant
Let me understand how fragments are extracted to understand how duplicate groups arise:
Assistant
Let me look at how fragments are extracted to understand how duplicate groups can arise.
Assistant
Now I have a clear understanding of the issue. The problem is cross-group deduplication - two separate clone groups describe the same duplication relationship between the same pairs of code fragments, with member windows shifted by exactly one line. The current
dedupeStrictSubsetGroupMembersonly handles intra-group deduplication (removing subset members within a single group), but doesn't handle the case where TWO SEPARATE groups describe the same duplication.Let me first look at how tests work and try to create a reproduction:
Assistant
Now I have a clear understanding of the issue. Let me create a test to reproduce the bug, then implement the fix.
The bug is about cross-group deduplication - two separate clone groups describe the same duplication relationship with member windows shifted by exactly one line. The current
dedupeStrictSubsetGroupMembersonly handles intra-group deduplication.Let me first write a test to reproduce this:
Assistant
Let me check the Go environment.
Assistant
The user wants me to continue fixing the duplicate-overlapping-clone-groups bug. Let me check my current state - I need to verify that the Go environment is properly configured and then run the tests.
Looking at the previous output, it seems the go module cache issue was resolved (the tests ran but showed all tests were skipped). Let me check if there's a go.mod file and set up the environment properly.
Let me check what's happening and run the tests properly.
Assistant
It seems the command ran but didn't produce any output, which is unusual. Let me check if Go is properly configured and the environment variables are set.
Assistant
Good, the environment is set up properly. Let me first run the existing tests to understand the baseline:
Assistant
Now I have a clear understanding of the issue. The bug is about cross-group deduplication - two separate clone groups describe the same duplication relationship with member windows shifted by exactly one line. The current
dedupeStrictSubsetGroupMembersonly handles intra-group deduplication (removing subset members within a single group), but doesn't handle the case where TWO SEPARATE groups describe the same duplication.Let me first create a test that reproduces this issue:
Assistant
Now I understand the issue clearly. The bug is about cross-group deduplication - two separate clone groups describe the same duplication relationship with member windows shifted by one line. The current
dedupeStrictSubsetGroupMembersonly handles intra-group deduplication.Let me first write a test to reproduce this exact issue:
Assistant
Now let me run the test to confirm it fails (reproduces the bug):
Assistant
The test reproduces the bug - we get 2 groups instead of 1. Now I need to implement the cross-group deduplication logic.
The issue is that two separate clone groups describe the same duplication relationship with member windows shifted by one line. I need to add a cross-group deduplication pass.
Let me look at the current
groupClonesWithStrategyfunction and understand how to add cross-group deduplication:Assistant
Now I need to implement the cross-group deduplication logic. The issue is that two separate clone groups describe the same duplication relationship with member windows shifted by one line. I need to add a new deduplication pass that:
- After intra-group deduplication is done, examines all remaining groups
- If two groups describe the same duplication relationship (i.e., they have the same set of files with overlapping windows), keep only the one with more specific/inner windows
Let me implement this in the
group_dedup.gofile:Assistant
Now I understand the issue completely. I've reproduced the bug with the test. The problem is that two separate clone groups describe the same duplication relationship with member windows shifted by one line. I need to implement a cross-group deduplication pass.
Let me implement the fix in
group_dedup.go:Assistant
Let me fix the import statement first and then add the cross-group deduplication logic.
Assistant
Let me try a different approach - I'll write the complete updated file:
Assistant
Let me run the test to see if the fix works:
Assistant
The test is still failing. Let me debug this by checking what the groups actually look like:
Assistant
Let me add more debugging to understand what's happening:
Assistant
Let me copy the debug test to the test file and run it:
Assistant
I see the issue. The debug output shows 2 groups after cross-group dedup, which means my deduplication logic isn't working correctly. The problem is in the
isDuplicatefunction - when y.py fragments are equal, it resets bothg1Tighterandg2Tighterto false, which then fails the final decision logic.Let me fix the logic:
Assistant
The code has a syntax error - I used an undefined constant
decUndecided. Let me fix this.Assistant
I need to fix the syntax error with the iota constants. Let me rewrite the file with the constants properly defined:
Assistant
Now let me run the test to see if the fix works with the proper constant definitions.
Assistant
Good, the build succeeded. Now let me run the test:
Assistant
The test passes. Let me run all existing dedup tests to make sure I haven't broken anything:
Assistant
All dedup tests pass. Now let me remove the debug test file and run all analyzer tests to make sure I haven't broken anything:
Assistant
Now let me run all the existing tests in the analyzer package to make sure nothing is broken:
Assistant
All analyzer tests pass. Now let me run the full test suite across all packages to make sure nothing is broken:
Assistant
All tests pass. Now let me add more comprehensive tests to cover edge cases for the cross-group deduplication logic:
Assistant
Now let me run the new tests to verify they all pass.
Assistant
All new tests pass. Let me run all the existing dedup tests and all analyzer tests to make sure everything still works:
Assistant
Let me run the full test suite across all packages:
Assistant
All tests pass. Let me verify the final state of the changes by reviewing the code:
Assistant
The user has provided a git diff showing my changes to
group_dedup.go. The changes look correct. Let me verify the test changes as well and make sure everything is in order before submitting.Assistant
Let me verify the current state of the repository and run the tests one final time.
Assistant
Let me run the full test suite one final time to confirm everything is working correctly.
Assistant
All tests pass. Let me provide a summary of the changes and submit.
Summary
I've fixed the
duplicate-overlapping-clone-groupsbug by adding cross-group deduplication to the clone detection pipeline.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 / header). For example:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.