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 inspect the repository structure and clone-detection/grouping code, then identify the existing deduplication behavior and tests. I’ll reproduce the overlap case if feasible, implement the narrowest general merge/suppression rule, run relevant tests, and review the diff before submitting.
- Assistant
The repository already has a post-group pass that removes contained members within each group, but it does not compare separate groups. I’ll extend that post-pass with a conservative group-level overlap deduplication: only same-sized groups whose members can be bijectively matched in the same files with substantial line overlap are considered duplicates. The wider window is retained (falling back to higher similarity), while the discarded group’s fragment pointers are suppressed from pair output as the existing pass does. This avoids collapsing merely adjacent or weakly overlapping clone findings.
- Assistant
The first test run compiled the analyzer and exposed an unintended compatibility effect: filtering clone pairs belonging to a discarded overlapping group removes valid pair results expected by existing service behavior. The issue is specifically redundant groups and score inflation, so I’m adjusting the implementation to suppress only the redundant group, not otherwise valid clone pairs. The existing within-group member suppression remains unchanged.
- Assistant
The revised implementation now passes the analyzer, service, app, and integration test packages. I’ll do a final diff and static-format check, verify the new pass is invoked in the actual detection path, and ensure no temporary artifacts or test modifications were introduced.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.