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
Now wire it into
groupClonesWithStrategy: - Assistant
Now add tests covering the reported shape and edge cases:
- Assistant
All new and existing tests pass. Now run the full analyzer package plus related packages:
- Assistant
The test passes without my change, so I introduced a regression. Let me examine the failing test:
- Assistant
Simpler — temporary prints in
groupClonesWithStrategy: - Assistant
The subsumption keeps only the lower-similarity whole-function pair (0.6533), and something downstream filters it. Let me check the thresholds:
- Assistant
One Type-4 pair remains but the service drops it. Let me find the service-side filter:
- Assistant
Now update the tests to reflect the similarity-aware policy:
- Assistant
Now remove the temporary debug code:
- Assistant
All packages pass. Now verify against the actual reproducer from the issue:
- Assistant
The current output differs from the v1.22.9 report in the issue. Let me confirm the bug still reproduces on unpatched HEAD, to validate the comparison:
- Assistant
Default grouping is
connected. Let me test other grouping modes on Fixit to see if the duplicate-group shape appears at HEAD, comparing patched vs unpatched: - Assistant
Centroid-mode removal is also correct — same shape, lower-similarity subset windows. Final checks — gofmt and the full test suite:
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.