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.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
Good, it is used. Now let's look at group_dedup_test.go for style, and think about adding a new dedup pass for cross-group overlap.
Assistant
Now let's implement the cross-group dedup function in group_dedup.go.
Assistant
Now let's hook this into
groupClonesWithStrategyafter the existing dedupe pass, and re-sort.Assistant
Now let's build.
Assistant
Build succeeds. Now let's run the analyzer tests related to clones.
Assistant
All existing tests pass. Now let's write a reproduction test to validate the new dedup logic works for the exact scenario from the issue.
Assistant
The fix works as intended. Now let's remove the temporary test file and run the full analyzer test suite plus other affected packages.
Assistant
Now let's run the full test suite for analyzer, service, app, domain to double check nothing else broke.
Assistant
All tests pass across the entire repo. Now let's actually try to reproduce the real-world scenario with the Fixit repo to fully validate end-to-end, since we have network access disallowed for solutions but the repo clone might be feasible via curl (issue explicitly gives reproducer steps). Let's check if network is available.
Assistant
We have network access. Let's build pyscn binary and run it on this repo to verify end-to-end fix.
Assistant
gofmt ordering isn't critical for this throwaway build. Let's build.
Assistant
"os" already imported. Let's fix osStderr to os.Stderr.
Assistant
Good, main repo unaffected (was already detached HEAD originally). Now let's restore the debug prints removal and fix the actual logic in group_dedup.go.
Assistant
Good, that restored my clean (non-debug) version. Now let's view current
pickNonRedundantGroupand rewrite the winner-selection logic to prefer higher similarity instead of superset range.Assistant
Now let's update the doc comment for
dedupeOverlappingGroupsto reflect the new tie-break policy, and rebuild/test.Assistant
Now build and run the test suite again.
Assistant
All good. Now let's rebuild the "after" binary with the fix and rerun full end-to-end validation against Fixit.
Assistant
Now confirming the fix picks the higher-similarity group. Let's clean up the temp test and worktrees, and run full test suite once more.
Assistant
Good. Now let's double check the final diff, then run full test suite.
Assistant
Now let's run the full test suite across the whole repo once more to make sure everything passes.
Assistant
All tests pass. Let's do a final check with
git statusto confirm only intended files changed, and clean up temp files/binaries.Assistant
Clean. Let's review the final diff one more time for correctness/style consistency.
Assistant
No formatting issues. Now let's go through the checklist.
Assistant
Assistant
The fix is complete, verified, and only touches the relevant analyzer files. Submitting now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.