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.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
Let me look at how fragments are extracted, to understand how such shifted-window groups arise:
- Assistant
Now add the
locationCovershelper and refactorcoversto use it: - Assistant
Existing tests pass. Now add tests covering the new cross-group behavior:
- Assistant
All pass. Now run the full analyzer package plus related packages to check for regressions:
- Assistant
Now verify against the actual reproducer — build pyscn and run it on Instagram/Fixit:
- Assistant
Pre-fix: 8 groups; post-fix: 7. Let me see which group was suppressed:
- Assistant
No surviving group covers those api.py ranges — suspicious. Let me check whether this is run-to-run nondeterminism rather than my fix:
- Assistant
Let me add temporary debug logging to see which group suppresses the api.py group:
- Assistant
MinSimilarity defaults to 0.0, so something else drops the coverer group. Let me debug what happens to it downstream:
- Assistant
The coverer group (sim 0.8137, Type-3) survives dedupe but is dropped downstream in both pre- and post-fix runs. Something in the service layer drops it. Let me find it:
- Assistant
Analyzer files are back to their original state. Now let me check the domain types and the sort order in service:
- Assistant
Now let me check how the duplication percentage is computed, so the fix covers the over-counting claim:
- Assistant
Now wire it into
buildCloneResponseafter the filters: - Assistant
Now write tests for the service-level dedup:
- Assistant
All green. Run the remaining packages too:
- Assistant
Everything passes. Let me review the final diff:
- Assistant
The fix is complete. Summary of what was done:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.