AST and semantic extractors generate mismatched node IDs for the same file, splitting it into two disconnected nodes
Related to #952 (same root cause, opposite manifestation — that one is collision; this is divergence).
Bug
When a file is processed by both the AST extractor (Step 3A) and a semantic subagent (Step 3B), the two paths can produce different IDs for the same physical file. The AST extractor generates IDs from Path(f).stem (bare filename, no path prefix). Semantic subagents, following the Step 3B prompt, naturally use the relative path as context and produce IDs like script_pipeline_step or src_pipeline_step. The Step 3C merge deduplicates by id — so the two nodes never merge.
Result
One physical file ends up as two unconnected nodes in graph.json:
- AST node (
pipeline_step) — island containing only internalcontainsedges to its own functions. Appears fully disconnected in the HTML viz. - Semantic node (
script_pipeline_step) — carries all cross-file edges:references,shares_data_with,implements, etc.
The file looks broken in the visualization. Any graph traversal asking "what does this file connect to externally?" starts from the AST node and finds nothing, even though the semantic node has the correct edges.
Repro
Run graphify on any project where Python (or other code) files live under a subdirectory (script/, src/, lib/, etc.) so the relative path has a prefix beyond the stem. The semantic subagent will naturally prefix the ID; the AST extractor will not. Any such file that also appears in doc/config files cross-referenced by relative path will produce split nodes.
Verify by inspecting graph.json: search for both pipeline_step and script_pipeline_step — both will exist with disjoint edge sets.
Expected
Step 3C (or the AST extractor) should normalize all node IDs to a consistent relative-path-based slug before deduplication, so AST and semantic nodes for the same file always land on the same ID and merge. The fix direction in #952 is correct — it just needs to apply symmetrically to the semantic subagent prompt as well.
Version
graphifyy 0.8.16
It's possible this is an issue of mismatching SKILL.md version to graphify cli version, I'm rerunning my extractions to verify if this is the case.
Follow-up: two remaining cases after the 0.8.16 symbol-ID fix
Tested against a 48-file Python data-pipeline project on graphify 0.8.16 with the updated skill. The symbol-level ID fix works — function nodes now match between AST and semantic extraction. But two related cases remain.
1. File-level node IDs still use full path (not one-parent-dir)
The 0.8.16 fix applied parent_dir.stem to symbol nodes via _file_stem(), but the file-level node itself is still ID'd from the full relative path from the cache root. A file at match/script/pipeline_step.py gets AST file node ID match_script_pipeline_step_py (full path normalized), while the semantic subagent — following the {parent_dir}_{stem} rule — generates script_pipeline_step as its reference. They don't collide, so the merge step creates two nodes.
Result: the DAG task references an intermediate Script: node (semantic), which has no edge to the AST file node. Queries about "what calls this file?" or "which DAG task runs this?" start from the AST island and find nothing.
The fix needs to apply symmetrically to file-level node IDs in the AST extractor, not only to symbol IDs.
2. Rationale fragment nodes from AST docstring extraction
After updating to the 0.8.16 skill, rationale nodes no longer appear from semantic subagents. However, the AST extractor still emits them — it extracts Python docstrings as rationale_for edges with the docstring text as a node label (e.g. script_pipeline_step_rationale_9, script_pipeline_step_rationale_32, etc.). These are single-edge orphan nodes identical in character to the ones the 0.8.16 skill prompt fixed on the semantic side.
The 0.8.16 rationale-as-attribute change needs to be applied to the AST extractor's docstring handling as well.
Versions
graphifyy 0.8.16
Real bug, confirmed in the source. The root cause is more specific than a general ID format mismatch:
extract.py line ~1684:
file_nid = _make_id(str(path))
str(path) includes the file extension. _make_id turns dots and separators into underscores, so script/pipeline_step.py → script_pipeline_step_py (note trailing _py).
skill.md line ~390 tells semantic subagents to use {parent_dir}_{stem} format:
script/pipeline_step.py → script_pipeline_step (no extension).
These two IDs never match, so AST and semantic nodes for the same file land as two disconnected graph nodes every time.
Suggested fix: add a canonical_file_id(path, root) helper in extract.py that uses _make_id(path.parent.name, path.stem) — matching the skill.md spec exactly — and replace the _make_id(str(path)) call at the file node construction site. A build.py normalizer pass (strip known extension suffixes like _py, _ts, _js) would handle backward compatibility for existing cached graphs.
PRs welcome — this is a clear, contained fix.
https://github.com/safishamsi/graphify/pull/1038 - made a fix in this pr @ryanhaarmann @safishamsi
Fixed in c898dc6, shipping in the next release.
Root cause
The file-level node ID was derived from the full relative path with extension (match/script/pipeline_step.py -> match_script_pipeline_step_py), while semantic subagents follow the skill.md {parent_dir}_{stem} spec (script_pipeline_step). The two never collided, so every file split into two disconnected nodes - exactly as you diagnosed.
The fix
Rather than rewrite the ~55 per-language extractor sites that emit _make_id(str(path)) (which is what the two community PRs attempted), the fix lives at the single remap chokepoint in extract(). File node IDs and every edge endpoint already funnel through the #502 relative-path remap pass for cross-machine stability. Changing that one pass to emit the {parent_dir}_{stem} form converts the node and every referencing edge together, atomically.
This matters because file IDs are import/dependency edge targets in many places. Converting the node without the edge targets just moves the orphan from "AST vs semantic" to "file node vs its own import edges." The chokepoint approach avoids that by construction - verified end-to-end that Python, TypeScript, Lua, C and bash import edges all stay connected after the change. symbol_resolution.py pre-computes the canonical form directly (bypassing the remap), so it was synced to match.
Top-level files collapse correctly too (setup.py -> setup, not {rootdir}_setup) because the remap relativizes to the project root first.
Added tests/test_file_node_id_spec.py covering the spec format, top-level files, file<->symbol stem sharing, and cross-file edge connectivity. Full suite green (1490 passed).
Backward compat
Existing cached graphs keep the old _py/_ts-suffixed IDs until rebuilt. Run graphify extract --force to migrate cleanly, as the skill.md spec already documents.
On the rationale sub-issue (#2)
Leaving that one as-is for now: file_type == "rationale" nodes with rationale_for edges are intentional - the cross-file resolution and god-node ranking explicitly handle them, and they have dedicated test coverage. Inlining them as attributes is a separate design decision with its own tradeoffs, not part of this ID-mismatch fix. Happy to discuss it in its own issue if you'd like to make the case.
Thanks for the precise diagnosis @ryanhaarmann - the extract.py:2224 vs skill.md:390 pinpoint made this straightforward.