Repository navigation
Description
Summary
graphify update (incremental mode) calls build_merge() without passing directed=, which defaults to False. Since the merged graph is then written back with to_json(..., force=True), a graph built with --directed becomes undirected after any routine refresh, and nothing in stdout or the report says so.
The saved directed flag round-trips correctly everywhere else — cluster-only inherits it (cli.py:1681, build_from_json(_raw, directed=_directed)), and #801 already went to the trouble of preserving per-edge source/target through the merge. It's specifically the graph type that is dropped.
Verified against v1.0.0 (current default branch) and reproduced on 0.8.27.
Why it matters
Betweenness centrality is only meaningful on a directed graph. Undirected, a leaf utility that everything imports becomes a fake bridge: every pair of its importers appears two hops apart "through" it, though no control flow passes through it at all.
On a real 4,607-node / 10,760-edge polyglot graph, a logging helper with in_degree=176, out_degree=0 — a pure sink — ranked as the #1 god node at 0.090 betweenness. Rebuilt directed, it scores exactly 0.0000, along with three other high-degree sinks that had been occupying most of the top five. The genuine bridges were invisible until those four dropped out.
So the failure mode isn't "the graph looks a bit different" — it's that ## God Nodes and the betweenness-derived ## Suggested Questions both silently start reporting ubiquity instead of architecture, and there is no signal that the graph changed type.
Reproduction
Minimal, no corpus required:
import json
from pathlib import Path
from graphify.build import build_from_json, build_merge
from graphify.cluster import cluster
from graphify.export import to_json
Path('graphify-out').mkdir(exist_ok=True)
extraction = {
'nodes': [
{'id': 'a_caller', 'label': 'caller()', 'file_type': 'code', 'source_file': 'a.py'},
{'id': 'a_callee', 'label': 'callee()', 'file_type': 'code', 'source_file': 'a.py'},
{'id': 'a_leaf', 'label': 'leaf()', 'file_type': 'code', 'source_file': 'a.py'},
],
'edges': [
{'source': 'a_caller', 'target': 'a_callee', 'relation': 'calls',
'confidence': 'EXTRACTED', 'confidence_score': 1.0, 'source_file': 'a.py'},
{'source': 'a_callee', 'target': 'a_leaf', 'relation': 'calls',
'confidence': 'EXTRACTED', 'confidence_score': 1.0, 'source_file': 'a.py'},
],
'hyperedges': [],
}
G = build_from_json(extraction, directed=True)
to_json(G, cluster(G), 'graphify-out/graph.json')
print('saved directed:', json.loads(Path('graphify-out/graph.json').read_text())['directed'])
# what `graphify update` does
G2 = build_merge([{'nodes': [], 'edges': [], 'hyperedges': []}],
graph_path='graphify-out/graph.json', prune_sources=None)
to_json(G2, cluster(G2), 'graphify-out/graph.json', force=True)
print('after update :', json.loads(Path('graphify-out/graph.json').read_text())['directed'])saved directed: True
after update : False
Passing directed=True to that same build_merge call returns is_directed()=True, confirming the plumbing works and only the default is at fault.
Location
graphify/cli.py:3547 (v1.0.0) — directed= is absent:
G = _build_merge(
[merged],
graph_path=existing_graph_path,
prune_sources=_prune_sources or None,
dedup=True,
dedup_llm_backend=dedup_backend,
root=target,
)graphify/build.py — def build_merge(..., *, directed: bool = False, ...).
Same path is reached by graphify hook install (post-commit) and graphify --watch, so on a directed graph those revert it on every commit / file change.
Suggested fix
The robust version is to make build_merge inherit by default, since it already reads graph_path and so is the only place that knows the answer:
def build_merge(..., *, directed: bool | None = None, ...):
# directed=None -> inherit from the existing graph; explicit True/False still wins.
if directed is None:
directed = bool(data.get("directed", False)) if graph_path.exists() else FalseThat fixes every caller at once and makes "an existing directed graph stays directed" the default everywhere, which seems like the least surprising behaviour.
The minimal alternative is to thread it at the call site in cli.py, reading the flag off existing_graph_path before the merge.
Either way it would help to print the resolved mode ([graphify update] directed=True) so a future downgrade is visible in the log rather than silent.
Related
- build_merge / --update drops existing graph's hyperedges from unchanged files (only nodes+edges are read from graph.json) #1574 —
build_merge/--updatedrops the existing graph's hyperedges. Same shape: graph-level state lost on merge while nodes/edges survive. - skill.md --update inline merge bypasses fixed build_merge() — direction-inversion bug from #760 still hits Claude Code skill workflow #801 — preserved per-edge direction through
build_merge; this is the remaining half (the graph type itself). - merge-graphs: unhandled NetworkXError on mixed directed/multigraph inputs, and exit code 0 on crash #1606 —
merge-graphson mixed directed/undirected inputs.
Activity
Rishet11 commentedon Jul 31, 2026
Reproduced. The keyword default is the whole bug, and
build_mergenever asks the loaded graph what it was.build_merge(..., *, directed: bool = False, ...)(graphify/build.py:1263) takes direction from the caller only, andbuild.py:1327rebuilds with that stale default (G = build(all_chunks, directed=directed, ...)) no matter what the on-disk graph said:One detail that corrects the report slightly:
build_mergeitself did not rewrite the flag in my run (the file still saiddirected: trueafterwards), so the downgrade lands when the caller serializes the returned graph, not insidebuild_merge. That matters for the fix — the returned object is what has to be right.cli.py:3547is the only call site in the tree (grepped; there is no second copy of the merge logic), and it passes nodirected=, so everygraphify updatethat goes through the merge path inheritsFalse.No existing test pins the
Falsedefault: the calls intests/test_build_merge_hyperedges_and_prune.pynever pass or assertdirected, andtest_build_merge_preserves_call_edge_direction(tests/test_build.py:501) only checks edge tuple order.Plan: make the parameter
directed: bool | None = Noneand, when it isNone, honor thedirectedflag already parsed out of the existinggraph.json, falling back to the currentFalsewhen there is no existing graph (that fresh-graph branch is the part I will test hardest — getting it wrong would flip behavior for brand-new graphs). Claiming this; PR againstv8.fix(watch): inherit the directed flag on the graphify update rebuild …
fix(build): inherit the on-disk directed flag in build_merge (#2342)
fix(watch): inherit the directed flag on the graphify update rebuild …
chore: bump to 0.9.32; changelog for #2333/#2334/#2336/#2342/#2326/#2323
safishamsi commentedon Aug 1, 2026
Fixed in v0.9.32.
graphify updatenow inherits the on-diskdirectedflag on both the clustered and--no-clusterrebuild paths, so God-node and path ranking keep their direction. Thanks for the report.Merge upstream/v8 (0.9.38) into feat/clusters
fix(build): inherit the on-disk directed flag in build_merge (Graphif…
fix(watch): inherit the directed flag on the graphify update rebuild …
chore: bump to 0.9.32; changelog for Graphify-Labs#2333/Graphify-Labs…
fix(drupal): P3's deferred overlay minors