Untitled conversation
- User
[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.9bashcurl -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:json{ "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: - Assistant
Investigating the clone detector's grouping/dedup logic and reproducing the duplicate overlapping clone groups issue.
- Assistant
Reproducing the bug and inspecting how fragments are extracted for nested
withblocks. - Assistant
Implementing cross-group deduplication for overlapping window boundaries, extending the existing within-group subset dedup.
- Assistant
Now adding tests for the Fixit reproducer case and related edge cases.
- Assistant
Removing the unused
pairsparameter fromdedupeNearDuplicateGroups. - Assistant
Fixed duplicate overlapping clone groups by adding a cross-group dedup pass after the existing within-group subset pruning (#416).
Root cause
Nested
withblocks produce separate clone pairs at different AST levels:- Inner:
with TemporaryDirectory()→ lines 299–315 / 318–334 - Outer:
with self.subTest(...)→ lines 298–315 / 317–334
isOverlappingLocationcorrectly blocks same-file overlapping pairs, so union-find forms two separate 2-member groups instead of one. The existingdedupeStrictSubsetGroupMembersonly collapses overlapping members within a group, not across groups.Fix
Added
dedupeNearDuplicateGroupsingroup_dedup.go, chained viadedupeCloneGroups:- Detect near-duplicates — same group size; members align by file; each aligned pair has nested/overlapping ranges (one window contains the other).
- Inner:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.