fix: propagate container.id across toolRunner iterations#1073
Open
Sarmkadan wants to merge 1 commit into
Open
Conversation
When using code_execution with client-side tools (betaTool), the API returns a container object with an id that must be forwarded in subsequent requests. The toolRunner did not carry this forward, causing "container_id is required" errors on the next iteration. After awaiting each response, extract container.id and set it on the request params for the next API call. This happens before the #mutated check so it works regardless of whether the user called setMessagesParams during the iteration. Apply the same fix to both BetaToolRunner and the legacy ToolRunner. 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 —
toolRunnerdoes not propagatecontainer.idacross iterations, causing a hard error when usingcode_executionwith client-sidebetaTools.Root cause
When the API returns a response with a
containerobject (created bycode_execution), thecontainer.idmust be included in subsequent requests so the API can reuse the same container. NeitherBetaToolRunnernor the legacyToolRunnerextracted this value from the response, so the next iteration sent a request withoutcontainer, triggering:{"type":"invalid_request_error","message":"container_id is required when there are pending tool uses generated by code execution with tools."}The only workaround (
setMessagesParams) also didn't work correctly — settingcontainervia the mutator triggered the#mutatedflag, which prevented the assistant message from being pushed to the conversation history, causing an infinite loop (Bug 2 in the issue).Fix
After awaiting each response, extract
container.idand set it onthis.#state.params.containerbefore the#mutatedcheck. This ensures:setMessagesParamssetMessagesParamsworkaroundApplied to both
BetaToolRunnerand the legacyToolRunner.Test plan
forwards container.id from response to next request— non-streaming mode, verifies second request body containscontainerforwards container.id in streaming mode— same verification via SSE streaming