Skip to content

fix: propagate container.id across toolRunner iterations#994

Open
Yanhu007 wants to merge 1 commit intoanthropics:mainfrom
Yanhu007:fix/tool-runner-container-propagation
Open

fix: propagate container.id across toolRunner iterations#994
Yanhu007 wants to merge 1 commit intoanthropics:mainfrom
Yanhu007:fix/tool-runner-container-propagation

Conversation

@Yanhu007
Copy link
Copy Markdown

Summary

Fixes #964

When using code_execution_20260120 with client-side betaTools, the first API response returns a container object with an id. However, BetaToolRunner's async iterator loop never forwards this container.id back into params.container for 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:

const { role, content } = await this.#message;
this.#state.params.messages.push({ role, content });

Only role and content are extracted — container from the response is discarded.

Fix

After appending the message to history, check if the response includes a container.id and propagate it to params.container:

const message = await this.#message;
const { role, content } = message;
this.#state.params.messages.push({ role, content });

if (message.container?.id && this.#state.params.container !== message.container.id) {
  this.#state.params.container = message.container.id;
}

Why this also fixes Bug 2 (infinite loop)

The workaround of using setMessagesParams to manually set container.id caused #mutated = true, which skipped the messages.push() step. This meant the assistant's response was never added to history, causing generateToolResponse to re-process old messages in an infinite loop.

With automatic container propagation, users no longer need setMessagesParams for this purpose, avoiding the infinite loop entirely.

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
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