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 exploring the repository structure to understand the codebase and then reproduce the issue.
- Assistant
Let me explore the structure more, especially looking for clone-related files.
- Assistant
Let me look at the clone detection and grouping logic. The issue is about duplicate/overlapping clone groups. Let me start with the domain layer.
- Assistant
Let me look at the clone detector implementation to understand how clone grouping works.
- Assistant
I see the file is truncated. Let me view the grouping-related parts:
- Assistant
Let me search for the grouping functions in the file.
- Assistant
Let me look at the DetectClones methods and the grouping logic:
- Assistant
Let me look at the grouping strategies and deduplication functions:
- Assistant
Let me look at the group_dedup.go file:
- Assistant
Now I understand the existing dedup logic. It handles within-group dedup (removing strict subsets from a single group). But the issue is about two separate groups that are near-duplicates of each other (same pair of fragments, slightly different window boundaries). Let me look at the grouping strategies to understand how groups are formed:
- Assistant
Let me look at the connected grouping strategy and other grouping implementations:
- Assistant
Let me look at the connected grouping implementation:
- Assistant
Let me look at the test file for group_dedup and how the groups are tested:
- Assistant
Now let me look at the helper functions used in grouping:
- Assistant
Let me find the helper functions like
pairKey,fragmentLess,averageGroupSimilarity: - Assistant
Let me look at these helper functions:
- Assistant
Let me also look at the test helper functions:
- Assistant
Let me see that helper:
- Assistant
Let me look at the full
groupClonesWithStrategyfunction: - Assistant
Let me also run the existing tests to make sure they pass:
- Assistant
Let me set up the Go environment:
- Assistant
Let me set up GOPATH:
- Assistant
Let me check the GOPATH setup:
- Assistant
Let me set GOPATH and HOME:
- Assistant
Good, all existing tests pass. Now let me implement the fix. I need to add a function to detect and suppress overlapping clone groups across groups (not just within a group).
Let me first write a test to reproduce the exact issue:
- Assistant
Now let me implement the fix. I'll add the
dedupeOverlappingGroupsfunction togroup_dedup.go: - Assistant
Let me see the rest of the file:
- Assistant
Now let me implement the fix. I'll add the
dedupeOverlappingGroupsfunction togroup_dedup.go: - Assistant
I see there's a duplicate
sortCloneGroupsfunction. Let me fix that: - Assistant
I need to remove the first (incomplete) duplicate of
sortCloneGroups: - Assistant
Let me verify the fix:
- Assistant
Let me see the full file:
- Assistant
Good, the file looks clean. Now let me verify it compiles:
- Assistant
Good, it compiles. Now let me modify
groupClonesWithStrategyto calldedupeOverlappingGroups: - Assistant
Now let me edit the
groupClonesWithStrategyfunction to calldedupeOverlappingGroups: - Assistant
Good. Let me verify it compiles and run existing tests:
- Assistant
Good, it compiles. Let me run the existing tests:
- Assistant
All existing tests pass. Now let me write a test that reproduces the exact issue. Let me add tests for
dedupeOverlappingGroups: - Assistant
Now let me add tests for the new
dedupeOverlappingGroupsfunction: - Assistant
I see there's a duplicate closing brace issue. Let me check and fix:
- Assistant
I see the duplicate. Let me fix it:
- Assistant
Let me verify:
- Assistant
Good, the duplicate is fixed. Let me run the tests:
- Assistant
All tests pass, including the new ones. Let me also run the broader test suite to make sure I haven't broken anything:
- Assistant
All analyzer tests pass. Let me also run the broader test suite:
- Assistant
All tests pass across the entire repository. Let me also quickly check the integration tests:
- Assistant
All tests pass. Let me now review the final state of my changes:
- Assistant
Let me look at the full diff:
- Assistant
The diff looks clean. Let me clean up the comment in the
TestOverlappingGroups_PartialOverlapBothKepttest that has my thought process: - Assistant
Let me clean up that comment:
- Assistant
I see there's a duplicate line. Let me fix it:
- Assistant
Good, the duplicate is fixed. Let me run all the tests one final time:
- Assistant
All 21 tests pass. Let me run the full test suite one more time to confirm nothing is broken:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.