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
I’ll first map the repository and locate the clone grouping/deduplication implementation and related tests. Then I’ll reproduce the overlap behavior with the smallest available fixture or a temporary script, implement a general group-level suppression rule, and run the focused and broader test suites.
- Assistant
The project is Go-based, and clone logic appears under
internal/servicerather than the initially searched paths. I’ll inspect clone-specific source and tests, paying particular attention to where pairwise matches become groups and where overlapping members are currently handled. - Assistant
There is already a dedicated
group_dedup.gofrom the related strict-subset fix, plus focused tests. I’ll read its invariants and detector integration before extending it; the safest solution is likely to preserve the existing within-group behavior while adding a separate across-group equivalence pass. - Assistant
The existing pass only compares members within each group, so the reported shape survives because each group independently has two non-overlapping fragments. A conservative across-group rule is appropriate: two groups are redundant only when they have the same cardinality and their members admit a one-to-one, same-file containment match, with one group consistently containing the other. This catches the one-line-expanded windows while avoiding suppression merely because one arbitrary member overlaps. I’ll inspect scoring and all grouping call sites to determine whether dropping the dominated group also requires pair cleanup or ID normalization.
- Assistant
Dropping only the group would fix the count but leave its narrower fragments in
clonePairs; statistics count unique locations from both pairs and groups, so duplication would remain inflated. I’ll therefore extend the dedupe result’s existing suppression mechanism: when a whole contained group is removed, mark its distinct fragment objects as suppressed too, while never suppressing objects also present in a retained equivalent group. The match will require a perfect one-to-one containment correspondence and at least two valid members. - Assistant
The implementation now performs group-level perfect matching after the existing within-group pruning and feeds dominated fragments into the established pair filter. I’ll run the analyzer tests first; these include randomized grouping invariants and the prior overlap regression, which should expose overly broad suppression or nondeterminism.
- Assistant
The test command is blocked by environment configuration rather than code (
GOMODCACHE/GOPATHis unset). I’ll provide a writable temporary Go cache explicitly and rerun without modifying repository configuration. - Assistant
A second unset environment variable (
GOCACHE, with noHOME) prevented compilation. I’ll set both cache locations under/tmpand rerun. - Assistant
Focused tests pass. To satisfy the reported reproduction rather than relying only on synthetic reasoning, I’ll build the CLI and obtain the specified Fixit revision in
/tmp, then run clone analysis and inspect the two smoke.py windows in generated JSON. This keeps all reproduction artifacts outside the repository. - Assistant
The specified revision downloaded and the CLI built successfully; this version exposes clone detection through
analyzerather than a standaloneclonecommand. I’ll inspect the current analyze flags and run the closest equivalent JSON command. - Assistant
To confirm both sides of the regression, I’ll build an unmodified
HEADbinary from a temporary git worktree, run baseline and fixed binaries against the same checkout with clone-only analysis, and compare group ranges involving smoke.py lines 298–334. - Assistant
The real repository reproduces the defect: baseline emits 8 groups and the fixed binary emits 7. I’ll now inspect exact ranges and pair/statistics counts to verify the removed group is specifically the 299/318 nested-window duplicate, while the wider 298/317 group remains.
- Assistant
The current branch’s grouping defaults differ from v1.22.9, so the wider windows belong to a larger seven-member group rather than the two-member group shown in the report. Nevertheless, the count/pair reduction indicates a two-member contained group was removed. I’ll print all baseline/fixed group members to confirm the exact dominated ranges and ensure no unrelated group disappeared.
- Assistant
This comparison exposed an important overreach: the removed group was an
api.pygroup, not the historical smoke.py pair (which the current baseline no longer emits). The same file likely has broader containing fragments, but simple containment can conflate nested clone relationships of very different sizes. The issue specifically concerns near-identical windows, so I’ll quantify line-boundary differences among baseline groups and tighten the rule to require high reciprocal overlap / small boundary shifts rather than arbitrary containment. - Assistant
The diagnostic script referenced clone fields at the wrong nesting level (
locationcontains the range). I’ll correct it and identify the exact containment pair before choosing a threshold. - Assistant
No containment exists among the baseline’s emitted groups, confirming that grouping itself is nondeterministic due to map iteration; the two runs did not start from identical group sets. I’ll tighten “near-duplicate” to require each contained window to retain at least 80% of the containing window’s lines (the report is 17/18 ≈94%), then validate deterministically with a temporary in-package executable helper rather than infer correctness from cross-run group counts.
- Assistant
The 80% guard makes containment explicitly “near-identical” rather than any nested range. To exercise unexported dedupe functions without adding tests to the submitted repository, I’ll copy the working tree to
/tmp, add a temporary focused Go test there, and verify: the reported 17/18 windows collapse to the wider group, the narrow pair is filtered, partial correspondence does not collapse, and substantially nested groups remain distinct. - Assistant
The temporary deterministic regression passes all intended cases. I’ll now return to the actual repository, run its complete Go test suite and static formatting checks, then inspect the final diff and repository status for accidental artifacts.
- Assistant
All repository tests pass and only the intended source file is modified. For the checklist’s strict reproduction requirement, the current branch’s grouping behavior no longer produces the exact v1.22.9 layout, so I’ll check whether the cited release tag is available locally/remotely; if so, I’ll build that tag and confirm the original two ranges directly. I’ll also run
go veton the modified package. - Assistant
The cited release tag is not available from this checkout’s origin, so exact historical binary reproduction is unavailable. However, the temporary test recreates the exact reported ranges and similarities’ pair shape, and verifies the fixed output deterministically; the downloaded Fixit revision also confirms current end-to-end analysis remains healthy.
go vetpasses. I’ll do a final code review for nil handling, matching direction, pair suppression, and diff cleanliness before submission. - Assistant
Final review confirms:
- [x] Reproduced the reported error: I downloaded the cited Fixit revision and ran clone-only analysis; because current grouping differs from v1.22.9, I additionally recreated the exact
298–315/317–334versus299–315/318–334group shape in a temporary out-of-tree test. The pre-fix algorithm retains both groups. - [x] Confirmed the fix resolves it: The temporary regression verifies only the wider group remains and the narrower group’s clone pair is also removed, preventing both group-count and unique-fragment/statistics inflation.
- [x] Considered edge cases: Suppression requires equal group cardinality, a perfect one-to-one same-file match, consistent containment, and at least 80% line coverage. Tests verified partial group overlap and substantially nested relationships remain distinct; nil/invalid fragments fail matching safely; shared fragment objects retained elsewhere are not removed from pairs.
- [x] Reproduced the reported error: I downloaded the cited Fixit revision and ran clone-only analysis; because current grouping differs from v1.22.9, I additionally recreated the exact
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.