Repository navigation
fix(ai): degrade unsupported hosted tool history on provider switches - #57256
rekram1-node wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
The fix works. I ran the #57044 reproduction script in packages/core and a protocol-level Anthropic reproduction for #53633 on both checkouts. On the base, OpenAI Chat fails to compile the foreign hosted-tool history and Anthropic rejects unknown server-tool names. With this PR both compile, and the hosted call and result become readable text with no dangling client tool call. All packages/ai tests pass and bun run typecheck is clean.
Public API is unchanged: hostedToolHistory is only added to the internal ProviderShared helpers, and stored sessions and schemas are untouched.
One minor inline note about how the fallback text reads on OpenAI Chat-style protocols. Otherwise the approach looks sound: the fallback lives in protocol lowering, both halves of the pair are degraded by id, and Anthropic keeps its native blocks only when it can actually replay them.
There was a problem hiding this comment.
OpenAI Chat (and other protocols that join assistant text parts with "") runs these fallback parts together with the text around them. With the #57044 repro the assistant content becomes Provider tool web_search called with: {"query":"Effect"}Provider tool web_search returned:\nFound itDone. Ending each fallback text part with a newline (or wrapping it in blank lines) would keep the history readable for the model.

Problem
Switching providers after a provider-executed tool can make the session impossible to continue: the destination rejects inline tool results, or Anthropic rejects an unfamiliar server-tool name.
Fixes #57044. Fixes #53633.
Change
Normalize unsupported hosted history during protocol lowering, without changing stored sessions or public schemas.
Out of scope
OpenAI Responses hosted items being stored as JSON text rather than replayed as native items. No tool enabling or schema cleanup is included.
Verification
devwith the new regression cases.packages/ai:bun test --timeout 30000— 1,852 pass, 28 skip, 0 fail.bun test test/hosted-history.test.ts --rerun-each 10— 290 pass. Covers seven destination protocols, errors, mixed local tools, images, supported Anthropic native blocks and incompatible same-name search results.bun run checkpasses.