Graphify-Labs/graphify · error · RuntimeError

cannot stat {p}: {exc}

Error message

cannot stat {p}: {exc}

What it means

Shrink-guard in the devin fragment's export step (tools/skillgen/fragments/core/devin.md:493). to_json(G, communities, 'graphify-out/graph.json') refuses to overwrite an existing graph.json that has more nodes, returns False, and the script exits 1 with the older 'Run a full rebuild to be safe' wording (no --force flag mentioned). GRAPH_REPORT.md and the analysis sidecar are only written after a successful persist (#1392).

Source

Thrown at graphify/cli.py:2244

        # Usage: graphify merge-driver %O %A %B  (set in .git/config merge driver)
        if len(sys.argv) < 5:
            print("Usage: graphify merge-driver <base> <current> <other>", file=sys.stderr)
            sys.exit(1)
        _base_path, _current_path, _other_path = sys.argv[2], sys.argv[3], sys.argv[4]
        # Hard caps so a malicious or corrupted graph.json cannot exhaust memory
        # at parse time. 50 MB / 100k nodes are well above any realistic graph
        # (typical graphs are <5 MB / <50k nodes); anything larger should fail
        # the merge so a human can investigate.
        _MERGE_MAX_BYTES = 50 * 1024 * 1024
        _MERGE_MAX_NODES = 100_000
        import networkx as _nx
        from networkx.readwrite import json_graph as _jg
        def _load_graph(p: str):
            path_obj = Path(p)
            try:
                size = path_obj.stat().st_size
            except OSError as exc:
                raise RuntimeError(f"cannot stat {p}: {exc}") from exc
            if size > _MERGE_MAX_BYTES:
                raise RuntimeError(
                    f"graph.json {p} is {size} bytes, exceeds {_MERGE_MAX_BYTES}-byte cap"
                )
            data = json.loads(path_obj.read_text(encoding="utf-8"))
            # A committed raw (--no-cluster) graph stores edges under "edges";
            # parse via the shared links/edges-normalizing loader (#2212).
            from graphify.paths import load_node_link_graph as _lnlg
            return _lnlg(data), data
        try:
            G_cur, _ = _load_graph(_current_path)
            G_oth, _ = _load_graph(_other_path)
        except Exception as exc:
            print(f"[graphify merge-driver] error loading graphs: {exc}", file=sys.stderr)
            sys.exit(1)  # surface the conflict so git doesn't accept a corrupt merge
        merged = _nx.compose(G_cur, G_oth)
        if merged.number_of_nodes() > _MERGE_MAX_NODES:
            print(

View on GitHub (pinned to 7fe58b0b0f)

Solutions

  1. Do a full rebuild as instructed — with the modern CLI, a full build with --force — so graph.json reflects the current corpus.
  2. If the shrink is unexpected, compare existing vs new node counts and inspect extract/detect sidecars for skipped files.
  3. Remove stale graphify-out/graph.json before rebuilding when the output dir is inherited.
  4. Keep INPUT_PATH stable between full builds and incremental updates to keep node sets comparable.

Example fix

# before
/graphify update .
# ERROR: refused to shrink ... fewer nodes ...

# after
/graphify build --force .
Defensive patterns

Strategy: validation

Validate before calling

import json
from pathlib import Path

old_n = len(json.loads(Path('graphify-out/graph.json').read_text(encoding='utf-8')).get('nodes', []))
new_n = len(json.loads(Path('graphify-out/.graphify_extract.json').read_text(encoding='utf-8')).get('nodes') or [])
if new_n < old_n:
    print(f'shrink {old_n}->{new_n}: full rebuild (--force) required before export')

Prevention

When it happens

Trigger: A rebuild/update yielded fewer nodes than the existing graphify-out/graph.json: files deleted from the corpus, files skipped in re-extraction, or a stale larger graph.json from a previous run on a bigger tree.

Common situations: graphify update after pruning or branch switch; partial extraction due to parse failures; leftover graph.json from a different repository; running the pipeline twice against different paths.

Related errors


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