fix(rewoo): prevent plan() and aplan() replay from mutating cached tool_calls#192
Open
BEASTSHRIRAM wants to merge 3 commits intomesa:mainfrom
Open
fix(rewoo): prevent plan() and aplan() replay from mutating cached tool_calls#192BEASTSHRIRAM wants to merge 3 commits intomesa:mainfrom
BEASTSHRIRAM wants to merge 3 commits intomesa:mainfrom
Conversation
for more information, see https://pre-commit.ci
Contributor
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan for PR comments
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
souro26
reviewed
Mar 12, 2026
…is not yet populated
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 a silent tool replay bug in
ReWOOReasoning.plan()andaplan()where multi-step tool call replays mutateself.current_plan.tool_callsin-place, causing the agent to silently replay incorrect tool steps on subsequent calls. The fix stores the original tool calls separately and returns a copy instead of mutating the cached plan.Bug / Issue
Fixes #184 (related to async memory issue, but exposes a broader sync/async mutation bug)
In a complex reasoning task using
ReWOOReasoning(e.g., the negotiation examplewhere an agent plans multiple steps ahead), when a plan has 3+ tool calls:
remaining_tool_calls=3,len(current_plan.tool_calls)=3, index = 3-3 = 0 ✓ Correct tool returnedcurrent_plan.tool_calls = [tool_0](now length 1)remaining_tool_calls=2,len(current_plan.tool_calls)=1, index = 1-2 = -1 ✗ Negative index wrong toolThe mutation happens because both branches of the early-return path used a mutable alias:
No error is raised. The agent silently replays the wrong tool, leading to semantic failures
in tasks requiring multi-step plans (negotiation, complex reasoning, sequential tool use).
Implementation
self._all_tool_calls = []to__init__()to store the original tool calls list separatelyself._all_tool_calls = list(rewoo_plan.llm_plan.tool_calls)index_of_tool = len(self._all_tool_calls) - self.remaining_tool_callsplan()andaplan()methods (identical early-return logic in both)Testing
All 20 ReWOO reasoning tests pass, including:
test_plan_with_remaining_tool_calls()verifies correct tool is returnedtest_aplan_with_remaining_tool_calls()async path works correctlytest_remaining_tool_calls_decrement()index calculation across multiple scenariosTests confirm that each replay returns the correct tool from the full plan without
corrupting
self.current_plan.tool_calls.Additional Notes
This is a silent correctness bug in
ReWOOReasoning, the multi-step planning strategy.Any agent using ReWOO with plans containing 2+ tool calls is affected. The failure is
invisible no exception is raised, the agent simply replays wrong tool steps, causing
task failures that are hard to debug.
No API changes. No new dependencies. The fix adds one
import copyand decouples statemanagement in two methods. Fixes both sync and async paths with identical logic.