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.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 let's implement the cross-group dedup logic. Let's view the end of clone_detector.go for isOverlappingLocation context to refactor.
Assistant
Now let's update
groupClonesWithStrategyto call the new cross-group dedup pass, and add the new logic in group_dedup.go.Assistant
Now let's add the new dedup logic to group_dedup.go.
Assistant
Now let's build the project to check for errors.
Assistant
Build succeeds. Now let's run the group_dedup tests and full analyzer tests.
Assistant
All existing tests pass. Now let's write a quick reproduction test to validate the fix logic directly.
Assistant
The fix works as expected. Now let's remove the temp test file, and double-check
gfhelper exists (used in group_dedup_test.go) for consistency.Assistant
All tests pass across the whole repository. Now let's try to actually reproduce the original issue against Fixit repo to validate the fix works end-to-end with the real CLI.
Assistant
Good, this confirms backup is clean (pre-debug). Let's restore it and apply the improved quality tie-break.
Assistant
Now let's rebuild and re-run the full test suite plus the real-world reproduction to confirm.
Assistant
All pass. Let's rebuild the CLI binary and run against Fixit multiple times to check consistent, correct dedup behavior now.
Assistant
The dedup fires consistently across runs and each time correctly picks the higher-similarity (0.8866) group. Let's confirm final output consistently keeps the 0.8866 group (Type4) and never the 0.8137 one.
Assistant
Consistently keeps the higher-similarity Type4 group and correctly drops the redundant near-miss duplicate. Now let's clean up temporary artifacts and view the final diff.
Assistant
Let's view the final diff in full for review.
Assistant
The diff looks clean and matches only the intended fix. Let's clean up temp files/binaries and run the full test suite one more time as a final sanity check.
Assistant
All tests pass, working tree only has the intended changes. Now let's go through the checklist explicitly.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.