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 I can fix the duplicate overlapping groups.
- Assistant
Let me look at the clone detection code more specifically.
- Assistant
There's a
group_dedup.gothat looks directly related — I'll inspect that and the clone grouping flow. - Assistant
I'll read the rest of the dedup logic and the related tests next.
- Assistant
I'll inspect where groups are built and where existing dedup is applied.
- Assistant
rg is not available, use grep instead.
- Assistant
I'll check how fragments/windows are extracted and how groups relate to each other.
- Assistant
I'll inspect the connected grouping strategy and any related documentation next.
- Assistant
I'll check how the duplication percentage is calculated and how pairs interact with groups.
- Assistant
Let me also check how CodeDuplication percentage is computed from groups - that will tell me if we also need to filter pairs.
- Assistant
I'll inspect pair creation and the overlap checks next.
- Assistant
I'll look at the prior #416 fix and remaining tests for style and conventions.
- Assistant
I'll check the #416 fix pattern and try to reproduce the Fixit case.
- Assistant
I'll set up the Go environment and build the project.
- Assistant
Build may still be going; I'll check its status.
- Assistant
I'll reproduce with the Fixit fixture next.
- Assistant
I'll inspect the smoke.py clone groups in the report.
- Assistant
I'll build a minimal reproduction of the nested-window groups.
- Assistant
I'll use the real smoke.py excerpt to try reproducing the two nested groups.
- Assistant
I'll check the fragment extraction defaults and why the inner windows aren't pairing.
- Assistant
I'll switch back to the repo root and continue from there.
- Assistant
I'll dump every smoke.py clone pair from the Fixit analysis.
- Assistant
I'll check which node types become fragments and review any related open issues or TODOs.
- Assistant
I'lltreview how dead-code merges overlapping findings for a consistent style.
- Assistant
Let me find pairKey, gf, fragmentLess, etc.
- Assistant
I'll look at registery helpers and the consistency follow-up for #416.
- Assistant
I'll implement group-level dedupe for nested/overlapping clone groups and wire it into the grouping funnel.
- Assistant
I'll append the overlapping-group dedupe helpers and wire them into the grouping funnel.
- Assistant
I'll fix the
Endlinetypo inlocationCovers. - Assistant
Need to open the file at that line first or use a different approach.
- Assistant
I'll correct that typo now.
- Assistant
I'll wire the new dedupe into
groupClonesWithStrategy. - Assistant
Need to goto the line first.
- Assistant
Now I can replace.
- Assistant
I'll verify with a temporary test for the issue case and run the existing group_dedup tests.
- Assistant
Temporary tests passed. I'll remove them and run the full analyzer package tests.
- Assistant
I'll confirm the
gfhelper setsLineCountcorrectly. - Assistant
I'll make
groupSpanfall back to location ranges whenLineCountis unset. - Assistant
Need to open the file first.
- Assistant
Now replace.
- Assistant
I'll check how unique clones are counted so suppressed groups don't leak into totals.
- Assistant
I'll also drop nested/dominated clone pairs before grouping so pairs and groups stay consistent.
- Assistant
I'll add pair-level nested-pair dedupe and hook it into the grouping path.
- Assistant
I'll append the nested-pair dedupe helpers at the end of the file.
- Assistant
There's a duplicate
return span— I'll clean that up. - Assistant
Remove the duplicate return.
- Assistant
Now wire pair dedupe into groupClonesWithStrategy.
- Assistant
I'll wire pair-level redes into the grouping funnel.
- Assistant
I'll fix the garbled comment wording.
- Assistant
I'll rerun the analyzer tests and a temporary verification for the issue case.
- Assistant
All good — I'll remove the temp tests and run the broader clone-related suite.
- Assistant
I'll inspect the failing service test to see if pair-level dedupe is being too aggressive.
- Assistant
I'll debug why that structural-match case ends with zero pairs.
- Assistant
I'll re-run that specific failing test for more detail.
- Assistant
I'll replicate the test's request settings exactly to see which pairs get dropped.
- Assistant
I'll instrument the analyzer to dump pairs before and after each dedupe step.
- Assistant
I'll dump pre/post-dedupe pairs with a temporary instrumented change.
- Assistant
I need to add the
osimport for the debug prints. - Assistant
Pair-level nested dedupe is too aggressive — it can keep a maximal pair that later falls below MinSimilarity. I'll keep only the group-level deadupe.
- Assistant
The first replace failed. Let me goto the function and fix it.
- Assistant
Let me replace the whole function body properly.
- Assistant
I'll remove the unused pair-level dedupe code and retest.
- Assistant
Wrong file. Let me open groupge_dedup.go and remove pair-level code.
- Assistant
I'll delete from line 405 to end.
- Assistant
I'll re-run the analyzer and service tests.
- Assistant
I'll do a final issue-case check and run the full service suite.
- Assistant
I'll rewrite the temporary test cleanly.
- Assistant
I'll write the temporary test with Python to avoid corruption.
- Assistant
I'll verify the final diff is clean.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.