fix(tool runner): preserve state across iterations#966
Open
jeanpierrecarvalho wants to merge 1 commit intoanthropics:mainfrom
Open
fix(tool runner): preserve state across iterations#966jeanpierrecarvalho wants to merge 1 commit intoanthropics:mainfrom
jeanpierrecarvalho wants to merge 1 commit intoanthropics:mainfrom
Conversation
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.
Fixes #964
Summary
This fixes two related
BetaToolRunneriteration-state bugs:message.container.idinto the next request when the runner receives a container-backed assistant responsesetMessagesParams()changes non-message params between iterationsRoot cause
BetaToolRunnertreated anysetMessagesParams()call as if the message history had been fully replaced.That caused two bad outcomes:
max_tokensprevented the runner from persisting the current assistant turn before generating the next requestcontainer.idwas not forwarded into the next request, which breaks pending tool-use follow-upsIn practice this could cause duplicate tool-call loops and eventually fail with:
container_id is required when there are pending tool uses generated by code execution with tools.What changed
messageswere actually replaced, instead of treating every param mutation the same waymessage.container.idinto the next request whencontainerwas not explicitly set by the callerValidation
./node_modules/.bin/jest tests/lib/tools/ToolRunner.test.ts --runInBandbeta.messages.toolRunner()run against the Anthropic API withcode_execution_20260120Before fix
Using
upstream/mainwith the same live repro:container: nullmax_tokenschangedcontainer_id is required when there are pending tool uses generated by code execution with tools.After fix
With this branch:
containerserver_tool_use, assistanttool_use, and generatedtool_resultmax_tokens) is preserved