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 detection/grouping works, so I can fix the duplicate overlapping clone groups bug.
- Assistant
Next I'll search the clone-detection code for grouping and dedup logic, especially anything related to overlapping windows.
- Assistant
rg is not available, let me use grep instead.
- Assistant
There's already a
group_dedup.go— I'll inspect it and the related tests next. - Assistant
So the existing group_dedup only handles subset members within a single group. The issue is about two whole groups that are near-duplicates of each other. Let me read the rest of the file and the test...
- Assistant
Next I’ll inspect how clone groups are formed and check recent commits touching cross-group dedup.
- Assistant
I'll inspect how fragments and groups are created so we know why near-duplicate overlapping pairs become two groups.
- Assistant
I'll look for design notes/TODOs and check how compound statement fragments create these nested windows.
- Assistant
Checking algorithm docs and whether nested/overlapping same-file fragments are filtered before pairing.
- Assistant
I'll try reproducing with a minimal nested-with sample and inspect how groups currently form.
- Assistant
Need to set GOPATH or GOMODCACHE.
- Assistant
Build seems to have completed or is still going - let me check.
- Assistant
My simple sample only produced one group — I'll reuse the real Fixit
smoke.pycase the issue cites. - Assistant
The issue said 10 groups with v1.22.9; we got 9 on current code. Checking the
smoke.pyclone groups next. - Assistant
Next I'll check how duplication percentage is calculated - group vs pair counting - so the fix targets the right place.
- Assistant
Duplication is driven by group density, so I'll inspect whether the same pair-level overlap also shows up in the pairs list.
- Assistant
I'll check group ID assignment and helper functions next, then implement the cross-group overlap dedupe.
- Assistant
Checking test helpers and whether location containment utilities already exist.
- Assistant
Implementing cross-group overlap dedupe and applying the same idea at the pair level so nested windows collapse before/with grouping.
- Assistant
I'll add the new functions to group_dedup.go and wire them into clone_detector.go.
- Assistant
I'll fix the comment typo and wire the new dedupe into
groupClonesWithStrategy. - Assistant
Let me fix the comment and wire the function.
- Assistant
The replace found the wrong file - it searched clone_detector. Let me open group_dedup.go and fix the typo there.
- Assistant
Let me fix the comment and wire the detector.
- Assistant
There's a loop bug: after suppressing
iwe should stop comparing it further. Fixing that and adding tests. - Assistant
The edits corrupted the file — I'll rewrite
group_dedup.gocleanly from scratch. - Assistant
Next I'll add tests for the new cross-group/pair overlap dedupe and verify the build.
- Assistant
All related tests passed. Rebuilding and verifying against the Fixit repro next.
- Assistant
The xargs wiring broke the Python script — I'll inspect the JSON report directly.
- Assistant
Fix confirmed on Fixit: the nested-window duplicate is gone and only the outer maximal group remains. Running broader analyzer tests next.
- Assistant
Analyzer tests are green; next I'll run the clone-related service and integration tests.
- Assistant
I'll check whether that failing clone service test is caused by my change or was already broken.
- Assistant
My change seems to affect that test — I'll dig into which pairs form and what the dedupe drops.
- Assistant
I'll probe this case with a small analyzer-level unit script next.
- Assistant
Checking the ParseResult structure.
- Assistant
Let me look at how clone_service extracts fragments.
- Assistant
Let me write a proper test.in the service package or use a small main that calls the service. Actually the issue might be that when LSH is used or when MaxClonePairs is set, nested pairs might affect ...
- Assistant
pairs=0 with my changes. Without they were non-empty. So my dedupe is wiping them. How?
Maybe there areself-overlapping pairs somehow being Myreated incorrectly?
Or need max edit and maybe multiple pairs where one covers and gets-drop due to prefer?
Letme: print pairs before...
- Assistant
Need to add "os" to imports.
- Assistant
Add os import
- Assistant
Pair dedupe keeps the outerfunction pair, but something later drops it — tracing further down the pipeline.
- Assistant
I'll clean up the botched edit and check clone-service filtering next.
- Assistant
Looking at filter by MinSimilarity and MaxSimilarity... let me check newDefaultCloneRequest for those defaults.
- Assistant
Pair-level maximal-window dedupe is too aggressive — it drops the high-similarity residue couple that still matters. I'll keep only cross-group dedupe and clean up the detector.
- Assistant
I'll simplify to group-only dedupe and restore a clean
groupClonesWithStrategy. - Assistant
There's a duplicate comment — I'll fix that and update the preference logic and tests.
- Assistant
Rewriting both files cleanly to final form.
- Assistant
I left garbage in the file from an incomplete ending. Rewriting the full file carefully.
- Assistant
Let me fix the isSameLocation comment with the exact string.
- Assistant
Updating tests to match the higher-similarity preference and remove pair-level cases.
- Assistant
All dedupe tests pass. Verifying Fixit and service tests next.
- Assistant
Confirming the Fixit case is fixed and tests pass. Reviewing the final diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.