Skip to content

dedup.py Pass 1 exact normalization merges short generic labels across unrelated files, inflating god_nodes #895

Closed

Description

@Adriftnote

dedup.py Pass 1 exact normalization merges short generic labels across unrelated files, inflating god_nodes

Summary

dedup.py:deduplicate_entities() Pass 1 ("exact normalization") groups nodes by _norm(label) — a key that lowercases the label and collapses non-alphanumeric runs to spaces. For short, generic labels (main(), description, methodology, init(), issue, …) this key is identical across many unrelated source files, so the pass unions every occurrence into a single survivor node and rewires every incoming edge onto it.

The fuzzy-pass guard (_short_label_blocked, _is_variant_pair) only runs on Pass 2 (MinHash/JW). Pass 1 is unconditional — there is no short-label or generic-label gate before the union.

Result: artificial god nodes whose degree comes entirely from cross-source collisions, not real centrality. This is distinct from #438 (AST _make_id stem collision) and #543 (cross-file INFERRED calls resolution via global name map) — those operate at the extraction layer; this one fires at the dedup layer, after the AST extractor has correctly produced distinct IDs.

Root cause

graphify/dedup.py ~L165-L180:

# ── pass 1: exact normalization ───────────────────────────────────────────
norm_to_nodes: dict[str, list[dict]] = defaultdict(list)
for node in unique_nodes:
    key = _norm(node.get("label", node.get("id", "")))
    if key:
        norm_to_nodes[key].append(node)

uf = _UF()
for key, group in norm_to_nodes.items():
    if len(group) > 1:
        winner = _pick_winner(group)
        for node in group:
            uf.union(winner["id"], node["id"])

_norm (L17): re.sub(r"[^a-z0-9]+", " ", label.lower()).strip() — "main()", "main", "MAIN" all collapse to "main".

The Pass 2 guards (_short_label_blocked, _is_variant_pair) explicitly handle this risk for fuzzy matches but never see Pass 1.

Reproducer

Real corpus: a knowledge-archive repo with skills/, scripts/, third-party plugin trees. graphify v0.8.5.

After full /graphify --update:

Survivor node ID Survivor label Surviving degree Distinct source_file values feeding edges
skills_scout_main main() 99 15+ (scripts/scan_tool_inventory.py, scripts/archive_tool.py, scripts/build_embeddings.py, docs/archive-agent-poc/scripts/archive_agent_poc.py, Understand-Anything/.../extract-domain-context.py, …)
raw_nemotron3_..._description description 98 17 paper JSON files
raw_agentic_..._methodology methodology 40 8 paper JSON files

Verification — exactly one node survives Pass 1 for each _norm key:

>>> from graphify.dedup import _norm
>>> _norm("main()")
'main'
>>> _norm("description")
'description'
>>> _norm("methodology")
'methodology'
>>> _norm("init()")
'init'

In the surviving graph, [n for n in nodes if n["label"] == "main()"] returns a single node carrying every incoming calls edge from 15+ unrelated callers — those callers' own main() functions had distinct AST-generated IDs (scripts_archive_tool_main, scripts_scan_tool_inventory_main, …) that Pass 1 collapsed.

Merge log line confirms the scale:

[graphify] Deduplicated 3559 node(s) (3287 exact, 272 fuzzy).

3287 of the 3559 merges came from Pass 1.

Why this hits paper-corpus users especially hard

When the input includes structured paper JSONs (Nemotron, Externalization in LLM Agents, …), semantic subagents commonly emit field-name nodes (description, methodology, core_problem, abstract, summary). Each individual paper produces a distinct ID, but every label normalizes to the same key, so Pass 1 collapses all of them into one god node per field name.

The downstream effects:

  • god_nodes() output is dominated by these artifacts, not by real abstractions
  • Community detection treats the survivor as a hub, distorting community boundaries
  • surprising_connections produces spurious bridges via the collision node
  • Suggested Questions are framed around AMBIGUOUS edges that exist only because of the collision

Proposed fix (any of these, in increasing complexity)

(a) Short / generic label guard for Pass 1. Skip the union if the _norm key is ≤ N characters (e.g. 12, same threshold as _short_label_blocked) and the group nodes belong to different source_file values. Mirror the existing Pass 2 guard.

(b) Source-file disjointedness check. Inside Pass 1, only union nodes whose source_file paths share a common directory ancestor, or when entropy of _norm exceeds a threshold (very generic single-word labels fail). The current _entropy helper is only used for Pass 2 candidate selection — it could gate Pass 1 too.

(c) Generic-label denylist. Hard-list the recurring offenders for code (main, init, run, update, setup, teardown) and paper schemas (description, methodology, abstract, summary, introduction, conclusion, limitations, related_work). Refuse Pass 1 merges when the key is on this list and the source_files differ.

(d) Opt-out flag. --no-exact-dedup or dedup_short_labels=False parameter on deduplicate_entities. Less elegant but immediately useful for users running incremental updates on heterogeneous corpora.

(a) is the smallest change with the broadest impact. (c) is more aggressive but matches the failure modes users actually see.

Environment

  • graphify version: 0.8.5
  • Python: 3.13
  • Install: uv tool install graphifyy
  • Corpus: ~3000–5000 nodes, mixed code + wiki + papers, run via /graphify --update

Related

Happy to send a PR for (a) — Pass 1 short-label guard mirroring _short_label_blocked's threshold — if there's appetite for the patch.

Activity

  1. safishamsi commented on May 16, 2026

    @safishamsi
    Member

    Fixed in v0.8.7.

    Pass 1 now partitions same-label groups by source_file before unioning. Nodes with generic labels (handle, init, run) from different files are no longer merged — they fall through to Pass 2 fuzzy matching where the entropy/similarity gates prevent god-node creation. Within the same file, same-label merging still works as before.

    Also fixed the exact_merges counter which previously over-counted by including cross-file non-merges.

  2. added 2 commits that reference this issue on May 16, 2026
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