Repository navigation
Description
Pre-flight checks
- I have checked the Troubleshooting section in the README
What happened?
When a semantic (doc) node and an AST code node share an id, and the doc's own path is a prefix of that id, _defines_id returns True for both. _collision_rank then has no provenance key left to separate them: the next keys are "has a source_file" (both do), the lifecycle penalty (equal), and then label length. A doc node with a shorter label than the code node wins.
The code node then carries the doc as its source_file. On the next --update that re-extracts the doc without that node, build_merge replaces the doc's nodes and the code node is deleted, although the code file never changed.
Layout that triggers it: pkg.md beside pkg/test_x.py. The AST id for the file is pkg_test_x. The extraction spec asks doc subagents to reuse the AST id for a code entity they describe, so pkg.md emits pkg_test_x, and pkg_ is also a prefix of pkg.md's own path.
Checked directly on 0.9.97:
Tests | defines: code True doc True | rank code (False, False, 1, 9) doc (False, False, 1, 5) | winner doc
test_x.py (tests) | defines: code True doc True | rank code (False, False, 1, 9) doc (False, False, 1, 17) | winner code
So the outcome depends on how briefly the doc names the file. This is not #4738 (reference stubs between documents, fixed by #4743, landed in 0.9.96; the skill's extraction spec does not ask subagents for that marker) and not #4281 (dropped extensions). The definer-wins rule (_defines_id as the first rank key) holds whenever only one side's path prefixes the id. The gap is the case where both do.
Expected: the AST/code-tier node keeps the id, since it is extracted fact and the doc's copy is an inference about it (CONTRIBUTING: "Keep inference visibly separate from extracted fact"). The doc node's edges then attach to the code node.
Possible fix: in _collision_rank, add a key right after the defining key that prefers _origin == "ast" over _origin == "semantic" when both sides define the id. It changes no collision where only one side defines it.
Steps to reproduce
Self-contained, no corpus needed (writes a temp graph.json):
"""A doc whose own path prefixes a code node's id takes that node over in build_merge,
and the doc's next re-extract deletes it."""
import json, tempfile
from pathlib import Path
import graphify
from graphify.build import build_merge
from networkx.readwrite import json_graph
d = Path(tempfile.mkdtemp())
code = {"id": "pkg_test_x", "label": "test_x.py", "file_type": "code",
"source_file": "pkg/test_x.py", "source_location": "L1", "_origin": "ast"}
other = {"id": "pkg_test_x_run", "label": "run()", "file_type": "code",
"source_file": "pkg/test_x.py", "source_location": "L3", "_origin": "ast"}
g = {"directed": False, "multigraph": False, "graph": {}, "hyperedges": [],
"nodes": [code, other],
"links": [{"source": "pkg_test_x", "target": "pkg_test_x_run", "relation": "contains",
"confidence": "EXTRACTED", "source_file": "pkg/test_x.py", "_origin": "ast"}]}
(d / "graph.json").write_text(json.dumps(g))
# --update re-extracts only the doc pkg.md; its subagent gives the code file's node the AST id,
# as the extraction spec asks
doc = {"nodes": [{"id": "pkg_test_x", "label": "Tests", "file_type": "code",
"source_file": "pkg.md", "_origin": "semantic"},
{"id": "pkg_overview", "label": "Overview", "file_type": "document",
"source_file": "pkg.md", "_origin": "semantic"}],
"edges": [{"source": "pkg_overview", "target": "pkg_test_x", "relation": "describes",
"confidence": "EXTRACTED", "source_file": "pkg.md", "_origin": "semantic"}],
"hyperedges": []}
G = build_merge([doc], graph_path=d / "graph.json")
print("graphify", graphify.__version__ if hasattr(graphify, "__version__") else "")
print("1) after merge: pkg_test_x source_file =", G.nodes["pkg_test_x"].get("source_file"))
(d / "graph2.json").write_text(json.dumps(json_graph.node_link_data(G, edges="links")))
doc2 = {"nodes": [{"id": "pkg_overview", "label": "Overview", "file_type": "document",
"source_file": "pkg.md", "_origin": "semantic"}], "edges": [], "hyperedges": []}
G2 = build_merge([doc2], graph_path=d / "graph2.json")
print("2) after pkg.md is re-extracted without that node: pkg_test_x present =", "pkg_test_x" in G2)Error output or graph output
[graphify] WARNING: node 'pkg_test_x' is minted by two different files — keeping 'Tests' from 'pkg.md', dropping 'test_x.py' from 'pkg/test_x.py'. An ID is derived from the source path plus the entity name, so this one does not identify a single entity and the dropped node is lost. To keep them distinct, run 'graphify extract' per subfolder and merge with 'graphify merge-graphs'.
[graphify] Replaced 2 node(s) from re-extracted source file(s).
graphify
1) after merge: pkg_test_x source_file = pkg.md
2) after pkg.md is re-extracted without that node: pkg_test_x present = False
With the doc label "test_x.py (tests)" (longer than test_x.py) the code node survives and step 2 prints True.
Graphify version
0.9.97
Operating System
Windows
Python Version
3.12
Installation Method
pip
Additional Environment Details
graphifyy 0.9.97 installed with pip on Windows 11, Python 3.12. graphify/dedup.py at v8 HEAD is byte-identical to the 0.9.97 wheel's copy (curl of the raw file, then cmp, 2026-10-29).
Additional context
Found while running the skill's --update path on a corpus mixing docs and code; worked around locally by dropping semantic nodes whose id an AST code node from another file already owns, before build_merge.
Activity
github-actions commentedon Oct 29, 2026
Thanks for opening this issue, @Kalessin-Roke. 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.
fix(dedup): keep an AST definer's id when another file's node also de…