Skip to content

fix: propagate container.id across toolRunner iterations#1073

Open
Sarmkadan wants to merge 1 commit into
anthropics:mainfrom
Sarmkadan:fix/tool-runner-container-propagation
Open

fix: propagate container.id across toolRunner iterations#1073
Sarmkadan wants to merge 1 commit into
anthropics:mainfrom
Sarmkadan:fix/tool-runner-container-propagation

Conversation

@Sarmkadan
Copy link
Copy Markdown

Summary

Fixes #964toolRunner does not propagate container.id across iterations, causing a hard error when using code_execution with client-side betaTools.

Root cause

When the API returns a response with a container object (created by code_execution), the container.id must be included in subsequent requests so the API can reuse the same container. Neither BetaToolRunner nor the legacy ToolRunner extracted this value from the response, so the next iteration sent a request without container, 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 — setting container via the mutator triggered the #mutated flag, 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.id and set it on this.#state.params.container before the #mutated check. This ensures:

  1. The container is propagated regardless of whether the user called setMessagesParams
  2. Users no longer need the broken setMessagesParams workaround
  3. The fix is minimal — 4 lines of logic in each runner

Applied to both BetaToolRunner and the legacy ToolRunner.

Test plan

  • forwards container.id from response to next request — non-streaming mode, verifies second request body contains container
  • forwards container.id in streaming mode — same verification via SSE streaming
  • All 30 existing ToolRunner tests pass

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
@Sarmkadan Sarmkadan requested a review from a team as a code owner May 28, 2026 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: toolRunner does not propagate container.id across iterations, and setMessagesParams causes duplicate tool call loops

1 participant