Skip to content

Fixes to reasoning-0 not found error - #12055

Merged
aayush-kapoor merged 6 commits into
vercel:mainfrom
jovanwongzixi:fixes
Jan 30, 2026
Merged

aayush-kapoor merged 6 commits into
vercel:mainfrom
jovanwongzixi:fixes

Conversation

@jovanwongzixi

@jovanwongzixi jovanwongzixi commented Jan 27, 2026 •

Copy link
Copy Markdown
Contributor

Background

This change is necessary due to the issue #12054, more details are included there.

Summary

I added a check to determine if reasoning-start as already been emitted. When reasoning-start has not emitted, activeExtraction.isFirstReasoning && activeExtraction.afterSwitch will be true, so I have used that as a check to determine if a reasoning-start event needs to be sent. reasoning-0 will then be created and the subsequent reasoning-end will not trigger an error.

Manual Verification

After my changes, no thinking blocks will be displayed (for OpenCode) and the error is resolved. The sample script I used for setting up a mock LLM server is located at this gist.

reasoning_part_reasoning-0_not_found_resolved

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Please advise if additional tests and documentation are needed for this change.

Future Work

My implementation assumes startWithReasoning is initialised as false. I have yet to test there are any breaking changes if startWithReasoning is `true.

Related Issues

#12054

@ghost ghost added the ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. label Jan 27, 2026
@jovanwongzixi jovanwongzixi changed the title Fixes Fixes to reasoning-0 not found error Jan 27, 2026
Comment thread packages/ai/src/middleware/extract-reasoning-middleware.ts Outdated
Removed afterSwitch to handle case when </think> happens without initial <think>. isFirstReasoning should be toggled correctly in `publish` if a valid thinking block exists

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>

@aayush-kapoor aayush-kapoor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please add unit tests to simulate the bug so that we can verify this fixes it.

also add a changeset file. look into our contributing guidelines for more info

@jovanwongzixi

Copy link
Copy Markdown
Contributor Author

I have pushed a unit test to test if reasoning-start will be emitted before reasoning-end when given empty thinking blocks in extract-reasoning-middleware-test.ts. Changeset added too. Let me know if any further changes are needed.

Comment thread .changeset/rotten-moons-bow.md Outdated
@@ -0,0 +1,5 @@
---
'ai': minor

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

for future changes, please only do a 'patch' change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it, thanks!

@aayush-kapoor aayush-kapoor linked an issue Jan 30, 2026 that may be closed by this pull request
1 task done
@aayush-kapoor
aayush-kapoor merged commit ce9daa3 into vercel:main Jan 30, 2026
17 of 18 checks passed
turnerburchard added a commit to turnerburchard/ai that referenced this pull request Mar 5, 2026
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
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. task-merge-tracking-no-issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reasoning part reasoning-0 not found due to bug in extractReasoningMiddleware

3 participants