Skip to content
TheChatArchiveThe Chat Archive
QwenQwen/Qwen3.6-27B· alibabaHugging 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.

    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. Qwen Assistant

    Let me analyze this bug report. The issue is about pyscn's clone detector emitting two separate clone groups that describe the same duplication relationship between the same two code fragments, with member windows shifted by exactly one line. This results in redundant clone groups that inflate the clone_groups count and duplication percentage.

    Let me start by exploring the repository structure to understand the codebase.

  3. Qwen Assistant

    Good, I can see the basic structure. Let me explore more to find the clone detection related code.

  4. Qwen Assistant

    Let me explore the Go source code structure, particularly looking for clone-related code:

  5. Qwen Assistant

    I can see there's a group_dedup.go file which is likely related to deduplicating clone groups. Let me look at the key files:

  6. Qwen Assistant

    Now let me look at the test file for group dedup:

  7. Qwen Assistant

    Now I understand the issue better. The current dedupeStrictSubsetGroupMembers function handles deduplication within a single group (removing members that are strict subsets of other members in the same group). However, the bug reported is about two separate groups that are near-duplicates of each other - both groups describe the same duplication but with slightly different window boundaries.

    Let me look at the clone detector to understand how groups are formed and where the dedup happens:

  8. Qwen Assistant

    Now I need to understand the issue better. The problem is that two separate clone groups are emitted that describe the same duplication between the same two fragments. Let me look at how groups are formed:

  9. Qwen Assistant

    Now let me look at the complete linkage grouping, which might be more relevant:

  10. Qwen Assistant

    Now I understand the issue better. The problem is that when detecting clones, the system can produce two different clone groups that describe the same duplication between the same fragments, but with slightly different window boundaries (one line shifted). This happens because different fragments at slightly different line ranges are detected as clones.

    Let me think about this more carefully:

    • Group 6 has fragments at lines 299-315 and 318-334
    • Group 14 has fragments at lines 298-315 and 317-334

    These are the same pairs of code locations, but with different fragment boundaries. The issue is that these two groups are separate groups and the dedup logic doesn't handle deduplicating across groups.

    Let me look at how fragments are created and if there could be multiple fragments representing the same location:

  11. Qwen Assistant

    Let me look at the pairKey and fragmentLess functions:

  12. Qwen Assistant

    Now I understand the problem better. The issue is that two separate groups are being produced that represent the same duplication. This happens because the clone detector finds multiple overlapping code fragments, and when grouped, they form two near-identical groups.

    The current dedupeStrictSubsetGroupMembers only deduplicates within a single group (removing members that are strict subsets of other members in the same group/file). But the bug is about deduplicating across groups - when two groups are near-duplicates of each other.

    Let me think about the solution:

    1. After grouping, I need to add a step that merges or suppresses clone groups whose members are overlapping windows of the same underlying fragments.
    2. Two groups should be considered duplicates if, for each member in one group, there's a "corresponding" member in the other group that overlaps significantly (or one covers the other).

    Let me first create a reproducer to understand the issue better:

  13. Qwen Assistant

    Let me look at the integration test to understand how the system works end-to-end:

  14. Qwen Assistant

    I see the test infrastructure. Let me look more at the issue - the key insight is that the duplicate groups have members that overlap with each other. For example:

    • Group 6: A1 (299-315), B1 (318-334)
    • Group 14: A2 (298-315), B2 (317-334)

    Where A1 is a strict subset of A2 (same file), and B1 is a strict subset of B2 (same file). These are the same duplication but with slightly different window boundaries.

    The solution should detect when two groups are essentially describing the same duplication relationship and merge/suppress them. Let me look at where this deduplication should happen:

  15. Qwen Assistant

    Now I see the flow. After grouping, dedupeStrictSubsetGroupMembers is called, which only handles deduplication within a single group. I need to add a function that deduplicates across groups.

    Let me write a test first to reproduce this issue:

  16. Qwen Assistant

    Let me look at the test helper functions used in group_dedup_test.go:

  17. Qwen Assistant

    Need to find the gf and gp helper functions used in the tests.

  18. Qwen Assistant

    Now I understand the test helpers. Let me now create a test that reproduces the issue described in the bug report:

  19. Qwen Assistant

    Good, my understanding is correct. Now let me design the solution. The fix should:

    1. After dedupeStrictSubsetGroupMembers runs (which handles within-group dedup), add a new step that deduplicates across groups.
    2. Two groups should be considered duplicates if one is a "superset" of the other:
      • Both groups have the same number of fragments
      • For each fragment in the "inner" group, there exists a fragment in the "outer" group that covers it (same file, outer.start <= inner.start && outer.end >= inner.end)
      • The mapping between the two groups is a bijection (one-to-one)

    Let me first look at the existing code more carefully to understand the data structures:

  20. Qwen Assistant

    Now let me implement the fix. I'll add a new function dedupeOverlappingCloneGroups that removes duplicate groups where one group's members are all covered by another group's members:

  21. Qwen Assistant

    Now I need to add a new function that deduplicates across groups. The key insight is:

    • Group A and Group B are duplicates if they have the same number of fragments
    • For each fragment in one group, there's a corresponding fragment in the other group that overlaps significantly
    • If all fragments of group A are covered by (or overlap with) corresponding fragments of group B, and vice versa, they're describing the same duplication

    Let me add the cross-group deduplication function:

  22. Qwen Assistant

    Now I need to integrate this new function into the dedup pipeline. Let me update the groupClonesWithStrategy function in clone_detector.go:

  23. Qwen Assistant

    I need to add the cross-group dedup step after the within-group dedup. Let me update the function:

  24. Qwen Assistant

    Good. Now let me verify the code compiles:

  25. Qwen Assistant

    Now I need to set up the Go environment properly. Let me check what environment variables are needed.

  26. Qwen Assistant

    The code compiles. Now let me write a test to verify the fix works:

  27. Qwen Assistant

    Now let me run the tests to see if they pass:

  28. Qwen Assistant

    I see several issues:

    1. The test expects g14 to survive but my algorithm keeps g6 (the narrower one). The logic is inverted.
    2. The nil handling needs to filter nil groups from the output.
    3. The "DifferentFiles" test also has the same direction issue.

    Let me look at the issue more carefully. When g6 has narrower windows and g14 has wider windows, g14 should survive. In my code, when allACoversB is true (A covers B), I return groupACoversB, and then the caller suppresses j (the second group). But if A = g6 and B = g14, then g6 doesn't cover g14 — it's the other way around!

    Let me trace through the logic:

    • checkGroupCovering(g6, g14): g6 has fragments at 299-315, 318-334. g14 has fragments at 298-315, 317-334.
    • For each fragment in g6 (a), check if any fragment in g14 (b) covers it:
      • g14[0] (298-315) covers g6[0] (299-315)? YES (298 <= 299 && 315 >= 315)
      • g14[1] (317-334) covers g6[1] (318-334)? YES (317 <= 318 && 334 >= 334)
    • So allBCoversA = true (all of g6 is covered by g14)
    • For each fragment in g14 (b), check if any fragment in g6 (a) covers it:
      • g6[0] (299-315) covers g14[0] (298-315)? NO (299 > 298)
      • g6[1] (318-334) covers g14[1] (317-334)? NO (318 > 317)
    • So allACoversB = false

    Since allBCoversA && !allACoversB, I return groupBCoversA. Then in the caller, groupBCoversA means suppress i (g6). That's correct!

    Wait, let me re-read my code:

    switch covering {
    case groupACoversB:
        // groups[i] covers groups[j], suppress j (the narrower one)
        suppressed[j] = true
    case groupBCoversA:
        // groups[j] covers groups[i], suppress i (the narrower one)
        suppressed[i] = true
    }
    

    When allBCoversA is true and allACoversB is false, I return groupBCoversA. Then in the switch, it does suppressed[i] = true. That's correct! i = g6 should be suppressed.

    But the test shows g6 survived. Let me debug:

  29. Qwen Assistant

    Interesting! The issue is that coveredByA is [true, true] even though g6's fragments don't strictly cover g14's fragments. Let me trace through:

    For checkGroupCovering(g6, g14):

    • a = g6, b = g14
    • coveredByB[i] = true if any b[j] covers a[i]
    • coveredByA[j] = true if any a[i] covers b[j]

    Wait, the condition is fragmentCovers(fb.Loc, fa.Loc) which checks if b[j] covers a[i]. If true, both coveredByB[i] and coveredByA[j] are set to true.

    But the issue is that I'm setting coveredByA[j] whenever b[j] covers a[i]. That's wrong! coveredByA[j] should be set when a[i] covers b[j], not the other way around!

    Let me fix the logic:

  30. Qwen Assistant

    Now the logic is correct. I need to fix my implementation in group_dedup.go. The issue was that I was setting both coveredByB[i] and coveredByA[j] in the same condition. Let me fix it:

  31. Qwen Assistant

    I see the bug. In the inner loop, I have:

    if fragmentCovers(b.Fragments[j].Location, a.Fragments[i].Location) {
        // b[j] covers a[i]
        coveredByB[i] = true
        coveredByA[j] = true  // BUG: this should not be set here!
    }
    

    The coveredByA[j] should only be set when a[i] covers b[j], not when b[j] covers a[i]. Let me fix this:

  32. Qwen Assistant

    Now let me also fix the dedupeOverlappingCloneGroups function to filter out nil groups from the output:

  33. Qwen Assistant

    I need to also skip nil groups when building the output:

  34. Qwen Assistant

    Now let's run the tests again:

  35. Qwen Assistant

    All my new tests pass. Now let me run all existing tests in the analyzer package to make sure I didn't break anything:

  36. Qwen Assistant

    All tests pass. Let me also run the complete test suite to ensure nothing else is broken:

  37. Qwen Assistant

    All tests pass. Now let me review my changes to make sure they're complete and correct:

  38. Qwen Assistant

    Let me also view the changes to clone_detector.go:

  39. Qwen Assistant

    Now let me think about edge cases and review the solution:

    1. Same file vs different files: The fragmentCovers function correctly checks FilePath equality before comparing line ranges. This ensures fragments from different files are not considered to cover each other.

    2. Groups with different sizes: The checkGroupCovering function returns noCovering if groups have different numbers of fragments, which is correct.

    3. Partial overlap: If only some fragments of one group are covered by another group, both groups remain (not duplicates). This is the correct behavior.

    4. Identical groups: If two groups have identical fragment ranges, the first one is kept and the second is suppressed.

    5. Nil handling: Both nil groups and nil fragments within groups are handled correctly.

    6. Empty groups: Empty input or single-group input passes through unchanged.

    Let me also verify the solution is general enough and not hardcoded to specific cases. The algorithm works for:

    • Any number of fragments per group
    • Any number of groups
    • Any file paths
    • Any line ranges

    Let me also think about performance. The algorithm is O(n² * m²) where n is the number of groups and m is the number of fragments per group. This should be acceptable for typical use cases.

    Now let me verify by running the full test suite one more time to make sure everything works:

    <tool_call> <function=bash_terminal> <parameter=command> cd /pyscn && go test ./... 2>&1 | grep -E "(PASS|FAIL|ok|---)" </tool_call>

  40. Qwen Assistant

    I need to run the test command properly.

  41. Qwen Assistant

    All tests pass. Let me verify the changes I've made with git diff:

  42. Qwen Assistant

    I need to run the git diff command properly.

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