Skip to content

fix(ai): fold tool changes alongside context_management compaction on Responses - #65028

Open
rekram1-node wants to merge 1 commit into
devfrom
responses-tool-change-fixes
Open

rekram1-node wants to merge 1 commit into
devfrom
responses-tool-change-fixes

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

On OpenAI Responses, tool changes now fold into top-level tools when automatic context_management compaction is on, instead of going in place.

A removal in place leaves the tool declared in an earlier additional_tools item and adds a developer notice saying it's gone. Automatic compaction drops developer messages but keeps the declarations, so after it runs the model sees the tool with no notice:

 additional_tools: [weather]
-developer: "These tools are no longer available. Do not call them: weather."   ← dropped by compaction
 → the model keeps calling weather, and it's refused every step

I hit this live on gpt-6-astra with compactThreshold: 9000 while testing #64381: the model looped on the removed tool until the step limit, 2 of 2 runs. Folding sends the current tool list at the top, so a removed tool simply isn't declared. It's the same rule supportsEffortUpdates already uses for context_management.

The cost: with context_management on, a tool change misses the prompt cache, which is what every tool change does today.

Verification

  • New test in test/tool-updates.test.ts: with contextManagement set, no additional_tools item is sent and top-level tools is the current set. It fails without the change.
  • Full packages/ai suite, bun typecheck and bun run check pass.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks sound. I checked it in packages/ai, since OpenCode core still folds every tool change and so can't trigger either path. Both new tests in test/tool-updates.test.ts fail on the base and pass with this change. The full packages/ai suite and tsc type-checking pass.

The final custom-tool map still decides tool_choice and how new calls are parsed. The other users of OpenAIFreeform.tools (xAI, Chat, the compaction endpoint) are not affected, because only OpenAI Responses changes tools in place. Folding when contextManagement is set follows the same rule as supportsEffortUpdates.

The public API is unchanged; everything touched is internal to packages/ai.

No concerns.

@rekram1-node
rekram1-node force-pushed the responses-tool-change-fixes branch from 2476866 to 0ef0d4d Compare November 20, 2026 01:34
@rekram1-node rekram1-node changed the title fix(ai): keep earlier tool declarations stable across tool changes on Responses fix(ai): fold tool changes alongside context_management compaction on Responses Nov 20, 2026

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The free-form part was dropped, so this is now only the context_management fold. The change looks sound. It applies the same rule supportsEffortUpdates already uses, and with compaction on, a tool change misses the prompt cache, as every tool change does today. The new test fails on the base and passes here. The full packages/ai suite and tsc type-checking pass.

The public API is unchanged; the change is internal to packages/ai.

No concerns.

This branch has not been deployed

No deployments
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.

1 participant