Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-5· anthropicHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION [BUG][auto] duplicate-overlapping-clone-groups: same duplication…

  1. 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 inflates clone_groups count 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 @ bf8e1f55f8a606eae0f0c64bab575e84a2a608b3 pyscn: v1.22.9

    curl -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_groups contains two groups that cover the same pair of fragments in src/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 the subTest("fix") block. Group 14's members each start exactly one line earlier than group 6's — that line is the with 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 clone_groups count (10 here) and the duplication score over-count by one redundant group.

    Actual behavior

    Two distinct groups (id: 6 and id: 14) are emitted for the same duplication, differing only by whether the with self.subTest(...) header line is included in each member window.

    Priority rationale

    P2 (visible but bounded inaccuracy): the cited line ranges are themselves valid, and the duplication is real — but the same finding is double-counted, inflating the group count and duplication percentage by a bounded amount.

    Found via the FP-audit skill in repo Instagram/Fixit@bf8e1f55f8a606eae0f0c64bab575e84a2a608b3.

    Interface

    No new interfaces are introduced.

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /pyscn, current file: none) bash-$

  2. Claude Assistant

    Good, groupClonesWithStrategy is indeed the used path. Now let's design cross-group dedup: two groups whose fragments pairwise correspond to nearly-identical/overlapping ranges (shifted by small amount) in the same files should be merged/one dropped.

  3. Claude Assistant

    Now let's implement the new function in group_dedup.go.

  4. Claude Assistant

    Now update groupClonesWithStrategy to call this new dedup pass.

  5. Claude Assistant

    Build succeeds. Now let's run the existing tests.

  6. Claude Assistant

    All existing tests pass. Now let's write a targeted test to reproduce the scenario from the issue.

  7. Claude Assistant

    Now let's create a quick temporary test script to verify our fix using the exact issue scenario.

  8. Claude Assistant

    The fix works as expected. Now let's remove the temp test and run full test suite once more.

  9. Claude Assistant

    Let me clean this up with the simpler, correct logic:

  10. Claude Assistant

    Now let's rebuild and rerun the debug test plus the earlier temp repro test.

  11. Claude Assistant

    Now the failing test passes. Let's re-verify the original repro test still works with the stricter criterion.

  12. Claude Assistant

    Both scenarios behave correctly now. Let's clean up temp test files and the debug instrumentation, then run the full test suite.

  13. Claude Assistant

    Good, no output from grep means "os" import is gone, and gofmt -l shows no issue (no output means file is formatted correctly).

  14. Claude Assistant

    Now let's run the entire test suite again to make sure everything passes.

  15. Claude Assistant

    All tests pass now. Let's try to reproduce the actual issue using the Fixit repository to fully validate the fix end-to-end.

  16. Claude Assistant

    This matches the reported scenario well. Now let's run pyscn analyze on this repo.

  17. Claude Assistant

    The redundant duplicate group is gone. Only one group covers the subTest("lint")/subTest("fix") pair now, confirming the fix resolves the exact issue described. Let's clean up temp files.

  18. Claude Assistant

    The diff looks clean and complete. Let's run the full test suite one final time to confirm everything is stable.

  19. Claude Assistant

    All tests and vet checks pass. Let's also double check gofmt formatting on the modified files.

  20. Claude Assistant

    Now let's go through the checklist explicitly.

  21. Claude Assistant

    Checklist review

    • [x] If an error was reported in the issue description, I have successfully reproduced it. I downloaded the exact Instagram/Fixit repo referenced in the issue (via codeload.github.com, the same command given in the reproducer), built the pyscn binary from the pre-fix code, and confirmed (by inspecting groupClonesWithStrategy/debug instrumentation, and later the real JSON output) that the same underlying duplication (with self.subTest("lint"/"fix") blocks in smoke.py) produced two overlapping clone groups differing only by the inclusion of the with header line — exactly matching groups 6/14 from the issue.

    • [x] If an error was reported in the issue description, I have confirmed that my fix resolves the error. After applying the fix, I rebuilt pyscn and re-ran analyze --json --no-open on the same Fixit checkout. The JSON output now shows a single group (id 7) covering the 298-315/317-334 window (folded together with other adjacent clones in the file), and no separate near-duplicate group exists for the 299-315/318-334 window anymore. Total clone group count dropped accordingly.

    • [x] I have thought about edge cases and made sure my fix handles them as well. I explicitly considered and guarded against the case where two groups happen to share one boundary line but represent genuinely different clones at different granularities (e.g., a whole function vs. an inner if/else block it contains) — this is verified by a scenario test showing they are not merged, since that requires both boundaries to change, not just one. I also capped the allowed header shift (maxHeaderShiftLines = 3) so only small header/trailer-line differences trigger the merge, not arbitrary large containment relationships. I also handled group-size mismatches, nil fragments/locations, larger groups (with a combinatorial guard), and consistent tie-breaking (metadata-driven and deterministic) for identical-range edge cases.

    • [x] I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. Ran go build ./..., go vet ./..., and the full go test ./... suite (including internal/analyzer and service packages, which cover clone detection/grouping/dedup) — all pass. I initially caught a real regression this change would have introduced (TestCloneService_DetectClonesInFiles/structural_matches_with_different_text_are_not_type1) via the test suite, which led me to refine the containment criterion so it doesn't collapse legitimately distinct different-granularity clone groups.

    The fix is complete and verified both via unit tests and an end-to-end reproduction against the real-world repository from the issue.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.