Skip to content

graphify label discards all LLM work: graph.json grows mid-run and the #479 shrink guard refuses the final write (no --force on this path) #2976

Open

Description

@Kevin-hDev

Summary

graphify label fails deterministically with exit code 1 on a large graph: graph.json grows by a few nodes while the command itself is running, and the final to_json write is then refused by the #479 shrink guard because the labeled graph is smaller than the file on disk. All LLM labeling work is discarded.

There is no way to override this: the label code path never passes force=True to to_json, and unlike update / extract it does not read --force or GRAPHIFY_FORCE.

Reproduced twice, with two different models. A control run of cluster-only on the same graph succeeds.

Environment

  • graphify 0.9.48 (installed with uv tool install graphifyy)
  • Python 3.12.13
  • macOS 27.0, arm64
  • Backend: claude-cli (Claude Code CLI 2.1.241)
  • Repo: ~32k nodes / ~70k edges, 1671 communities, mostly Rust (16.7k nodes) + TypeScript/TSX (5.2k nodes)

Steps to reproduce

graphify update . --force        # -> "Rebuilt: 32057 nodes, 70404 edges"
# confirmed on disk: graph.json has 32057 nodes

graphify label . --backend=claude-cli --model=claude-haiku-4-5-20251001
echo $?                          # -> 1

Actual output

[graphify] WARNING: new graph has 32057 nodes but existing graph.json has 32058
(net -1). Refusing to overwrite. Possible causes: missing chunk files from a
previous session, or fuzzy dedup collapsed same-named symbols across files
during an --update on an already-current graph. Run a full rebuild (/graphify .)
to be safe, or pass force=True only if you have verified the reduction is
legitimate.
graph.json NOT written: refusing to overwrite (see warning above).
GRAPH_REPORT.md, .graphify_labels.json and .graphify_analysis.json left untouched.
Loading existing graph...
Graph: 32057 nodes, 70404 edges
Re-clustering...
Labeling communities...
[graphify] backed up semantic+curated graph (7 files) -> 2026-08-23/

(The two stderr lines appear first because stdout is block-buffered; chronologically the refusal happens last.)

The command loaded 32057 nodes. By the time it wrote, graph.json on disk held 32058 — one more node than when the run started. After the failed run, graph.json mtime is inside the run window, and its node count is 32058.

Second occurrence (first one I hit)

Same command, --model=claude-sonnet-5, on the same repo an hour earlier:

[graphify] WARNING: new graph has 32131 nodes but existing graph.json has 32240 (net -109). Refusing to overwrite.

Same shape, larger delta. ~15 minutes of model calls discarded.

Control: cluster-only on the same graph succeeds

graphify cluster-only .
echo $?                          # -> 0
Loading existing graph...
Graph: 32058 nodes, 70406 edges
Re-clustering...
Done - 1671 communities. GRAPH_REPORT.md, graph.json and graph.html updated.

Same load, same re-clustering, same to_json. The only difference is the LLM naming path, so the graph itself and its on-disk state are not the problem.

Ruled out as external causes

No concurrent writer existed during either failing run:

  • no graphify watch or any other graphify process running (checked with pgrep during and after)
  • no graphify MCP server configured
  • no git hooks installed (.git/hooks/ contains only the shipped samples)
  • the only Claude Code hook referencing graphify just echoes a text reminder; it runs no command
  • the second run started on a graph rebuilt 30 minutes earlier, whose node count I verified myself before launching

Why there is no workaround

cli.py reads GRAPHIFY_FORCE only in the update (line ~2154) and extract (line ~2942) blocks. In the cluster-only / label block (line ~1745 onward) the only force-named variable is force_relabel = cmd == "label", which controls relabeling, not the write. The single to_json call at line ~2059 is made without force=, so it always defaults to force=False:

if not to_json(G, communities, str(out / "graph.json"),
               community_labels=labels, built_at_commit=_commit):
    ...
    sys.exit(1)

So a user whose graph hits this has no CLI-level way to land the labels.

What I could not determine

I did not find the code path that writes graph.json during the label run. The cluster-only/label block contains exactly one to_json call, and that one is the call that gets refused — so the growth comes from somewhere else in the run. I am reporting the observation rather than guessing at the mechanism.

Suggested directions

  1. Make the shrink guard compare against the graph that was loaded at the start of the run rather than re-reading graph.json at write time, so a command cannot be blocked by a file it modified itself.
  2. Failing that, honour --force / GRAPHIFY_FORCE in the cluster-only / label block, for parity with update and extract.
  3. Consider persisting .graphify_labels.json before the guarded graph.json write, or restoring it on refusal, so an expensive labeling pass is not lost when the write is rejected.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions