fix(graph): prevent reset_executor_state from corrupting MultiAgentBase state#1786
Closed
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
Closed
Conversation
…se state GraphNode.reset_executor_state() checked hasattr(self.executor, 'state') without distinguishing executor type. For MultiAgentBase executors (e.g. nested Graph), this overwrote GraphState with AgentState, breaking the executor. Add the same hasattr(self.executor.state, 'get') guard that __post_init__ already uses, so only AgentState-based executors are reset. Fixes strands-agents#1775 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Author
|
Closing — focusing on higher-impact contributions. |
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.
Problem
GraphNode.reset_executor_state()corrupts the executor state when the executor is aMultiAgentBase(e.g. a nestedGraph).The method checks
hasattr(self.executor, "state")without distinguishing executor type, then unconditionally assignsAgentState(...). ForMultiAgentBaseexecutors whose.stateis aGraphState, this overwrites it with the wrong type — breaking the nested executor.Two call sites are affected:
_execute_node: guarded byreset_on_revisit(triggers when revisiting a nested graph node in a cycle)deserialize_state: unguarded (triggers when restoring a completed run with nonext_nodes_to_execute)Root Cause
__post_init__already has the correct guard:But
reset_executor_state()was missing thehasattr(self.executor.state, "get")check:GraphStatedoesn't have a.get()method, so the guard correctly skips it.Fix
Add the same
hasattr(self.executor.state, "get")guard toreset_executor_state(), matching the existing pattern in__post_init__.Test
Added
test_reset_executor_state_preserves_multiagent_graph_state— verifies that aGraphNodewrapping aMultiAgentBasewithGraphStatepreserves the state type afterreset_executor_state().Fixes #1775