Skip to content

Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.

fix(merge): flag batch files that load but contribute zero nodes and edges

Lum1104afa1d51cb7e1
diff --git a/tests/skill/understand/test_merge_batch_graphs.py b/tests/skill/understand/test_merge_batch_graphs.py
index 0c3f5ecd..15bf5e30 100644
--- a/tests/skill/understand/test_merge_batch_graphs.py
+++ b/tests/skill/understand/test_merge_batch_graphs.py
@@ -1245,5 +1245,52 @@ class TestUnrecognizedBatchFilename(unittest.TestCase):
self.assertNotIn("file:src/y.ts", node_ids)
+class TestEmptyBatchGuard(unittest.TestCase):
+ """A batch file that parses but contributes 0 nodes + 0 edges is how a
+ silent partial merge looks from the outside (#484) — it must be flagged
+ loudly on stderr AND in the phase report, without failing the merge.
+ """
+
+ def setUp(self) -> None:
+ import tempfile
+ self.tmp = Path(tempfile.mkdtemp(prefix="ua-mbg-empty-"))
+ self.intermediate = self.tmp / ".understand-anything" / "intermediate"
+ self.intermediate.mkdir(parents=True, exist_ok=True)
+
+ def tearDown(self) -> None:
+ import shutil
+ shutil.rmtree(self.tmp, ignore_errors=True)
+
+ def _write_batch(self, name: str, nodes: list, edges: list) -> None:
+ import json as _j
+ (self.intermediate / name).write_text(
+ _j.dumps({"nodes": nodes, "edges": edges}),
+ encoding="utf-8",
+ )
+
+ def _run_merge(self) -> tuple[int, str]:
+ import subprocess
+ result = subprocess.run(
+ [sys.executable, str(_MODULE_PATH), str(self.tmp)],
+ capture_output=True, text=True,
+ )
+ return result.returncode, result.stderr
+
+ def test_empty_batch_warns_but_does_not_fail(self) -> None:
+ self._write_batch("batch-1.json", [_file_node("src/a.ts")], [])
+ self._write_batch("batch-2.json", [], [])
+ rc, stderr = self._run_merge()
+ self.assertEqual(rc, 0)
+ self.assertIn("batch-2.json loaded but contributed 0 nodes and 0 edges", stderr)
+ # Re-emitted in the phase report section, not just the load log
+ self.assertIn("loaded but contributed no nodes or edges", stderr)
+
+ def test_no_warning_when_all_batches_contribute(self) -> None:
+ self._write_batch("batch-1.json", [_file_node("src/a.ts")], [])
+ rc, stderr = self._run_merge()
+ self.assertEqual(rc, 0)
+ self.assertNotIn("contributed 0 nodes and 0 edges", stderr)
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/understand-anything-plugin/skills/understand/merge-batch-graphs.py b/understand-anything-plugin/skills/understand/merge-batch-graphs.py
index 9f99fdd3..84807cff 100644
--- a/understand-anything-plugin/skills/understand/merge-batch-graphs.py
+++ b/understand-anything-plugin/skills/understand/merge-batch-graphs.py
@@ -1108,6 +1108,7 @@ def main() -> None:
# merged graph with content the agent labeled incorrectly.
unrecognized_set = set(unrecognized_batch_files)
batches: list[dict[str, Any]] = []
+ empty_batch_warnings: list[str] = []
for f in batch_files:
if f.name in unrecognized_set:
continue
@@ -1117,6 +1118,17 @@ def main() -> None:
n = len(batch.get("nodes", []))
e = len(batch.get("edges", []))
print(f" {f.name}: {n} nodes, {e} edges", file=sys.stderr)
+ # A file that parses but contributes nothing is how a silent
+ # partial merge looks from the outside (see #484) — flag it
+ # loudly instead of relying on a downstream reviewer to notice.
+ if n == 0 and e == 0:
+ msg = (
+ f"{f.name} loaded but contributed 0 nodes and 0 edges — "
+ f"either the analyzer wrote an empty batch or the file "
+ f"was read mid-write; inspect it directly"
+ )
+ print(f" Warning: {msg}", file=sys.stderr)
+ empty_batch_warnings.append(msg)
if not batches:
print("Error: no valid batch files loaded", file=sys.stderr)
@@ -1139,6 +1151,17 @@ def main() -> None:
for w in missing_part_warnings:
report.append(f" - {w}")
+ # Surface empty-contribution batches to the phase report (same rationale
+ # as missing_part_warnings above — stderr alone gets buried).
+ if empty_batch_warnings:
+ report.append("")
+ report.append(
+ f"Warning: {len(empty_batch_warnings)} batch file(s) loaded but "
+ f"contributed no nodes or edges:"
+ )
+ for w in empty_batch_warnings:
+ report.append(f" - {w}")
+
# Surface unrecognized-filename drops to the phase report so the
# downstream review step sees them, not just stderr.
if unrecognized_batch_files: