Skip to content

[Bug]: Node ID collisions silently drop nodes on documentation-heavy corpora #4738

Open

Description

@snapp-kenya

Pre-flight checks

  • I have checked the Troubleshooting section in the README

What happened?

Node ID collisions silently drop nodes on documentation-heavy corpora

Summary

On a 474-file Markdown corpus, graphify extract resolved 18 distinct node-ID collisions by silently dropping one node each. The IDs in question are minted from a referenced document's path while the node carries the citing document's source_file, so two unrelated files legitimately produce the same ID and the loser is lost.

The workaround the warning itself recommends — graphify extract per subfolder + graphify merge-graphs — does not fully fix it. Splitting by top-level folder still left 7 collisions inside a single subtree, which only cleared after a second, manual recursion. There is no file-level extraction mode to fall back on.

Environment

  • graphify 0.9.94 (installed from source in python:3.12-slim, pip install ".[mcp,openai]")
  • Backend: deepseek / deepseek-flash
  • Corpus: 474 Markdown files (~4.8 MB), 470 docs + 4 code files
  • Platform: macOS (Docker Desktop, arm64)

Reproduction

Any corpus where document A links to or cites document B in another folder reproduces this, because A mints a node whose ID is derived from B's path.

docker run --rm --entrypoint graphify -e DEEPSEEK_API_KEY \
  -v /path/to/docs:/work graphify:extract extract /work

Observed collisions

Real examples from the run:

WARNING: node 'specifications_20_architecture_operational_logging_document'
  is minted by two different files — keeping 'Logging' from
  'specifications/20-architecture/delivery/change-policy.md',
  dropping 'Logging specification' from '.github/instructions/rust.instructions.md'
WARNING: node 'functional_agent_runtime_doc'
  is minted by two different files — keeping 'Agent runtime' from
  'functional/agents/agent-operator.md',
  dropping 'Agent Runtime and Subagent Contract (referenced)' from
  'delivery/developer-interaction.md'
WARNING: node 'company_license_schedule_c'
  is minted by two different files — keeping 'Schedule C - Support' from
  'company/license.md',
  dropping 'Schedule C - Support' from 'company/license-schedule-c.md'

The core defect

Look at the surviving node for the first example:

{
  "id": "specifications_20_architecture_operational_logging_document",
  "label": "Logging",
  "file_type": "document",
  "source_file": "specifications/20-architecture/delivery/change-policy.md"
}

The ID says .../operational/logging, but source_file says .../delivery/change-policy.md. The node was minted from a reference to operational/logging.md and never got the identity of the file it actually came from.

So:

  1. A reference stub is minted with the target's path in its ID but the citing file's source_file.
  2. When the real target document is extracted, it mints the same ID.
  3. Dedup keeps one and drops the other — and in this case it kept the stub whose source_file contradicts its own ID, not the defining document.

That last point is the sharpest bug: the survivor is the wrong node. A node whose source_file disagrees with its ID should lose to one where they agree.

Why the documented workaround is insufficient

The warning says: "run 'graphify extract' per subfolder and merge with 'graphify merge-graphs'."

merge-graphs correctly prefixes IDs per input (repo::id), so merged IDs are unique — that part works. But the loss happens inside each subfolder's own dedup pass, before the merge:

Grouping Collisions observed
Whole corpus, one run 11 distinct IDs (enumerated from the semantic cache)
18 folder groups (specifications split by subfolder, company split per file) 7 more, all inside specifications/20-architecture
+ 8 subfolder groups for that subtree 0

18 distinct colliding IDs in total.

The 7 extra ones are instructive: they did not appear in the whole-corpus run at all. Per-folder chunking changes which neighbours the model sees, so it emits reference stubs it had not emitted before. Collision count is therefore not stable across groupings — you cannot verify a corpus is clean by checking one configuration. Reaching zero required hand-inspecting each round's warnings and recursing manually; nothing in the tooling detects that a group is still internally lossy, and a lossy run still exits 0.

Two further gaps make the workaround harder than it should be:

  • File-level extraction is not supported. graphify extract /work/README.md fails with Not a directory, even though a single file is a perfectly valid extraction unit. This is the natural granularity when two files in the same folder collide (the company/license.md case above).
  • Symlinks are not followed, so you cannot assemble a synthetic "group" directory of links; I had to physically copy files into a mirror tree (and preserve their relative paths so source_file stayed correct).

Impact

  • Silent data loss at the node level: 18 nodes dropped, and with them their edges. The run reports success.
  • The surviving node can be the wrong one (stub over definition), corrupting source_file provenance for that entity.
  • Affects documentation corpora specifically, where cross-references are the norm — i.e. the exact input graphify is marketed for.
  • Only surfaces as a stderr WARNING; nothing in the exit code or summary line reflects it.

Suggested fixes

  1. Don't mint a node for a cross-document reference. Emit an edge to the target's own node when it exists, or give the stub an ID that encodes the citing file (<citing>__ref__<target>), so it can never collide with the definition.
  2. Prefer the defining node in dedup. When IDs collide, prefer the node whose source_file matches the path segment embedded in the ID; treat a node whose source_file contradicts its ID as the loser.
  3. Report collisions in the run summary, not just stderr — e.g. 18 node-ID collisions resolved by dropping nodes; re-run per folder to keep them. A non-zero count currently looks identical to a clean run.
  4. Add an extraction-unit flag (--unit=folder|file) so the recommended workaround is expressible without shell scripting, and/or --id-namespace=<tag> to prefix IDs within a single run.
  5. If neither is done, at least follow symlinks so group directories can be assembled without copying.

Workaround used

18 folder groups (with specifications and company split further), 8 additional groups for the specifications/20-architecture subtree, then merge-graphs over 25 graphs:

Single run Per-folder + merge
Nodes 2,692 3,504
Edges 4,490 5,466
Duplicate IDs 0 0
Node-ID collision warnings 18 0

Merge dropped 4 nodes versus the sum of its inputs; those are external stubs (stdlib/third-party), which prefix_graph_for_global intentionally leaves unprefixed so they unify across inputs. That is expected behavior, not a collision.

Activity

  1. added
    bug
    on Oct 24, 2026
  2. github-actions commented on Oct 24, 2026

    @github-actions

    Thanks for opening this issue, @snapp-kenya. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  3. BreBryBro commented on Oct 29, 2026

    @BreBryBro

    Two more data points from graphify 0.9.97 (a newer release than the 0.9.94 in the report), on a mixed code + docs repo with about 9,200 source files and an Anthropic backend through the Message Batches API. The run emitted 4 minted by two different files warnings. They show two distinct mechanisms, and the second one is not a cross-reference stub.

    1. Same shape as your company/license.md vs license-schedule-c.md example: a filename stem that is a prefix of another.

    WARNING: node 'docs_prds_prd_1572_gov_actor_integrity_engine' is minted by two different files —
      keeping 'PRD-1572 Gov Actor Integrity Engine' from 'docs/prds/PRD-1572-GOV-ACTOR-INTEGRITY-ENGINE.md',
      dropping 'Gov Actor Integrity Engine (PRD-1572)' from 'docs/prds/PRD-1572.md'
    

    Path stem docs_prds_prd_1572 + entity gov_actor_integrity_engine produces the same string as path stem docs_prds_prd_1572_gov_actor_integrity_engine + the file's own title entity. Joining with _ is not injective when one stem is a prefix of another. Both are real defining documents, so neither is a stub and a "prefer the defining file" rule (#4743) cannot choose between them. Only a non-ambiguous separator or a salt can.

    2. Semantic ids with no path prefix at all. Three of the four look like this:

    WARNING: node 'min_sample_n_floor' is minted by two different files —
      keeping 'MIN_SAMPLE_N_FLOOR (250)' from 'docs/adr/A.md',
      dropping 'MIN_SAMPLE_N_FLOOR = 250 / INCONCLUSIVE' from 'docs/adr/B.md'
    

    causal_use_warning and forbidden_token_lint behave the same way, with the same two files. In each case the model emitted the bare constant name as the id. In the same graph, a sibling ADR's node for the same concept was path-qualified (docs_adr_<C>_..._min_sample_n_floor). So qualification depends on what the model returns, and nothing re-qualifies a bare id afterwards. The ids carry no path, so they are not the #4281 case, which drops only the directory. #4281's path-qualifying pass keys on a shorter path stem and would not apply to these, as far as I can tell.

    Here B is a newer ADR that restates A's constants. Whether one shared node is the right answer is arguable: they are the same constant. But the loser's label carries information the survivor lacks (/ INCONCLUSIVE), and the drop is silent apart from stderr.

    Counts: the run had 4 collisions and 654 extracted twice from '<same file>' under different labels notes. The 654 are same-file and much less concerning.

    Suggestions, in addition to the ones in the report:

  4. CBEPX commented on Nov 10, 2026

    @CBEPX

    A related case still reproduces in graphifyy==0.9.104: two slices of one file can emit a definition and a marked reference stub with the same ID.

    The same-file case can lose substantive information. This synthetic reproducer needs no model, credentials, or source repository:

    from copy import deepcopy
    from pathlib import Path
    from graphify.dedup import deduplicate_entities
    
    definition = {
        "id": "rbac_role",
        "label": "Readonly role grants get, list and watch on pods only after approval.",
        "file_type": "code",
        "source_file": "rbac.yaml",
        "source_location": "rules",
    }
    stub = {
        "id": "rbac_role",
        "label": "Readonly role (reference only)",
        "file_type": "code",
        "source_file": "rbac.yaml",
        "source_location": "roleRef",
        "metadata": {"graphify_reference_stub": True},
    }
    
    for incoming in ([definition, stub], [stub, definition]):
        nodes, _ = deduplicate_entities(
            deepcopy(incoming), [], communities={}, root=Path.cwd(), hyperedges=[]
        )
        print([node["label"] for node in nodes])
        assert definition["label"] in {node["label"] for node in nodes}

    The assertion fails. Both input orders select Readonly role (reference only) and remove the permission details and approval condition.

    _namespace_reference_stub_collisions requires at least two distinct source_file values. It does not protect different slices of the same file. _collision_rank then favors the shorter label.

    This also occurred in a real extraction from a split YAML file. A separate validation guard rejected the duplicate IDs before publication. Direct native dedup of that retained result selected the stub over the detailed definition.

    A possible fix is to retain fragment identity until collision resolution. Preserve each fragment's node attributes and rewire its edges and hyperedges together. Merely choosing the first or shortest label can discard conditions.

    I tested a local wrapper workaround with fragment-scoped IDs. Native CLI cold and warm runs preserve both labels and their relationships. This is not an upstream patch.

  5. BreBryBro commented on Nov 10, 2026

    @BreBryBro

    A correction to our 2026-10-29 comment. There we called our 654 same-file extracted twice from '<same file>' under different labels notes "much less concerning". Measured against CBEPX's same-file case, that judgment was wrong.

    Reproducer on our build version. We ran CBEPX's model-free reproducer unchanged on graphifyy==0.9.97, the version our graph was built with. It fails the same way: the reference stub wins in both input orders.

    A variant with no stub marker fails too: two plain same-file definitions with the same id, one with a longer, more detailed label. The shorter label is kept in both input orders. So in 0.9.97 the same-file path loses information even without graphify_reference_stub.

    Our 654 notes, counted from the run's stderr (all 654 parsed):

    Outcome Notes
    shorter label kept 649
    equal length 5
    longer label kept 0
    dropped label at least 2× the length of the kept one 149
    kept label is a substring of the dropped one 356

    The notes come from 106 distinct files, mostly Markdown (570), then HTML (35), text (27) and PDF (22). So on same-file collisions the shorter label wins every time, and in about a quarter of cases what is dropped is substantially longer.

    This supports keeping fragment identity until collision resolution, as proposed above. A tie-break of "shortest label" (or "first seen") cannot tell a qualifier-bearing definition from a terse duplicate.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions