fix(graph): only evaluate outbound edges from completed nodes#1846
Open
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
Open
fix(graph): only evaluate outbound edges from completed nodes#1846giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
Conversation
_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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ofO(outbound_edges)and can fire nodes whose actual dependencies haven't completed yet.Reported in: #685
Root cause
_find_newly_ready_nodes()iterates overself.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:
This changes the evaluation from
O(all_nodes × incoming_edges)toO(outbound_edges × incoming_edges), and prevents false-positive readiness detection.Testing
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)Fixes #685