Repository navigation
Description
Summary
graphify export obsidian aborts with KeyError in to_obsidian when a community's member list contains an id that has no backing node in G. The exporter assumes every clustered community member is a key in G.nodes (and in node_filename), but at least one synthesized member id ('agents_doc' in my run) is not — so the whole vault export crashes instead of skipping the dangling member.
Environment
- graphify(y) 0.8.36
- networkx 3.6.1
- Python 3.13.13
- backend:
claude-cli(semantic), macOS
Repro
On a repo whose graph clusters into many communities (mine: ~10k nodes, 1206 communities after cluster-only), where multiple documents normalize to the same stem (e.g. several *-AGENTS.md / doc files across different directories):
graphify extract . --backend claude-cli
graphify cluster-only "$(pwd)" --backend=claude-cli # succeeds: "Done - 1206 communities. GRAPH_REPORT.md and graph.json updated."
graphify export obsidian --dir "$VAULT" # crashes
Traceback
Traceback (most recent call last):
File ".../bin/graphify", line 10, in <module>
sys.exit(main())
File ".../graphify/__main__.py", line 3712, in main
n = _to_obsidian(G, communities, str(obsidian_dir),
community_labels=labels or None, cohesion=cohesion or None)
File ".../graphify/export.py", line 1010, in to_obsidian
for node_id in sorted(members, key=lambda n: G.nodes[n].get("label", n)):
File ".../graphify/export.py", line 1010, in <lambda>
for node_id in sorted(members, key=lambda n: G.nodes[n].get("label", n)):
File ".../networkx/classes/reportviews.py", line 196, in __getitem__
return self._nodes[n]
KeyError: 'agents_doc'
Root cause
In to_obsidian (export.py:1010), the ## Members section iterates a community's members and dereferences each via G.nodes[n] (in the sort key) and node_filename[node_id] on the next line:
for node_id in sorted(members, key=lambda n: G.nodes[n].get("label", n)):
data = G.nodes[node_id]
node_label = node_filename[node_id]
...members can contain an id that is not a node in G. Evidence from my run: the offending id "agents_doc" occurs 0 times in graphify-out/graph.json but does appear in graphify-out/.graphify_analysis.json (the sidecar the exporter draws community/label data from). The graph does contain real nodes whose ids end in _agents_doc (e.g. t3x_rte_ckeditor_image_classes_agents_doc and other *-AGENTS.md doc nodes from different directories), so this looks like a normalized/collapsed concept id that ends up in community membership without being materialized as a node in G. Either way, the export layer trusts a 1:1 member → G.nodes mapping that does not hold.
Suggested fix
Make the member iteration defensive so one dangling id can't abort the entire vault export:
members = [m for m in members if m in G.nodes and m in node_filename]
for node_id in sorted(members, key=lambda n: G.nodes[n].get("label", n)):
...(optionally log.debug the skipped ids). The deeper fix would be upstream — ensure clustering/label assignment only emits real node ids as community members — but guarding the exporter prevents a single synthesized member from taking down the whole export obsidian run.
Workaround
Excluding the directory whose docs produced the colliding stem (via .graphifyignore) and re-running extract removes the synthesized member and lets the export complete.
Activity
fix: obsidian crash, NFC/NFD dedup, JSON data nodes, OpenAI temperatu…
safishamsi commentedon Jun 10, 2026
Fixed in HEAD (commit a37672f).
to_obsidianandto_canvasnow filter community member IDs against the graph before the loop — dangling members are skipped rather than crashing with KeyError. Smoke tested on a fresh v8 install: export completes cleanly with dangling members present. Shipping in the next release.swells808 commentedon Jul 3, 2026
Still reproduces in 0.9.5 — the #1236 fix only landed in
to_obsidian, notto_canvas.On a real export (
graphify export obsidian, py3.14),to_obsidianwrites all notes fine — the guard atexport.py:1104works:…but
to_canvasthen dies on the same dangling member:export.py:1354in the shipped 0.9.5 is unguarded:Same one-line filter as
to_obsidianfixes it:(The
node_filenames.get(node_id, safe_name(G.nodes[node_id]...))fallback at line 1360 also derefs the dangling id in its default arg, so filteringmembersup-front covers both call sites.)Net effect: notes export, then the run crashes before writing
graph.canvas, leaving a partial mirror. Deterministic on any graph where community detection emits a member id absent fromG. Could you reopen — the "fixed bothto_obsidianandto_canvas" note didn't make it into the canvas path.fix(export): guard to_canvas against dangling community members (#1236 …
safishamsi commentedon Jul 3, 2026
Good catch, @swells808 — you're right, the #1236 fix guarded
to_obsidianbut notto_canvas, soexport obsidianstill crashed writinggraph.canvas. Fixed onv8(2ba07e8): the samem in G and m in node_filenamesfilter now applies into_canvasat both loops — the box-sizing loop (so the group box matches the cards actually drawn) and the card-layout loop (so the label sort and thenode_filenamesfallback never deref a dangling id). Verified: a community with a dangling member now exportsgraph.canvascleanly with the dangling id skipped and real members present;to_obsidianunaffected. Regression test added. Ships next release.fix: obsidian crash, NFC/NFD dedup, JSON data nodes, OpenAI temperatu…
fix(export): guard to_canvas against dangling community members (Grap…