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
clone_groupscount (10 here) and the duplication score over-count by one redundant group.Actual behavior
Two distinct groups (
id: 6andid: 14) are emitted for the same duplication, differing only by whether thewith self.subTest(...)header line is included in each member window.Priority rationale
P2 (visible but bounded inaccuracy): the cited line ranges are themselves valid, and the duplication is real — but the same finding is double-counted, inflating the group count and duplication percentage by a bounded amount.
Found via the FP-audit skill in repo
Instagram/Fixit@bf8e1f55f8a606eae0f0c64bab575e84a2a608b3.Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /pyscn, current file: none) bash-$
Assistant
Now let me write the cross-group dedup implementation.
Assistant
All checks complete. Let me go through the checklist:
1. Reproduced the reported error Yes. I downloaded
Instagram/Fixit@bf8e1f5and ranpyscn analyze --json --no-open. With the current default thresholds the exact smoke.py pair no longer surfaces, but the same defect class reproduced exactly (--clone-threshold 0.9): two groups[config.py 682-697, 700-726, 728-748, 750-778]and[config.py 684-697, 701-726, 729-748, 751-778]— the same duplication reported twice with each member window shifted by 1–2 lines (clone_groups: 4, duplication 8.34%). I also reproduced the literal issue shape (299-315/318-334 vs 298-315/317-334 in smoke.py) through the grouping + dedup pipeline in a temporary Go test.2. Confirmed the fix resolves it Yes. I added a cross-group dedup pass (
dedupeOverlappingGroups) inside the existingdedupeStrictSubsetGroupMembersentry point: a group is dropped when each of its members can be injectively matched (bipartite matching) to a distinct member of another group describing the same code window (same file, line-range IoU ≥ 0.8). The most informative group (widest total span, then size/similarity/stable location order) survives; the redundant group's fragments are added to the suppressed set so its clone pairs are filtered too. After the fix: Fixitclone_groups4 → 3, duplication 8.34% → 6.25%, and the temporary unit test on the exact smoke.py shape yields exactly one group (298-315/317-334) and one pair.3. Edge cases Handled: nil groups/fragments/locations; groups with <2 located members; different files never matched; identical ranges (mutual coverage resolved by a deterministic preference order); chains of ≥3 near-identical groups (best-first traversal so a dropped group can't suppress others); nested-but-different-granularity clones (whole function vs. inner block) are kept — verified by temp tests and by regression runs on requests, flask, pyscn/python, and several django packages where output was byte-identical to the pre-fix binary except for the genuine duplicate in
django/core(python.py 64-111 / xml_serializer.py 149-216, a 0.98/0.92 IoU duplicate of a kept group). Determinism verified over 3 repeated runs. Complexity kept near-linear by only comparing groups that share a same-window member.4. Existing tests Ran
go test ./...(whole repo, includinginternal/analyzerandintegration) plusgo vet ./...andgofmt -l— all pass, nothing broken. My temporary test file was deleted; the only change staged isinternal/analyzer/group_dedup.go, and the straypython/.pyscnreport dir created while testing was removed.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →