{"record":{"id":"a5c38ef79f2174b8","repo":"Graphify-Labs/graphify","slug":"error-refused-to-shrink-graphify-out-graph-json-a5c38e","errorCode":null,"errorMessage":"ERROR: refused to shrink graphify-out/graph.json (existing graph has more nodes; #479).","messagePattern":"ERROR: refused to shrink graphify-out/graph\\.json \\(existing graph has more nodes; #479\\)\\.","errorType":"console","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"tools/skillgen/expected/graphify__skill-amp.md","lineNumber":434,"sourceCode":"    raise SystemExit(1)\ncommunities = cluster(G)\ncohesion = score_all(G, communities)\ntokens = {'input': extraction.get('input_tokens', 0), 'output': extraction.get('output_tokens', 0)}\ngods = god_nodes(G)\nsurprises = surprising_connections(G, communities)\nlabels = {cid: 'Community ' + str(cid) for cid in communities}\n# Placeholder questions - regenerated with real labels in Step 5\nquestions = suggest_questions(G, communities, labels)\n\n# Export FIRST and honor the #479 shrink-guard: to_json returns False (writing\n# nothing) when the new graph is smaller than the existing graph.json. Only write\n# GRAPH_REPORT.md + the analysis sidecar when the graph was actually written, so\n# they never describe a graph that graph.json doesn't contain (#1392).\nwrote = to_json(G, communities, 'graphify-out/graph.json')\nif not wrote:\n    print('ERROR: refused to shrink graphify-out/graph.json (existing graph has more nodes; #479).')\n    print('If this shrink is intentional (you deleted files), re-run a full build with --force.')\n    raise SystemExit(1)\nreport = generate(G, communities, cohesion, labels, gods, surprises, detection, tokens, 'INPUT_PATH', suggested_questions=questions)\nPath('graphify-out/GRAPH_REPORT.md').write_text(report, encoding=\\\"utf-8\\\")\nanalysis = {\n    'communities': {str(k): v for k, v in communities.items()},\n    'cohesion': {str(k): v for k, v in cohesion.items()},\n    'gods': gods,\n    'surprises': surprises,\n    'questions': questions,\n}\nPath('graphify-out/.graphify_analysis.json').write_text(json.dumps(analysis, indent=2, ensure_ascii=False), encoding=\\\"utf-8\\\")\nprint(f'Graph: {G.number_of_nodes()} nodes, {G.number_of_edges()} edges, {len(communities)} communities')\n\"\n```\n\nIf this step prints `ERROR: Graph is empty`, stop and tell the user what happened - do not proceed to labeling or visualization.\n\nReplace INPUT_PATH with the actual path.\n","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/Graphify-Labs/graphify/blob/7fe58b0b0f3873be9a21c30106b8b8527c353aa6/tools/skillgen/expected/graphify__skill-amp.md#L416-L452","documentation":"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.","triggerScenarios":"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/.","commonSituations":"Incremental updates after large refactors; switching INPUT_PATH without clearing outputs; extraction where a subset of files errored.","solutions":["For an intentional shrink: re-run the full build with --force (or remove graphify-out/graph.json) and re-run Step 4","For an unintentional drop: inspect .graphify_extract.json for missing files and re-run extraction","Check recent .graphifyignore edits and file deletions to explain the node-count decrease"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"from pathlib import Path\nimport json\n\ngraph_path = Path('graphify-out/graph.json')\nexisting = len(json.loads(graph_path.read_text(encoding='utf-8'))['nodes']) if graph_path.exists() else -1\nif existing >= 0 and G.number_of_nodes() < existing:\n    if not SHRINK_INTENTIONAL:\n        raise SystemExit('node count dropped — audit extraction before writing')\n    graph_path.unlink()  # intentional: allow full rebuild to persist\nwrote = to_json(G, communities, 'graphify-out/graph.json')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use --force full rebuild after intentional source-tree shrinkage","Clean graphify-out/ when switching INPUT_PATH","Investigate unexpected node drops in the extract JSON before forcing a write"],"tags":["graphify","generated-skill","shrink-guard","data-integrity","amp"],"backgroundTag":null,"analyzedSha":"7fe58b0b0f3873be9a21c30106b8b8527c353aa6","analyzedAt":"2026-08-14T19:23:21.323Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}