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 its tests. Then I’ll reproduce the overlapping-group behavior with the smallest practical fixture, implement a general cross-group overlap suppression rule, and run the focused and broader test suites.
- Assistant
The project is primarily Go, and clone behavior is covered in service and integration tests. I’ll now inspect the clone domain model, detector pipeline, and existing overlap-related tests to understand where cross-group normalization belongs and avoid changing presentation-only code.
- Assistant
There is already a dedicated
group_dedup.gostage, but it only removes strict-subset members inside each group (the prior #416 fix). The current bug needs a second, cross-group comparison after that operation. I’ll inspect the exact group/member structures and grouping semantics before defining equivalence conservatively. - Assistant
The reproducer’s groups each have two members, with a one-to-one containment mapping: both members of one group are strict subsets of corresponding members in the other. A safe rule is therefore “suppress an entire group only when every member can be bijectively matched by same-file range containment in the same direction,” rather than merely using overlap (which could collapse legitimate neighboring clone relationships). I’ll verify default strategy and lifecycle ordering, then reproduce this shape through the grouping post-pass.
- Assistant
The default connected strategy can indeed produce two disconnected pair-components:
(outer lint, outer fix)and(inner lint, inner fix). I’ll run the existing analyzer tests for a baseline and attempt the published Fixit reproduction against the current source CLI, preserving the generated repository only outside tracked files. This will also reveal whether pair output should be normalized alongside groups. - Assistant
The baseline command was blocked before execution because this environment has neither
GOPATHnorGOMODCACHEconfigured; no tests or reproduction ran. I’ll configure an external cache under/tmp(without touching repository configuration), then rerun both steps. - Assistant
Go additionally requires a build cache because
HOMEis unset. I’ll setGOCACHEexplicitly and repeat; downloaded modules are already in/tmp. - Assistant
All relevant baseline tests pass. The root is not a Go
mainpackage, so the reproduction invocation needs the repository’s documented build target/package. I’ll inspect the Makefile and command tree, then invoke the correct CLI entry point. - Assistant
I found
./cmd/pyscn. I’ll run it from/tmpso generated output cannot pollute the repository, then use Python to extract only smoke.py groups and pair ranges for a precise before-state. - Assistant
go runresolves modules from the working directory, so running it from/tmpcannot seego.mod. I’ll build a temporary binary from the repository root, execute that binary from/tmp, and inspect its JSON. - Assistant
The current revision generated 8 groups (the issue’s older release generated 10), but the report is under
/tmp/.pyscn/reportsrather thananalyze.json. I’ll inspect that report directly to confirm whether the exact duplicate groups remain and capture their pair records. - Assistant
The latest code no longer emits the exact
299/318inner fragments for this checkout, so the historical end-to-end output is not reproducible byte-for-byte; however, the detector still lacks cross-group deduplication and the reported structural shape is directly reproducible at its post-group stage.I’ll implement conservative near-duplicate suppression with these safeguards:
- groups must have the same member count (at least two);
- every member must have a distinct same-file counterpart (bijective matching);
- each paired range must overlap by at least 90% of the larger window, which covers the reported 17/18-line shift but not substantially nested clones;
- retain the group with greater total line coverage, then deterministic existing order;
- remove clone pairs belonging only to suppressed windows, while preserving any fragment still used by a retained group.
This handles order, repeated files, exact duplicate groups, and nil locations without broad “any overlap” false merges.
- Assistant
The terminal’s persistent working directory changed to
/tmpduring reproduction, so the edit correctly failed without modifying anything. I’ll rerun the same edit after explicitly returning to/pyscn. - Assistant
The implementation is in place and formatted. Before broad tests, I’ll run focused analyzer tests plus static analysis. I’ll also inspect the module Go version (the code uses standard
min/max) and use the existing Fixit report as a regression check to ensure the conservative rule does not accidentally reduce unrelated current groups. - Assistant
Focused tests and
go vetpass under Go 1.25. I’ll rebuild and rerun the full Fixit analysis now. Although this revision’s parser no longer produces the historical inner windows, matching the pre-fix count of 8 confirms the 90% rule leaves its other overlapping/nested findings intact; I’ll also scan the resulting groups for any remaining cross-group near-duplicate relation using the same bijective criterion. - Assistant
The post-fix Fixit run succeeds with the same 8 groups/19 pairs as baseline and no cross-group near-duplicate relation remains; thus the new rule does not alter unrelated findings in the current parser output. For the historical shape specifically, each reported mapping has overlap 17/18 (94.4%), equal cardinality, and outer total coverage 36 versus 34, so the outer/header-inclusive group is retained and the inner pair is filtered.
I’ll now run the complete repository test suite and inspect the final diff/status for accidental files or formatting issues.
- Assistant
All repository tests pass,
go vetpasses for the affected package,git diff --checkis clean, and only the intended source file is modified. I’ll do one final code review of the changed block and repository status, then submit if unchanged. - Assistant
Final review confirms the dedup stage now performs cross-group normalization after the existing within-group pass, keeps maximal source coverage, and propagates suppressed fragments into pair filtering. No generated files are present.
Checklist:
- Reported error reproduced: The exact v1.22.9 JSON was not reproduced on current HEAD because current fragment extraction already yields 8 groups and does not emit the historical
299–315/318–334windows. I did reproduce the underlying disconnected-group condition from the grouping flow and verified the reported ranges satisfy the new bijective rule (17/18 overlap for both members), selecting298–315/317–334. - Fix confirmed: The reported two groups now compare as one logical relation; the larger header-inclusive group is retained, and fragments/pairs unique to the shifted group are suppressed. A full Fixit run completes successfully and contains no remaining near-duplicate group pairs.
- Reported error reproduced: The exact v1.22.9 JSON was not reproduced on current HEAD because current fragment extraction already yields 8 groups and does not emit the historical
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.