Skip to content

Dedup pass 2 over-merges: winner picked from full normalized-label groups pulls in never-compared nodes #1247

Closed

Description

@teemow

Problem

In deduplicate_entities pass 2 (graphify/dedup.py), when a fuzzy pair (node, neighbor) passes all guards and reaches the merge step, the winner is selected from the union of both normalized-label groups:

all_group = norm_to_nodes.get(norm_label, [node]) + \
            norm_to_nodes.get(neighbor_norm, [neighbor])
winner = _pick_winner(all_group)
uf.union(winner["id"], node_id)
uf.union(winner["id"], neighbor_id)

norm_to_nodes[norm_label] contains every node sharing that normalized label — including same-label/different-source_file nodes that pass 1 deliberately kept separate (#1178) and that the pass-2 identical-label cross-file guard (#1046) also refuses to merge. If _pick_winner selects one of those never-compared nodes, the two uf.union calls merge it with both members of the verified pair, silently bypassing both guards.

Reproduction

from graphify.dedup import deduplicate_entities

nodes = [
    {"id": "session_manager_auth", "label": "Session Manager", "source_file": "auth.md"},
    {"id": "sm",                   "label": "Session Manager", "source_file": "billing.md"},
    {"id": "session_managr_notes", "label": "Session Managr",  "source_file": "notes.md"},
]
result, _ = deduplicate_entities(nodes, [], communities={})
print(len(result))  # 1 — all three collapsed into "sm"

Only the typo pair (Session Manager / Session Managr) was ever verified by Jaro-Winkler. sm (same label as A, different file) was never compared against anything, yet _pick_winner selects it (shortest id) and both unions run through it — all three nodes collapse into one. Expected: the verified pair merges, sm stays distinct (2 nodes).

Proposed solution

Pick the winner from the verified pair only:

winner = _pick_winner([node, neighbor])

Group members that genuinely belong together are still reachable: same-file duplicates were already unioned in pass 1, and any other member must win its own guarded comparison to join.

Acceptance criteria

  • The reproduction above yields 2 nodes, with sm surviving as a distinct node.
  • Regression test covering the scenario in tests/test_dedup.py.
  • Existing test suite stays green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions