Skip to content

benchmark crashes: KeyError 'links' on networkx 3.x (graph.json uses 'edges' key) #1198

Closed

Description

@atlas-architect

Summary

graphify benchmark crashes with KeyError: 'links' against a graph produced by graphify extract --no-cluster.

Environment

  • graphifyy 0.8.35 (installed via uv tool install graphifyy)
  • networkx 3.6.1
  • Windows, Python 3.13

Repro

graphify extract <code-dir> --out <out-dir> --no-cluster
cd <out-dir>
graphify benchmark

Traceback

File ".../graphify/benchmark.py", line 105, in run_benchmark
    G = json_graph.node_link_graph(data, edges="links")
...
File ".../networkx/readwrite/json_graph/node_link.py", line 247, in node_link_graph
    for d in data[edges]:
KeyError: 'links'

Root cause

The graph.json written by extract stores edges under the edges key, not links:

keys: ['nodes', 'edges', 'hyperedges', 'input_tokens', 'output_tokens']

But benchmark.py calls json_graph.node_link_graph(data, edges="links") with the literal old key. On networkx ≥3.x the hardcoded "links" no longer matches what extract emits, so data["links"] raises KeyError.

Suggested fix

Pass edges="edges" to match the extract output (or detect the present key):

G = json_graph.node_link_graph(data, edges="edges")

Notes

  • Reproduced on a --no-cluster raw extraction; haven't checked clustered output, which may differ.
  • Otherwise the tool is great — extract on a code-only corpus is fast and fully offline (a 47-file TS app → 247 nodes/470 edges in ~2.3s, zero API calls). Just wanted the benchmark token-reduction numbers and hit this. Thanks!

Activity

  1. atlas-architect commented on Jun 8, 2026

    @atlas-architect
    Author

    Update: this bug is wider than benchmark — the same node_link_graph(data, edges="links") vs the edges-keyed graph.json also breaks affected (and any command going through that load path). On networkx 3.6.1, graphify affected "<node>" fails with:

    error: could not load graph: 'links'
    

    Root cause: the writer emits "edges" (build.py reads the JSON directly — see the comment at build.py:384), but the readers call node_link_graph(..., edges="links") → KeyError: 'links', which the surrounding except TypeError: (the old-networkx missing-kwarg guard) doesn't catch.

    Same pattern at ~9 call-sites:

    • affected.py:152, benchmark.py:105, callflow_html.py:231, global_graph.py:37 + :91, multigraph_compat.py:115, serve.py:33, and __main__.py (lines 2702 / 2840 / 2930 / 3405 / 3463 / 3653).

    Fix is one token at each site — edges="links" → edges="edges" (match the writer's key). Verified locally on networkx 3.6.1: patching affected.py + benchmark.py made both commands work correctly — affected returns the full reverse-dependency cone, and benchmark reports its token-reduction metric (2.6× on a real Next.js/TS repo). query/explain/path already work because they read the JSON directly rather than via node_link_graph. Happy to send a PR if that's useful.

  2. safishamsi commented on Jun 8, 2026

    @safishamsi
    Member

    Not a bug — the claim has the keys inverted. graph.json stores edges under "links" (written by export.py:512 via node_link_data(G, edges="links")), and benchmark.py:105 correctly reads edges="links". Verified on networkx 3.6.1: all 16 benchmark tests pass. Applying the suggested fix (edges="edges") would introduce the crash, not fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions