fix(watch): forward community_labels to to_json in _rebuild_code

`graphify update` (and the git hooks that share its code path) wrote
graph.json with numeric-only community IDs instead of readable hub
names, because `_rebuild_code` called `to_json()` without the
`community_labels` parameter that `cluster-only` already passes.
Running `cluster-only` right after `update` "fixed" the names again,
which was the visible symptom.

- watch.py: forward the already-computed `labels` dict into `to_json`,
  matching the `cluster-only` code path (cli.py:1203).
- watch.py: `_canonical_topology_for_compare` now also strips the new
  `community_name` field before diffing topology. Without this, the
  topology-unchanged cache (used to skip a full re-cluster) would
  never match again once graph.json started carrying names, forcing
  a full re-cluster on every subsequent `update` even with no code
  changes.

Fixes #1808
This commit is contained in:
Farda Karimov
2026-07-13 18:35:20 +01:00
committed by safishamsi
parent 7ca43ab314
commit 6eb5923404
+2 -1
View File
@@ -566,6 +566,7 @@ def _canonical_topology_for_compare(graph_data: dict) -> dict:
continue
n = dict(node)
n.pop("community", None)
n.pop("community_name", None)
n.pop("norm_label", None)
norm_nodes.append(n)
canonical["nodes"] = sorted(
@@ -1043,7 +1044,7 @@ def _rebuild_code(
report_path = out / "GRAPH_REPORT.md"
labels_json = json.dumps({str(k): v for k, v in sorted(labels.items())}, ensure_ascii=False, indent=2) + "\n"
graph_tmp = out / ".graph.tmp.json"
json_written = to_json(G, communities, str(graph_tmp), force=True, built_at_commit=commit)
json_written = to_json(G, communities, str(graph_tmp), force=True, built_at_commit=commit, community_labels=labels)
if not json_written:
return False
candidate_graph_data = json.loads(graph_tmp.read_text(encoding="utf-8"))