Repository navigation
Description
Summary
graphify query returns the relevant nodes but can omit real edges between them. This occurs when both endpoints are selected as seed nodes, and more generally for cross-edges between nodes that have already been visited.
Tested against Graphify 0.9.30 and the current v8 branch at ecfcd16.
Minimal reproduction
# app.py
from pricing import discounted_total
def checkout(subtotal: float, discount_rate: float) -> float:
return discounted_total(subtotal, discount_rate)# pricing.py
def discounted_total(subtotal: float, discount_rate: float) -> float:
return subtotal * (1 - discount_rate)graphify extract . --code-only
graphify query "How does checkout calculate the final total?"graphify-out/graph.json correctly contains a checkout() --calls--> discounted_total() edge. Both functions are selected as query seeds and both nodes appear in the output, but the calls edge is missing.
Root cause
_bfs() and _dfs() in graphify/serve.py append an edge to edges_seen only when that edge discovers an unvisited neighbor:
if neighbor not in visited:
next_frontier.add(neighbor)
edges_seen.append((n, neighbor))Because all seed nodes are marked visited before traversal begins, an edge between two seeds is never recorded. The same behavior omits non-tree/cross-edges between other already-visited nodes. The rendered result is therefore a traversal tree rather than the induced subgraph described by the returned node set.
Expected behavior
Every graph edge whose endpoints are both in the visited node set should be eligible for rendering, while preserving traversal-edge order and avoiding duplicates.
With that behavior, the reproduction includes:
EDGE checkout() --calls [EXTRACTED context=call]--> discounted_total() at=app.py:L5
Proposed fix
After BFS/DFS determines the visited node set, retain the traversal edges and append missing edges from G.edges() whose endpoints are both visited. Deduplicate using ordered endpoint pairs for directed graphs and unordered endpoint pairs for undirected graphs.
Validated locally with regression coverage for:
- an edge directly between two seed nodes;
- a cross-edge in a triangle where all three nodes are visited;
- the original CLI reproduction.
Relevant upstream tests passed:
tests/test_serve.py + tests/test_query_cli.py
133 passed
Disclosure
This report was prepared with OpenAI Codex at the user's request after reproducing the issue on a synthetic fixture. No private repository data is included.
Activity
Rishet11 commentedon Jul 31, 2026
Picking this up — thanks for the precise root cause and the repro.
Confirmed the mechanism in
v8@4fe1109:_bfssetsvisited = set(start_nodes)(serve.py:833) before the loop, so theif neighbor not in visitedguard at :844 can never record a seed-to-seed edge._dfsmarks on pop (:868) and drops cross-edges the same way.Planned approach, following your suggestion with two additions:
_bfs/_dfsrather than at the call site, so the completion pass is structurally bound totraversal_graph(serve.py:1054-1055) and cannot resurrect edges that_filter_graph_by_contextdeliberately removed;G.edges(), so cost scales with the subgraph rather than the whole graph;G.is_directed()and unordered otherwise, sinceu->vandv->uare genuinely distinct on a DiGraph (mutual recursion, circular imports).Note the MCP
query_graphtool (serve.py:1449) shares this traversal, so its output gains edges too. I'll cover that path with a test.Will open a PR against
v8with before/after CLI output on your repro.chore: bump to 0.9.32; changelog for #2333/#2334/#2336/#2342/#2326/#2323
fix(query): render every edge between visited nodes, not just travers…
fix(query): render every edge between visited nodes, not just travers…
chore: bump to 0.9.32; changelog for Graphify-Labs#2333/Graphify-Labs…