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

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

_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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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