Skip to content

graph_stats cannot tell an agent how stale its graph is: built_at_commit is dropped by _load_graph, and no build timestamp is recorded at all #3354

Closed

Description

@winesoft-namjin-yun

graph_stats is the only tool that answers "what am I querying?", and it cannot answer "how old is it?". An agent working over MCP has no other way to find out: it can read the graph but it cannot stat graph.json, so it will answer questions about today's code from a graph built last month exactly as confidently as from one built ten minutes ago.

Reproduced on 0.9.54 (v8 @ 937e59a, stock, no local modifications).

Reproduction

Build a graph inside a git repo and ask the MCP server for its stats:

G = nx.DiGraph()
G.add_node("a_foo", label="foo", type="function")
G.add_node("a_py", label="a.py", type="file")
G.add_edge("a_py", "a_foo", type="contains", confidence="EXTRACTED")
export.to_json(G, {0: ["a_foo", "a_py"]}, str(repo / "graphify-out" / "graph.json"))

graph.json records where the graph came from:

graph.json top-level keys: ['built_at_commit', 'directed', 'graph', 'hyperedges', 'multigraph']
built_at_commit in file  : d787419075b674426a0cb3017c2416d4950232c2
git HEAD                 : d787419075b674426a0cb3017c2416d4950232c2

Load it the way the MCP server does, and the provenance is gone:

G.graph after _load_graph : {'_logical_directed': True, '_learning_overlay': {}}

So graph_stats over MCP answers:

Nodes: 2
Edges: 1
Communities: 1
EXTRACTED: 100%
INFERRED: 0%
AMBIGUOUS: 0%

Nothing in that output — or in any other MCP tool — says which revision the graph describes, or when it was written.

Root cause

Two separate gaps, one per field.

1. The commit is written but dropped on load. export.to_json writes it at the top level:

  • graphify/export.py:407 — data["built_at_commit"] = commit

networkx.readwrite.json_graph.node_link_graph copies only data["graph"] onto G.graph and silently discards every other top-level key, so serve.py never sees it:

  • graphify/serve.py:64 — G = json_graph.node_link_graph(data, edges="links")
  • graphify/serve.py:67 — G.graph["_logical_directed"] = _logical_directed — the one top-level value that is rescued, stashed by hand one line after the load, exactly because of this

The data reaches every other consumer that reads the raw JSON — graphify/callflow_html.py:299, graphify/cli.py:2278, graphify/report.py:172 all use built_at_commit. Only the MCP surface, which loads through node_link_graph, loses it. grep -n built_at_commit graphify/serve.py returns nothing on 0.9.54.

2. There is no build timestamp at all. built_at_commit answers which revision, not when written, and the two diverge in exactly the case that matters: a graph built from a commit that is now three weeks behind still reports that commit, and a --no-cluster rewrite (graphify/cli.py:2278) deliberately carries the old commit forward onto a newly written file. A consumer that cannot stat the file has nothing to fall back on.

Expected

Nodes: 2
Edges: 1
Communities: 1
EXTRACTED: 100%
INFERRED: 0%
AMBIGUOUS: 0%
Built at: 2026-08-25T09:15:42Z
Built from commit: d6ff04064219c45e6cb1aeda8e66c292b6650307

Appended, never prepended, and omitted line-by-line when absent, so a graph written by an older version renders byte-identically to what it renders today.

Notes on a fix

Three constraints worth stating up front, since each one is a way to get this wrong:

I have a patch against 0.9.54 and will open it alongside this issue.

Activity

  1. winesoft-namjin-yun commented on Oct 6, 2026

    @winesoft-namjin-yun
    ContributorAuthor

    Status update, so this is easy to pick up:

    Leaving this open since the underlying gap is unchanged.

  2. added a commit that references this issue on Oct 7, 2026
    748de12
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