fix(graph): prevent reset_executor_state from corrupting MultiAgentBase state#1896
Open
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
Open
fix(graph): prevent reset_executor_state from corrupting MultiAgentBase state#1896giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
Conversation
…se state GraphNode.reset_executor_state() checked hasattr(self.executor, 'state') but did not verify the state type before overwriting it with AgentState. When the executor is a MultiAgentBase (e.g. a nested Graph), its state is a GraphState, and overwriting it with AgentState corrupts the executor. The __post_init__ method already had the correct guard: hasattr(self.executor.state, 'get') but reset_executor_state() was missing it. This affected two call sites: - _execute_node (when reset_on_revisit is enabled with nested graphs) - deserialize_state (unconditionally resets all nodes on completed runs) Fixes strands-agents#1775
71beee9 to
3537416
Compare
Contributor
Author
|
Friendly ping — prevents |
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.
Summary
Fixes #1775 —
GraphNode.reset_executor_state()corruptsMultiAgentBaseexecutor state by overwritingGraphStatewithAgentState.Root Cause
reset_executor_state()checkshasattr(self.executor, 'state')without verifying the state type:__post_init__already had the correct guard (hasattr(self.executor.state, 'get')), butreset_executor_state()was missing it.Impact
Two call sites affected:
_execute_nodereset_on_revisit=Truewith nested graph in a cycledeserialize_stateFix
Mirror the
__post_init__guard:Test
Added
test_reset_executor_state_preserves_graph_state_for_nested_graph— creates aGraphNodewith a nestedGraphexecutor and verifiesreset_executor_state()preserves theGraphStatetype.All 49 graph tests pass.