Repository navigation
Description
Summary
Running graphify update . followed by graphify export wiki on a project that does not have a .graphify_analysis.json sidecar deletes every existing wiki article and writes only god-node summaries (~10 files), regardless of how many community articles previously existed.
In our project this caused a silent loss of 2,519 wiki articles when an automated pre-push hook ran the two commands in sequence. Detection happened only after the regression had already merged.
Tested on graphifyy==0.7.5 (Python package), Linux x86_64, default branch v7.
Reproduction
Starting from a project that has a populated graphify-out/ (e.g. produced by an earlier graphify extract . run with thousands of wiki articles):
# Pre-condition
ls graphify-out/wiki/*.md | wc -l # → 2519 (or any large count)
test -f graphify-out/.graphify_analysis.json && echo "sidecar present" || echo "sidecar MISSING"
# Make the sidecar 'missing' (simulating a clean checkout / a project that
# only ran `update`, never `extract`):
rm -f graphify-out/.graphify_analysis.json
# Reproduction
graphify update .
graphify export wiki
# Post-condition
ls graphify-out/wiki/*.md | wc -l # → 11 ← every community article goneSame outcome if the sidecar never existed at all (e.g. project initialized via graphify update only, without ever running the LLM-driven extract).
Root cause
Three independent design choices combine into a destructive interaction:
-
graphify update(graphify/watch.py::_rebuild_code) writesgraph.json,GRAPH_REPORT.md, and.graphify_root— but never writes.graphify_analysis.json. -
graphify cluster-only(graphify/__main__.py:1496-1551) re-clusters the graph but also never writes.graphify_analysis.json. Onlygraphify extract(__main__.py:2154-2188) writes that sidecar, andextractrequires LLM API access (expensive; not appropriate for a pre-push hook or watch loop). -
graphify export wiki(__main__.py:1800-1808) readscommunitiesfrom.graphify_analysis.jsonand silently falls back to{}if the file is absent:communities: dict[int, list[str]] = {} if analysis_path.exists(): _an = json.loads(analysis_path.read_text(encoding="utf-8")) communities = {int(k): v for k, v in _an.get("communities", {}).items()}
-
The destructive wiki-cleanup runs before the (now empty) community-iteration loop. From
graphify/wiki.py::to_wiki(lines 199-206 in 0.7.5):# Clear stale .md files from previous runs to prevent orphan accumulation. # ...to_wiki() owns wiki/ entirely (always writes the full set), # it can safely clear .md files at the start of each call. for old_article in out.glob("*.md"): old_article.unlink()
The cleanup is correct iff to_wiki() actually writes the full set. With an empty communities dict the loop produces no community articles — only the god-node summaries. The cleanup-then-write pattern collapses the entire wiki/ directory.
Impact
- Silent data loss. No warning, no non-zero exit code. The post-export wiki/ looks superficially valid (a few .md files exist), so automation cannot detect the regression by checking for empty output.
- Unsafe in CI / pre-push / watch automation. Any workflow that pairs
update(orcluster-only) withexport wikiwill produce this regression on every run after a clean checkout. - Encourages workarounds. Downstream projects either pin themselves to running the expensive
extracton every push (LLM cost), or build out-of-tree helpers to fill the gap.
In our case (a private monorepo) we caught this only post-merge, when the affected PR shipped 2,519 file deletions to main. We've since:
- Restored the wiki/ directory from a pre-regression commit.
- Built a local helper that imports
graphify.cluster+graphify.analyzefrom the installed package and recomputes the sidecar without LLM calls (Louvain clustering is deterministic), then injects the sidecar betweenupdateandexport wiki. - Added a "wiki article count drop > 50%" safety guard in our pre-push hook to abort + roll back if any future regression in this class slips through.
These fixes work, but the underlying contract should be repaired upstream so other graphify users don't hit the same trap.
Suggested fix (one of)
Pick the option that fits the project's design intent best:
-
Make
updatederive the sidecar. After writinggraph.json, if.graphify_analysis.jsonis absent or older thangraph.json, recompute communities/cohesion/gods/surprises locally (no LLM) and write the sidecar — mirroring the analysis-write block at__main__.py:2154-2176. This keepsupdateas the single command users run between extract baselines. -
Make
export wikifail fast when the sidecar is missing. Replace the silentif analysis_path.exists()fallback with an explicit error (non-zero exit +"refusing to export wiki: .graphify_analysis.json missing or empty; rungraphify extract .orgraphify recluster .first"). At minimum this prevents data loss; users opt back in to the destructive cleanup only when the precondition is met. -
Make
to_wiki()'s cleanup safe when the community set is empty. Skip thefor old_article in out.glob("*.md"): old_article.unlink()step whencommunitiesis empty (or below a heuristic threshold). The cleanup invariant in the comment ("to_wiki()owns wiki/ entirely (always writes the full set)") is only true when the full set is non-empty.
Option 1 is preferred — it closes the semantic gap rather than just papering over the symptom, and is consistent with how downstream consumers expect update to refresh derived artifacts.
Environment
graphifyy==0.7.5(installed viauv tool install graphifyy)- Python 3.13.0 (graphifyy venv interpreter)
- Linux x86_64
- Default repo branch: v7
Happy to test a fix against the same reproducer if it helps.
Activity
fix cluster-only label persistence, wiki data-loss guard, ollama erro…
safishamsi commentedon May 6, 2026
Fixed in v0.7.8: two-layer guard added. (1)
graphify export wikinow fails fast with exit 1 and a clear error message if .graphify_analysis.json is missing. (2)to_wiki()raises ValueError before the cleanup loop when communities is empty — wiki/ is never wiped without a full community set.fix cluster-only label persistence, wiki data-loss guard, ollama erro…