Skip to content

perf: find executable graph nodes with one reverse traversal - #38

Closed
liuzhengyang699 wants to merge 1 commit into
metauto-ai:mainfrom
liuzhengyang699:perf/output-ancestor-traversal
Closed

liuzhengyang699 wants to merge 1 commit into
metauto-ai:mainfrom
liuzhengyang699:perf/output-ancestor-traversal

Conversation

@liuzhengyang699

Copy link
Copy Markdown

Before running a graph, Graph.run searches forward from every node to see whether it can reach an output. Shared dead branches are revisited along every path, and a sufficiently long valid chain raises RecursionError before any agent executes.

Walk backward from the output nodes with a visited set instead. Reachability now takes O(V + E) work, avoids recursion, and gives constant-time membership checks during scheduling. The execution queue still follows graph insertion order, and nodes that cannot contribute to an output remain excluded.

Validation: python -m pytest test/swarm/graph/test_output_reachability.py -q — 4 passed, all marked mock_llm. The tests cover shared ancestors with multiple outputs, a chain longer than the recursion limit, repeated dead diamond branches, and no outputs. The long-chain and bounded-visit cases fail on upstream. git diff --check passed. No model calls or end-to-end quality benchmark.

@liuzhengyang699 liuzhengyang699 closed this by deleting the head repository Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant