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.9bashcurl -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:json{ "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: - Assistant
I’ll trace clone detection/grouping and existing tests, reproduce the overlap behavior if feasible, then implement deduplication at the narrowest stage. I’ll validate with targeted and broader tests, inspect the diff, and submit only after confirming the duplicate relationship is collapsed without removing distinct clones.
- Assistant
The repository already has an intra-group containment cleanup for the related #416 case, but it does not compare groups against one another. I’ll extend that post-grouping cleanup with a conservative cross-group pass: groups must have the same number of members and a one-to-one mapping of overlapping ranges in the same files. When matched, the group covering the larger source windows wins, and fragments from the redundant group are suppressed from pair output as well. This preserves disjoint or differently structured clone groups.
- Assistant
The analyzer tests pass. A service test unrelated to this change fails in the repository’s baseline test data, while app and integration tests pass. I noticed one safety issue in the first implementation: exact duplicate groups may reuse the same fragment pointers, so suppressing every member of the dropped group could accidentally remove the retained group’s pairs. I’m tightening suppression to affect only fragments not shared with the retained group.
- Assistant
The overlap matcher is now an efficient augmenting-path bipartite match rather than exponential backtracking, and the targeted analyzer, app, and integration suites all pass. The only failed run was the pre-existing service assertion about a structural clone; it is unrelated to group deduplication and did not occur in the affected analyzer tests. I’ll do the final diff check and submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.