Skip to content

feat(ai): allow removing providerOptions in pruneMessages - #19997

Open
wasim-builds wants to merge 2 commits into
vercel:mainfrom
wasim-builds:fix/11036-prunemessages-provideroptions
Open

feat(ai): allow removing providerOptions in pruneMessages#19997
wasim-builds wants to merge 2 commits into
vercel:mainfrom
wasim-builds:fix/11036-prunemessages-provideroptions

Conversation

@wasim-builds

Copy link
Copy Markdown
Contributor

Description

Fixes #11036

When pruneMessages drops reasoning or tool calls from a message, the remaining parts may still carry providerOptions (which OpenAI uses for validation signatures). OpenAI sees the signatures, looks for the pruned reasoning parts, and rejects the request because they are missing.

This PR adds an optional providerOptions?: 'keep' | 'remove' flag to pruneMessages (defaulting to 'keep'). When set to 'remove', it recursively strips providerOptions from messages and their content parts. This tricks the provider into treating them as brand-new messages without strictly checking signatures for pruned parts.

Testing

  • Added unit tests for removing providerOptions
  • Verified tests pass locally
  • Verified types

Fixes vercel#11036

When `pruneMessages` drops reasoning or tool calls from a message, the remaining parts may still carry `providerOptions` (like OpenAI signatures). OpenAI sees the signatures, looks for the pruned reasoning parts, and rejects the request because they are missing.

This PR adds an optional `providerOptions?: 'keep' | 'remove'` flag to `pruneMessages`. When set to `'remove'`, it recursively strips `providerOptions` from messages and their content parts. This tricks the provider into treating them as brand-new messages without strictly checking signatures for pruned parts.
Copilot AI lite review requested due to automatic review settings August 29, 2026 19:27

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pruneMessages doesn't work well with OpenAI reasoning models

2 participants