Graphify-Labs/graphify · error · SystemExit

ERROR: refused to shrink graphify-out/graph.json (existing g

Error message

ERROR: refused to shrink graphify-out/graph.json (existing graph has more nodes; #479).

What it means

The #479 shrink-guard error in the generated AMP render of the graphify skill. The Step 4 block calls to_json(G, communities, 'graphify-out/graph.json'); when that returns False (new graph has fewer nodes than the existing graph.json), the script exits with this error before writing GRAPH_REPORT.md or .graphify_analysis.json, so sidecars never describe an unpersisted graph (#1392). The message includes the intentional-shrink escape hatch: full rebuild with --force.

Source

Thrown at tools/skillgen/expected/graphify__skill-amp.md:434

    raise SystemExit(1)
communities = cluster(G)
cohesion = score_all(G, communities)
tokens = {'input': extraction.get('input_tokens', 0), 'output': extraction.get('output_tokens', 0)}
gods = god_nodes(G)
surprises = surprising_connections(G, communities)
labels = {cid: 'Community ' + str(cid) for cid in communities}
# Placeholder questions - regenerated with real labels in Step 5
questions = suggest_questions(G, communities, labels)

# Export FIRST and honor the #479 shrink-guard: to_json returns False (writing
# nothing) when the new graph is smaller than the existing graph.json. Only write
# GRAPH_REPORT.md + the analysis sidecar when the graph was actually written, so
# they never describe a graph that graph.json doesn't contain (#1392).
wrote = to_json(G, communities, 'graphify-out/graph.json')
if not wrote:
    print('ERROR: refused to shrink graphify-out/graph.json (existing graph has more nodes; #479).')
    print('If this shrink is intentional (you deleted files), re-run a full build with --force.')
    raise SystemExit(1)
report = generate(G, communities, cohesion, labels, gods, surprises, detection, tokens, 'INPUT_PATH', suggested_questions=questions)
Path('graphify-out/GRAPH_REPORT.md').write_text(report, encoding=\"utf-8\")
analysis = {
    'communities': {str(k): v for k, v in communities.items()},
    'cohesion': {str(k): v for k, v in cohesion.items()},
    'gods': gods,
    'surprises': surprises,
    'questions': questions,
}
Path('graphify-out/.graphify_analysis.json').write_text(json.dumps(analysis, indent=2, ensure_ascii=False), encoding=\"utf-8\")
print(f'Graph: {G.number_of_nodes()} nodes, {G.number_of_edges()} edges, {len(communities)} communities')
"
```

If this step prints `ERROR: Graph is empty`, stop and tell the user what happened - do not proceed to labeling or visualization.

Replace INPUT_PATH with the actual path.

View on GitHub (pinned to 7fe58b0b0f)

Solutions

  1. For an intentional shrink: re-run the full build with --force (or remove graphify-out/graph.json) and re-run Step 4
  2. For an unintentional drop: inspect .graphify_extract.json for missing files and re-run extraction
  3. Check recent .graphifyignore edits and file deletions to explain the node-count decrease
Defensive patterns

Strategy: fallback

Validate before calling

from pathlib import Path
import json

graph_path = Path('graphify-out/graph.json')
existing = len(json.loads(graph_path.read_text(encoding='utf-8'))['nodes']) if graph_path.exists() else -1
if existing >= 0 and G.number_of_nodes() < existing:
    if not SHRINK_INTENTIONAL:
        raise SystemExit('node count dropped — audit extraction before writing')
    graph_path.unlink()  # intentional: allow full rebuild to persist
wrote = to_json(G, communities, 'graphify-out/graph.json')

Prevention

When it happens

Trigger: Running the AMP skill's Step 4 when the new extraction has fewer nodes than the existing graphify-out/graph.json — sources deleted/renamed, .graphifyignore widened, partial extraction failures, or building a smaller path over an old graphify-out/.

Common situations: Incremental updates after large refactors; switching INPUT_PATH without clearing outputs; extraction where a subset of files errored.

Related errors


AI-assisted analysis of Graphify-Labs/graphify@7fe58b0b0f (2026-08-14). Data as JSON: /api/errors/a5c38ef79f2174b8. Report an issue: GitHub.