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 so we can fix the duplicate overlapping clone groups issue.
- Assistant
Let me search for clone-related code, especially around grouping and deduplication, and also look at issue #416 which was mentioned.
- Assistant
rg is not available, let me use grep instead.
- Assistant
There's already group_dedup for within-group overlap; I'll inspect that and the clone detector next.
- Assistant
Let me continue reading the file and also the clone detector where groups are formed.
- Assistant
I’ll inspect how grouping works and what prior issues/history say about overlapping groups.
- Assistant
I'll inspect clone fragment extraction and how overlapping same-file pairs are handled.
- Assistant
I'll check how the duplication score uses clone groups and pairs.
- Assistant
I'll inspect statistics creation and the git history around group dedup.
- Assistant
Let me look at how duplication percentage is calculated in analyze path, and also see the commit for #416 for design inspiration.
- Assistant
Let me look at how group density is computed:
- Assistant
I'll check other call sites and whether group IDs need renumbering.
- Assistant
I'll check test helpers and
almostEqual/ fragment ordering utilities. - Assistant
Checking the default grouping mode and whether complete linkage yields two groups.
- Assistant
I'll check the default group mode in config and domain.
- Assistant
Implementing overlapping clone-group dedupe and wiring it into the grouping funnel.
- Assistant
I'll add the new dedupe function and wire it into the grouping path.
- Assistant
Wiring the new dedupe into the grouping funnel.
- Assistant
I'll write a temporary test to verify the fix, then run the existing group_dedup tests.
- Assistant
Need to set GOPATH or GOMODCACHE
- Assistant
Temporary tests passed. Running broader related tests and cleaning up.
- Assistant
All analyzer tests pass. Verifying the final diff and compiling the package.
- Assistant
Verifying the temp test was removed and reviewing the final implementation before submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.