Skip to content

fix(ai): handle missing reasoning-start in streamText eventProcessor - #13110

Open
turnerburchard wants to merge 4 commits into
vercel:mainfrom
turnerburchard:fix/reasoning-part-not-found-eventprocessor
Open

turnerburchard wants to merge 4 commits into
vercel:mainfrom
turnerburchard:fix/reasoning-part-not-found-eventprocessor

Conversation

@turnerburchard

Copy link
Copy Markdown

Summary

When a provider emits reasoning-delta or reasoning-end stream events without a preceding reasoning-start, the eventProcessor in streamText now auto-creates the reasoning entry instead of emitting an error event that terminates the stream.

This is the same class of bug fixed in #12055 for extractReasoningMiddleware, but in the eventProcessor TransformStream inside streamText.

Context

We hit this with OpenAI's Responses API (reasoningSummary: 'auto') — on a trivial input, the API intermittently sent reasoning-delta events without a preceding reasoning-start, producing repeated errors:

reasoning part rs_<id>:0 not found

Changes

  • stream-text.ts: When reasoning-delta or reasoning-end arrives without an active reasoning entry, auto-create one (matching the approach from Fixes to reasoning-0 not found error #12055) instead of emitting an error
  • stream-text.test.ts: Two new test cases covering both scenarios

Test plan

  • New tests pass
  • Existing reasoning tests still pass

Relates to #12054

When a provider emits reasoning-delta or reasoning-end events without
a preceding reasoning-start (e.g. OpenAI Responses API with empty or
malformed reasoning blocks), the eventProcessor now auto-creates the
reasoning entry instead of emitting an error that terminates the stream.

This is the same class of bug fixed in vercel#12055 for
extractReasoningMiddleware, but in a different code path.

Fixes vercel#12054
@tigent tigent Bot added ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. bug Something isn't working as documented provider/openai Issues related to the @ai-sdk/openai provider labels Mar 5, 2026
@bbartels

Copy link
Copy Markdown

Running into this with opus 4.7 and amazon bedrock
@gr2m @aayush-kapoor any chance this could be looked at? :)

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

ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. bug Something isn't working as documented provider/openai Issues related to the @ai-sdk/openai provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants