{"record":{"id":"d525da81b1a94657","repo":"Graphify-Labs/graphify","slug":"graph-file-path-is-size-d-bytes-exceeds-cap","errorCode":null,"errorMessage":"graph file {path} is {size:_d} bytes, exceeds {cap:_d}-byte cap\n(set GRAPHIFY_MAX_GRAPH_BYTES=<bytes> or GRAPHIFY_MAX_GRAPH_BYTES=<N>GB to raise the limit)","messagePattern":"graph file (.+?) is (.+?) bytes, exceeds (.+?)-byte cap\n\\(set GRAPHIFY_MAX_GRAPH_BYTES=<bytes> or GRAPHIFY_MAX_GRAPH_BYTES=<N>GB to raise the limit\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"graphify/security.py","lineNumber":379,"sourceCode":"    graph.json is read into memory and JSON-parsed. Silently returns when\n    ``path.stat()`` cannot be read — the caller's own existence/path check\n    is expected to surface a clearer error in that case.\n\n    The cap is resolved on every call via :func:`_max_graph_file_bytes`, so the\n    ``GRAPHIFY_MAX_GRAPH_BYTES`` env var can be set before import and still\n    apply.\n\n    Raises:\n        ValueError - file size exceeds the cap. The message includes the\n        observed size, the cap, and how to raise the limit.\n    \"\"\"\n    cap = _max_graph_file_bytes()\n    try:\n        size = path.stat().st_size\n    except OSError:\n        return\n    if size > cap:\n        raise ValueError(\n            f\"graph file {path} is {size:_d} bytes, exceeds {cap:_d}-byte cap\\n\"\n            f\"(set GRAPHIFY_MAX_GRAPH_BYTES=<bytes> or \"\n            f\"GRAPHIFY_MAX_GRAPH_BYTES=<N>GB to raise the limit)\"\n        )\n\n\n# ---------------------------------------------------------------------------\n# Label sanitisation (mirrors code-review-graph's _sanitize_name pattern)\n# ---------------------------------------------------------------------------\n\n_CONTROL_CHAR_RE = re.compile(r\"[\\x00-\\x1f\\x7f]\")\n_MAX_LABEL_LEN = 256\n\n\ndef sanitize_label(text: str | None) -> str:\n    \"\"\"Strip control characters and cap length.\n\n    Safe for embedding in JSON data (inside <script> tags) and plain text.","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/Graphify-Labs/graphify/blob/7fe58b0b0f3873be9a21c30106b8b8527c353aa6/graphify/security.py#L361-L397","documentation":"Raised by check_graph_file_size_cap in graphify/security.py when a graph file's on-disk size exceeds the configured cap (from GRAPHIFY_MAX_GRAPH_BYTES, parsed per call so the env var can be set any time). It fires before the file is read and JSON-parsed, protecting callers from memory-bomb graph.json files measured in GiB. stat() failures are deliberately ignored so the caller's own existence check surfaces the clearer error.","triggerScenarios":"Loading a graph.json larger than the default cap via _load_graph (graphify/serve.py) or any path that calls check_graph_file_size_cap; a huge repo producing a multi-GiB graph.json; cap lowered via env var while an old large graph remains on disk.","commonSituations":"Monorepos with enormous graphs; CI machines where GRAPHIFY_MAX_GRAPH_BYTES was set aggressively low; mixing graphs produced by different graphify versions with different serialization sizes.","solutions":["Raise the cap if you trust the file: export GRAPHIFY_MAX_GRAPH_BYTES=<bytes> (or <N>GB form) exactly as the message suggests.","Rebuild the graph with a smaller scope (subset of the repo) to shrink graph.json below the default cap.","Check the actual size (ls -l graphify-out/graph.json) to confirm the file is legitimate and not corrupted or accidentally duplicated.","Ensure machines loading the graph have enough RAM for a JSON document of that size before raising the limit."],"exampleFix":"# before\ngraph = _load_graph(\"graphify-out/graph.json\")  # ValueError: exceeds cap\n\n# after\nimport os\nos.environ[\"GRAPHIFY_MAX_GRAPH_BYTES\"] = \"2GB\"  # or e.g. \"2147483648\"\ngraph = _load_graph(\"graphify-out/graph.json\")","handlingStrategy":"validation","validationCode":"def graph_within_cap(path: Path, cap: int) -> bool:\n    try:\n        return path.stat().st_size <= cap\n    except OSError:\n        return False\n\n# mirror of the default limit resolution\ndef default_cap() -> int:\n    raw = os.environ.get(\"GRAPHIFY_MAX_GRAPH_BYTES\", \"\").strip().upper()\n    if raw.endswith(\"GB\"):\n        return int(float(raw[:-2]) * 1024**3)\n    return int(raw) if raw else 1 * 1024**3  # confirm default from docs before relying","typeGuard":"def is_loadable_graph_size(path: Path) -> bool:\n    return graph_within_cap(path, default_cap())","tryCatchPattern":"try:\n    G = _load_graph(path)\nexcept ValueError as e:\n    if \"exceeds\" in str(e) and \"cap\" in str(e):\n        size = Path(path).stat().st_size\n        if size < 2 * 1024**3 and psutil.virtual_memory().available > 4 * size:\n            os.environ[\"GRAPHIFY_MAX_GRAPH_BYTES\"] = f\"{size + 1}\"\n            G = _load_graph(path)\n        else:\n            raise\n    else:\n        raise","preventionTips":["Set GRAPHIFY_MAX_GRAPH_BYTES deliberately per environment instead of discovering the cap at load time.","Check file size before loading in scripts that consume arbitrary graphs.","Keep graph builds scoped so graph.json stays well under the cap."],"tags":["limits","graph","memory","configuration"],"backgroundTag":null,"analyzedSha":"7fe58b0b0f3873be9a21c30106b8b8527c353aa6","analyzedAt":"2026-08-14T19:23:21.323Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}