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
I’ll trace the clone grouping and existing overlap tests, add a focused regression case, then implement the narrowest deduplication fix and run the relevant test suite.
- Assistant
rgisn’t installed in this workspace, so I’m usingfind/grepfor the repository trace. I’m first isolating where groups are finalized and where duplication percentage consumes them. - Assistant
The existing #416 post-pass only removes nested windows inside one group. The reproducer escapes it because the inner-window pair and outer-window pair form disconnected groups. I’m extending that same post-pass to suppress a whole group only when there is a one-to-one, same-file containment match for every member; partial overlaps and differently sized relationships remain distinct.
- Assistant
The focused regression is in place, including pair-output consistency and guard cases for partial matches and different group sizes. The analyzer test package is running now; its Go dependencies were not cached locally, so the toolchain began resolving the module cache automatically.
- Assistant
The targeted analyzer suite passes. The full repository suite is still progressing; all completed packages—including app, CLI, domain, integration, analyzer, config, parser, reporter, and MCP—are green so far.
- Assistant
The full suite exposed an important boundary case: nested groups can represent different clone classifications (for example, an exact outer structure and a renamed inner structure). Suppressing across those would erase a legitimate finding. I’m tightening the rule so cross-group containment only deduplicates groups of the same clone type, matching the reported Type-2/Type-2 case.
- Assistant
The tightened rule resolves the suite-discovered boundary case. The full
go test ./...run now passes, including the 53-second service package and the new reproducer. I’m doing a final diff/status check for accidental changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.