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
Let me start by exploring the repository structure to understand the codebase.
Assistant
This is a Go project (with Python wrapper). Let me explore the clone detection logic.
Assistant
The existing
dedupeStrictSubsetGroupMembershandles within a single group. Now I need to understand the issue: two separate groups describe the same duplication, with members shifted by one line. So this is a cross-group dedup problem.Let me look at the clone_detector.go to understand the flow.
Assistant
Now I understand the structure. The
dedupeStrictSubsetGroupMembersonly works within a single group. The issue is about two separate groups that are near-duplicates across groups.Let me understand the grouping. The LSH path or union-find grouping creates groups. The issue is that there can be two separate groups that cover the same underlying fragments but with windows shifted by one line.
Let me look at how groups are built — the grouping strategy.
Assistant
Now I understand the issue. Let me look at the existing test file for group_dedup to understand the test conventions.
Assistant
Now let me look at the helper functions
gf,gp,pairKey,fragmentLess,CodeLocation,CodeFragment,averageGroupSimilarity.Assistant
Let me check how duplication percentage is computed and how groups/pairs are used in reporting.
Assistant
Let me look at how duplication percentage is computed in the reporting layer.
Assistant
Now let me look at how the duplication percentage is computed in the summary (where CloneGroups count feeds in). Let me look at analyze.go calculateSummary or wherever CodeDuplication is computed.
Assistant
Let me check for existing overlap/contains helper functions to avoid duplication.
Assistant
Let me write a reproduction test first to confirm the issue at the unit level.
Assistant
GOPATH is /root/go (default since HOME is /root... wait HOME is empty). Let me set GOMODCACHE and GOPATH explicitly.
Assistant
I've reproduced the bug. Now let me implement the cross-group dedup. First let me look at the exact wiring point in clone_detector.go.
Assistant
Now let me implement the cross-group dedup. Let me open group_dedup.go and add the new functions.
Assistant
Now wire it into
groupClonesWithStrategy:Assistant
I need to navigate to the file first. Let me use the edit command with the proper approach.
Assistant
Let me check whether there are other grouping paths that bypass
groupClonesWithStrategy.Assistant
Both grouping paths use
groupClonesWithStrategy— single chokepoint. Now let me build and run the repro test plus existing dedup tests.Assistant
My repro test only calls
dedupeStrictSubsetGroupMembersdirectly. The cross-group dedup is applied at thegroupClonesWithStrategylevel. Let me update the repro to exercise the full chain.Assistant
The fix works — the maximal group {A, C} survives and the subset group {B, D} is suppressed. Now let me test edge cases thoroughly with a temporary test.
Assistant
All edge cases pass. Now let me run the full analyzer test suite to ensure nothing breaks.
Assistant
Now let me run the broader test suite, especially clone-related tests across packages.
Assistant
All tests pass. Let me also check e2e/integration tests which might use real fixtures and assert on group counts.
Assistant
Let me verify end-to-end with the actual repro. First let me check how to build the pyscn binary.
Assistant
The unit test precisely reproduces the issue's scenario. Let me also verify end-to-end with a synthetic Python file mimicking the smoke.py pattern.
Assistant
The JSON goes to stdout. Let me capture it and inspect clone groups.
Assistant
The output went to stderr or a file. The exit was 0 but out.json is empty. The JSON might be written to a file in the target dir or current dir. Let me check the analyze command behavior - maybe
--jsonwrites a report fileanalyze.jsonsomewhere.Assistant
The fix produces only 1 clone group. Let me confirm the "before" behavior (without the fix) produced 2 groups, by temporarily reverting.
Assistant
The "before" binary also produced 1 group here — my synthetic file's fragmenter didn't create the overlapping inner-window fragments. Let me understand how fragments are extracted to build a faithful end-to-end repro.
Assistant
Both
withstatements are fragment candidates. Let me checkshouldIncludeFragmentand MinNodes config to understand why the inner window wasn't detected in my synthetic file.Assistant
The cross-pairs (outer-of-A with inner-of-B) connect everything into one component in my synthetic file, so within-group dedup already collapses it. The real Fixit scenario has cross-pairs below the grouping threshold. Let me check the grouping threshold default.
Assistant
The unit test faithfully reproduces the exact dedup-stage scenario from the issue (same line numbers and fragment relationships). The end-to-end synthetic file merged into one component because cross-pairs exceeded threshold. Let me try to craft a file where cross-pairs fall below threshold to demonstrate the before/after end-to-end. Let me iterate with the old binary.
Assistant
I've reproduced the exact bug end-to-end with the OLD binary: TWO groups for the same duplication, group 1's members each starting one line earlier (the
with self.subTest(...)header line). Now let me run the NEW binary.Assistant
The fix works end-to-end: 2 groups → 1 group, keeping the maximal (covering) group. Let me verify the duplication percentage/score improved accordingly.
Assistant
CloneGroups count went 2→1 (the primary metric). The percentage is capped at 10 for this tiny file, but in the large real Fixit repo it won't be capped, so the redundant group's contribution is removed. Let me also check clone_pairs behavior before/after.
Assistant
CloneGroups count is fixed (2→1); the duplication percentage derives from group count and is now correct. The clone_pairs list retains genuine pairs (the issue is specifically about group count/duplication percentage).
Now let me run the full test suite once more, then clean up temporary test files.
Assistant
Now let me remove the temporary test files (I must not add new tests to the repository) and re-run to confirm submission state.
Assistant
All tests pass. Let me review the final diff.
Assistant
The diff is clean. Let me quickly check whether the repo expects a CHANGELOG entry for fixes.
Assistant
The fix is complete and clean. Let me do a final full test run (forcing a clean run, no cache) to be certain nothing is broken.
Assistant
All tests pass. Let me confirm the working tree is clean except for the two intended source changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.