Skip to content

fix(graph): only evaluate outbound edges from completed nodes#1846

Open
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
giulio-leone:fix/graph-outbound-edge-evaluation-685
Open

fix(graph): only evaluate outbound edges from completed nodes#1846
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
giulio-leone:fix/graph-outbound-edge-evaluation-685

Conversation

@giulio-leone
Copy link
Contributor

Bug

After any node completes, the graph evaluates ALL edges in the entire graph instead of only outbound edges from the completed nodes. This causes O(all_edges) evaluation instead of O(outbound_edges) and can fire nodes whose actual dependencies haven't completed yet.

Reported in: #685

Root cause

_find_newly_ready_nodes() iterates over self.nodes.items() (ALL nodes in the graph) and checks each one against the completed batch. Nodes connected to irrelevant edges could pass the readiness check if their incoming edges happened to match the completed batch.

Fix

Replace the all-nodes iteration with a targeted lookup:

  1. Collect candidate nodes from outbound edges of the completed batch using a set comprehension
  2. Only evaluate these candidates for readiness

This changes the evaluation from O(all_nodes × incoming_edges) to O(outbound_edges × incoming_edges), and prevents false-positive readiness detection.

Testing

  • Added test_find_newly_ready_nodes_only_evaluates_outbound_edges: builds a graph with two independent chains (A→B→C, D→E), verifies completing A only readies B (not E), and completing D only readies E (not B or C)
  • All 49 graph tests pass

Fixes #685

@github-actions github-actions bot added the size/s label Mar 7, 2026
@giulio-leone giulio-leone force-pushed the fix/graph-outbound-edge-evaluation-685 branch from 884d713 to badbe04 Compare March 8, 2026 22:07
@github-actions github-actions bot added size/s and removed size/s labels Mar 8, 2026
@giulio-leone
Copy link
Contributor Author

Friendly ping — CI is green, tests pass, ready for review whenever convenient. Happy to address any feedback. Thanks! 🙏

_find_newly_ready_nodes iterated over ALL nodes in the graph after
each batch completion, checking every node for readiness. This caused
O(all_edges) evaluation instead of O(outbound_edges) and could fire
nodes whose actual dependencies had not completed.

Now collects candidate nodes from outbound edges of the completed
batch only, preventing incorrect out-of-order execution.

Fixes strands-agents#685
@giulio-leone giulio-leone force-pushed the fix/graph-outbound-edge-evaluation-685 branch from badbe04 to 3a47d90 Compare March 9, 2026 20:50
@github-actions github-actions bot removed the size/s label Mar 9, 2026
@github-actions github-actions bot added the size/s label Mar 9, 2026
@giulio-leone
Copy link
Contributor Author

Friendly ping — this branch has been refreshed on the latest upstream base and all current review feedback has been addressed. It should be ready for review whenever you have a chance. Happy to make any further changes quickly.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Graph execution evaluates all edges after any node completion instead of only outbound edges (performance + correctness issue)

1 participant