{"record":{"id":"0b072410c5505482","repo":"Graphify-Labs/graphify","slug":"error-refused-to-shrink-graphify-out-graph-json-0b0724","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-codex.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-codex.md#L416-L452","documentation":"This is a deliberate data-integrity guard (#479) in the graphify build pipeline's Step-4 export snippet, not a library exception. graphify.export.to_json() compares the freshly built graph against the existing graphify-out/graph.json and returns False (writing nothing) when the new graph has fewer nodes. The wrapper script prints this ERROR and raises SystemExit(1) so that GRAPH_REPORT.md and .graphify_analysis.json are never written for a graph that graph.json does not actually contain (#1392).","triggerScenarios":"Calling to_json(G, communities, 'graphify-out/graph.json') after build_from_json() produced fewer nodes than the existing graph.json — typically because source files were deleted, INPUT_PATH pointed at a smaller subtree than the original build, or extraction skipped/dropped files. Only fires when graphify-out/graph.json already exists and is larger.","commonSituations":"Re-running a full build after pruning a codebase; running the build step against a subdirectory while graph.json was built from the repo root; a partial re-extract (some files skipped as binary or by ignore rules) silently shrinking the node set; stale graph.json left over from a previous larger checkout.","solutions":["If the shrink is intentional (you deleted source files), re-run the full build with --force so the shrink-guard is bypassed and graph.json is overwritten.","Verify INPUT_PATH matches the exact same root used for the original build — a smaller root relativizes fewer source files and yields fewer nodes.","Inspect graphify-out/.graphify_extract.json and compare its node count against graph.json to see which files dropped out (skipped, binary-only, or extraction failure).","If graph.json is stale garbage from an abandoned run, delete graphify-out/ entirely and rebuild from scratch."],"exampleFix":"# before: re-running build after deleting files, guard refuses\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    raise SystemExit(1)\n\n# after: intentional shrink -> force a full rebuild\n# bash: re-run the build with the force flag\n#   $(cat graphify-out/.graphify_python) build_step.py --force","handlingStrategy":"validation","validationCode":"import json\nfrom pathlib import Path\n\nnew_count = G.number_of_nodes()\nexisting = Path('graphify-out/graph.json')\nif existing.exists():\n    old_count = len(json.loads(existing.read_text(encoding='utf-8')).get('nodes', []))\n    if new_count < old_count:\n        print(f'Would shrink graph.json: {old_count} -> {new_count} nodes. Aborting before to_json.')\n        raise SystemExit(1)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always build from the same INPUT_PATH root so repeated builds cover the identical file set.","After deleting source files, immediately run a full rebuild with --force instead of an incremental one.","Treat to_json() returning False as a hard stop — never write the report or sidecar afterward.","Keep graphify-out/ out of version control so stale, larger graph.json files never leak between branches."],"tags":["graphify","data-integrity","shrink-guard","build","export"],"backgroundTag":null,"analyzedSha":"7fe58b0b0f3873be9a21c30106b8b8527c353aa6","analyzedAt":"2026-08-14T19:23:21.323Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}