GeezerVison is showing github.com — fix(ai): fold tool changes alongside context_management compaction on Responses by rekram1-node · Pull Request #65028 · anomalyco/opencode
Conversation
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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
There was a problem hiding this comment.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|