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
I'll start by exploring the repository structure and understanding how clone grouping/dedup works, then reproduce the overlapping-groups bug.
- Assistant
Let me find the clone detection related code, particularly around grouping and deduplication.
- Assistant
There's already a
group_dedup.go— I'll inspect that and related clone grouping code. - Assistant
The existing dedup only handles overlaps within a group; next I'll look at how groups are built and where cross-group dedup should plug in.
- Assistant
So the grouping happens at
groupClonesWithStrategywhich already callsdedupeStrictSubsetGroupMembers. I need to add another pass that deduplicates across groups when they are near-identical overl... - Assistant
I need slightly more context on fragment extraction and how overlapping nestings turn into multiple groups.
- Assistant
I'll check the changelog and recent commits for the intended design of group-level dedup.
- Assistant
Next I'll check how clone pairs and groups feed the duplication percentage and related metrics.
- Assistant
Let me look at how CodeDuplication percentage is calculated from clone groups.
- Assistant
Let me look at how analyze computes CodeDuplication and density.
- Assistant
I'll recreate the Fixit nested-
withpattern as a minimal fixture and run clone detection against it. - Assistant
Let me build pyscn and try to reproduce.
- Assistant
Need to set GOPATH
- Assistant
The build seems complete? Let me check if the binary exists.
- Assistant
Let me look at the clone groups in the resulting JSON.
- Assistant
My simplified fixture only produced one group — I'll pull Fixit's smoke.py and inspect lines 298–334.
- Assistant
Running clone analysis on Fixit's smoke.py to reproduce the duplicate groups.
- Assistant
Only 4 groups when analyzing just smoke.py. Let me check groups.
- Assistant
Running the full Fixit repo analysis to match the original reproducer.
- Assistant
9 groups instead of 10. Let me check the smoke.py related groups.
- Assistant
I'll check whether group IDs are reassigned and how groups become domain objects.
- Assistant
Let me also look at helper functions: fragmentLess, pairKey locations, and gf helper in tests.
- Assistant
Implementing the cross-group dedup next, starting with the group_dedup helpers.
- Assistant
Implementing cross-group overlapping dedup in
group_dedup.goand wiring it into the grouping path. - Assistant
Adding overlapping-group dedup and composing it with the existing subset-member pass.
- Assistant
I'll fix the comment typo and wire the new dedupe into the grouping path.
- Assistant
The previous replaces didn't apply cleanly — retrying them with explicit file paths.
- Assistant
Let me read the actual comment text
- Assistant
I'll apply the typo fix and wire-up with targeted edits.
- Assistant
Now I can edit line 164
- Assistant
Good. Now wire clone_detector.go
- Assistant
edit line 1125
- Assistant
Rebuild and verify the Fixit case, then run the group_dedup unit tests.
- Assistant
Existing tests pass. Let me rebuild and verify Fixit.
- Assistant
Confirming pairs remain while the duplicate group is dropped, then running a temporary unit check.
- Assistant
Running the full analyzer test package and a quick compile check.
- Assistant
Confirming the rest of
group_dedup.gois intact after the edits.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.