cluster-only prints "graph.json updated" when to_json refused to write
What happens
graphify cluster-only <path> on a large existing graph computed a clustering, declined to persist it, and then reported success:
[graphify] WARNING: new graph has 794784 nodes but existing graph.json has 794903 (net -119).
Refusing to overwrite. Possible causes: missing chunk files from a previous session, or
fuzzy dedup collapsed same-named symbols across files during an --update on an already-current
graph. Run a full rebuild (/graphify .) to be safe, or pass force=True only if you have
verified the reduction is legitimate.
Loading existing graph...
Graph: 794784 nodes, 1766987 edges
Re-clustering...
Done - 27088 communities. GRAPH_REPORT.md and graph.json updated.
Exit code 0. graph.json was not written — its mtime was unchanged and only 1.1% of nodes carried a community. The guard did its job; the final line contradicts it.
.graphify_labels.json, its .sig, and GRAPH_REPORT.md were written, for the clustering that was discarded. So a successful-looking run leaves labels and report describing a clustering the graph does not contain. Anything downstream keyed to community ids is then silently wrong.
We only caught it because our runbook says to verify community coverage after clustering rather than trust the exit code — that habit exists because this cost us a full clustering run once before.
Suggested fix
Either is enough, both would be better:
- When
to_jsonreturns falsy, say so and exit non-zero —graph.json NOT written: refusing to overwrite (net -119 nodes)— rather than printinggraph.json updated. - Don't persist labels,
.sigorGRAPH_REPORT.mdwhen the graph write was declined, so the outputs stay consistent with each other.
Second, separate finding: the -119 is unexplained
The guard's own explanation does not fit our case, and we could not account for the reduction:
| Check | Result |
|---|---|
Duplicate node ids in graph.json |
0 (794,903 nodes, 794,903 distinct, all str) |
networkx.node_link_graph(raw, edges="links") |
794,903 nodes, 1,768,522 edges — no loss |
graphify.paths.load_node_link_graph |
same call, so also lossless |
prune_dangling_edges |
removes edges only, never nodes |
| graphify's own report after "Loading existing graph..." | 794,784 nodes, 1,766,987 edges |
So 119 nodes and 1,535 edges disappear between reading the file and reaching the writer, inside graphify, on a graph that plain networkx round-trips intact. We did not use force=True, because "verify the reduction is legitimate" is not something we could honestly claim.
Workaround, in case it helps anyone else: load the graph yourself and drive the public API — load_node_link_graph, cluster, remap_communities_to_previous, label_communities_by_hub, then to_json(G, communities, path, community_labels=labels). The node count reaching the writer then equals the count on disk, the guard has nothing to fire on, and the output keeps graphify's exact format (community, community_name, norm_label). That produced 100% community coverage on all 794,903 nodes.
Also worth noting for anyone using cluster-only to refresh an existing store: it clusters from scratch with no reference to previous membership. Ours renamed 22,507 of 28,004 communities by hub. Community ids are what authored per-cluster content is keyed to, so that is a total loss of that content unless you pass the old membership through remap_communities_to_previous yourself. Driving the API with that step gave us 88% retention on the same change.
Versions: graphify 0.9.30, networkx 3.6.1, Python 3.13, macOS.
A related, smaller ask from the same workflow: GRAPH_REPORT.md's headline totals can only be regenerated by re-running clustering, so on a store whose graph is enriched after graphify runs (extra node layers added by downstream tooling), the report's summary block goes stale and the only cure re-clusters — which invalidates downstream artefacts keyed to community ids.
A graphify report-only <path> (or cluster-only --reuse-communities) that regenerates the report from the existing graph.json's communities, without re-detecting them, would let the audit stay truthful without paying the re-cluster. The community data is already in the file; only the totals and tables need recomputing.
This looks fixed on the v8 branch by 6ba08682 (fix(cli): surface four silent success-exit failures (#2534)). Could a maintainer confirm and close?