backup_if_protected snapshots GRAPH_REPORT.md after cluster-only/label overwrite it, so the previous report is unrecoverable — and graph.html is outside the backup set
Version: graphify 0.9.22 · macOS
Summary
backup_if_protected (added in #834, to "protect semantic and curated graphs from silent overwrite via dated-folder backup") is called in cluster-only / label after GRAPH_REPORT.md has already been overwritten. The dated backup folder therefore contains the new report, and the previous one is unrecoverable.
The other artifacts are handled correctly — the write happens after the backup call:
cli.py:1657 (out / "GRAPH_REPORT.md").write_text(report, ...) # overwrite
cli.py:1660 _backup(out) # "backup"
cli.py:1668 (out / ".graphify_analysis.json").write_text(...) # after backup ✓
cli.py:1672 to_json(G, communities, str(out / "graph.json"), ...) # after backup ✓
cli.py:1675 _wja(labels_path, ...) # after backup ✓
cli.py:1679 (labels_path.parent / (name + ".sig")).write_text(...) # after backup ✓
So GRAPH_REPORT.md is the one artifact in _BACKUP_ARTIFACTS whose snapshot is taken post-write.
Why it matters: the report is the cheapest before/after diff available — community count, labels, hubs. The moment you most want the previous copy is right after a re-cluster, which is exactly when labels churn (#2298, #1653). We wanted to diff the pre-run report against the post-run one and found the dated folder already held the new version.
Fix: move _backup(out) above line 1657.
Same area: graph.html is outside the backup set, and --no-viz deletes it
_BACKUP_ARTIFACTS (export.py:24-32) is:
["graph.json", "GRAPH_REPORT.md", ".graphify_labels.json",
".graphify_analysis.json", "manifest.json", ".graphify_semantic_marker", "cost.json"]
graph.html is not in it. And cluster-only --no-viz unlinks the existing one (cli.py:1685-1688):
html_target = out / "graph.html"
...
html_target.unlink()
The comment there explains the intent — avoid leaving a stale graph.html from an interrupted run — which is reasonable, but the effect is that cluster-only --no-viz destroys the previous visualization with no copy anywhere. On a large graph that HTML is expensive to regenerate.
We hit this on a repair run: we used --no-viz deliberately (to run export html separately afterwards) and the previous graph.html was simply gone in between. It survived only because the next command regenerated it.
Either adding graph.html to _BACKUP_ARTIFACTS, or deferring the unlink until a replacement exists, would close it.