fix: propagate container.id across toolRunner iterations#994
Open
Yanhu007 wants to merge 1 commit intoanthropics:mainfrom
Open
fix: propagate container.id across toolRunner iterations#994Yanhu007 wants to merge 1 commit intoanthropics:mainfrom
Yanhu007 wants to merge 1 commit intoanthropics:mainfrom
Conversation
When using code_execution with client-side betaTools, the first API response returns a container object with an id. The toolRunner loop never forwards this container.id to subsequent requests, causing them to fail because the API cannot find the container. After receiving a response with a container.id, automatically set params.container to that id for the next iteration. This also eliminates the need for the setMessagesParams workaround, which caused an infinite tool-call loop because mutated=true skipped message history appending. Fixes anthropics#964
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 #964
When using
code_execution_20260120with client-sidebetaTools, the first API response returns acontainerobject with anid. However,BetaToolRunner's async iterator loop never forwards thiscontainer.idback intoparams.containerfor subsequent requests. This causes the second iteration to fail because the API doesn't know which container to reuse.Root Cause
In the main loop (
[Symbol.asyncIterator]), after receiving a response:Only
roleandcontentare extracted —containerfrom the response is discarded.Fix
After appending the message to history, check if the response includes a
container.idand propagate it toparams.container:Why this also fixes Bug 2 (infinite loop)
The workaround of using
setMessagesParamsto manually setcontainer.idcaused#mutated = true, which skipped themessages.push()step. This meant the assistant's response was never added to history, causinggenerateToolResponseto re-process old messages in an infinite loop.With automatic container propagation, users no longer need
setMessagesParamsfor this purpose, avoiding the infinite loop entirely.