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 works so I can fix the duplicate overlapping clone groups bug.
- Assistant
Let me look at the clone detection related code.
- Assistant
There's already a
group_dedup_test.go— that looks highly relevant. Let me inspect the grouping/dedup code. - Assistant
There's a
group_dedup.gofile. Let me read it along with the test file. - Assistant
This is about #416 which was closed - the within-group subset dedup. The issue is about across-groups dedup. Let me read the rest of the file and search for related functionality.
- Assistant
I need to understand how fragments and groups are formed, and review any related issues or PRs around overlap handling.
- Assistant
Let me look at git history related to group_dedup and overlapping clones, and also understand how groups get created with different window boundaries.
- Assistant
Let me look at the issue more carefully. We have two groups:
- Assistant
Now I understand the architecture. Fragments are AST nodes (with blocks, functions, etc.), not sliding windows. So we get the outer
withstatement as one fragment and the inner body statement as ano... - Assistant
Let me try to reproduce the issue. First, I need to see if pyscn binary is available and if I can run the analyze.
- Assistant
Let me reproduce with a minimal test case based on the smoke.py pattern. First, build pyscn and create a minimal reproducer.
- Assistant
Need to set GOPATH/GOMODCACHE.
- Assistant
It seems like go build finished without outputting anything else or the binary. Let me check.
- Assistant
Binary is built. Let me create a minimal reproducer based on the issue description.
- Assistant
Let me run clone detection on the fixit smoke.py and my simplified version.
- Assistant
Got 4 groups. Let me look at the clone groups in the JSON.
- Assistant
Let me also check pairs - are there pairs for both inner and outer?
- Assistant
I need to understand how duplication percentage is calculated from groups.
- Assistant
Let me look at how code duplication percentage is calculated.
- Assistant
So CodeDuplication is based on group count. Reducing redundant groups fixes the inflated percentageération.
- Assistant
Let me look at
gfhelper and the e2e test related to detector grouping, and also see docs about clone algorithms. - Assistant
Let me find the gf helper definition.
- Assistant
Looking at createStatistics and TotalClones...
- Assistant
Also need to re-sort and re-id groups? Looking at sortCloneGroups and whether IDs are renumbered...
- Assistant
I have a clear plan. I'll implement cross-group deduplication for overlapping/nested clone groups and wire it into the existing grouping funnel.
- Assistant
Implementing the cross-group overlap dedupe in
group_dedup.goand wiring it into the grouping funnel. - Assistant
The edit hit the wrong file and got corrupted. Restoring it, then rewriting
group_dedup.gocarefully. - Assistant
group_dedup is intact. Opening it and applying a clean edit.
- Assistant
Writing the full fixed file with a shell heredoc to avoid corruption.
- Assistant
Existing tests pass. Verifying with a temporary Go test for the Fixit repro shape, then rebuilding against the smoke file.
- Assistant
Rewriting the temp test file cleanly — the previous version had typos.
- Assistant
All unit tests passed. Running the full analyzer package tests and verifying against the Fixit smoke repro.
- Assistant
Still 4 groups — earlier the inner fragments were in a larger multi-member group, so cross-group pair-dedupe may not apply. Checking the groups.
- Assistant
Checking the full Fixit repo case from the issue — the single-file case has a different group shape.
- Assistant
8 groups. Checking whether the smoke.py overlapping groups are deduped.
- Assistant
Unicode typos again. Let me write a clean script.
- Assistant
Writing the analysis script to a file instead.
- Assistant
I keep introducing typos. Let me be more careful and use a simple approach.
- Assistant
The fix worked for full Fixit — only the outer group remains. Verifying the before/after and running broader tests.
- Assistant
Confirmed: without the fix both groups appear (9 total); with it, the redundant one is dropped (8 total). Cleaning up and verifying the restored file.
- Assistant
Running simpler verification commands without typos.
- Assistant
Still 8 groups. Let me check smoke groups are only outer.
- Assistant
Outer-only group kept as expected. Running broader related tests next.
- Assistant
All related tests pass. Preparing to submit the fix.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.