fix(watch): rebuild the full corpus when graph.json is missing

Refs #5016.

Co-Authored-By: OpenAI Codex <noreply@openai.com>
(cherry picked from commit 4f0d5eaa1a)
This commit is contained in:
azizur100389 authored and safishamsi committed 2026-11-07 22:31:43 +00:00
1 parent 2394fd3f98
commit c66ccae853
2 files changed
+30 -2

No files matched your search

+3 -2
View File
@@ -2430,13 +2430,14 @@ def _rebuild_code(
# records the ast_hash of every file the last build extracted, so the
# change set can be read off it instead of re-extracting the whole
# corpus. `detected` was computed above for the full path anyway, so this
# costs one manifest read, not a second scan.
# costs one manifest read, not a second scan. A manifest cannot
# restore unchanged nodes when the graph it describes is missing.
#
# A manifest that is missing, unreadable or empty leaves changed_paths
# None — the full path. "No rows" means the baseline is unknown, and the
# only safe reading of unknown is "do the work"; `detect_incremental`
# makes the same call for `graphify extract` (#1925).
if incremental and changed_paths is None and not force:
if incremental and changed_paths is None and not force and (out / "graph.json").is_file():
manifest = load_manifest(str(out / "manifest.json"), root=watch_root)
if manifest:
_changed_buckets, _unchanged_buckets = classify_manifest_files(
+27
View File
@@ -0,0 +1,27 @@
"""A manifest cannot stand in for the graph an incremental update merges into."""
import json
import pytest
from graphify.watch import _rebuild_code
@pytest.mark.parametrize("change_one_source", [False, True])
def test_update_recreates_missing_graph_with_all_sources(tmp_path, change_one_source):
first = tmp_path / "first.py"
first.write_text("def first(): return 1\n", encoding="utf-8")
(tmp_path / "second.py").write_text("def second(): return 2\n", encoding="utf-8")
out = tmp_path / "graphify-out"
graph = out / "graph.json"
assert _rebuild_code(tmp_path, no_cluster=True)
assert (out / "manifest.json").is_file()
graph.unlink()
if change_one_source:
first.write_text("def renamed(): return 123\n", encoding="utf-8")
assert _rebuild_code(tmp_path, no_cluster=True, incremental=True)
labels = {node["label"] for node in json.loads(graph.read_text(encoding="utf-8"))["nodes"]}
assert "second()" in labels
assert ("renamed()" if change_one_source else "first()") in labels