Skip to content

fix(ai): throw timeout error when streamText times out#11595

Merged
lgrammel merged 7 commits intovercel:mainfrom
shubham-021:fix/streamText-timeout-error
Jan 7, 2026
Merged

fix(ai): throw timeout error when streamText times out#11595
lgrammel merged 7 commits intovercel:mainfrom
shubham-021:fix/streamText-timeout-error

Conversation

@shubham-021
Copy link
Contributor

@shubham-021 shubham-021 commented Jan 7, 2026

Background

When streamText times out before generating any output, it throws a generic NoOutputGeneratedError with the message "No output generated. Check the stream for errors.". It should throw NoOutputGeneratedError with a proper timeout message and cause.

Summary

When abort occurs, the abort reason is used as error. It can be an AbortError or a TimeoutError (or a custom reason object).

Manual Verification

  • run examples/ai-core/src/stream-text/openai-timeout.ts and verify output

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)

Related Issues

fixes #11577

@vercel-ai-sdk vercel-ai-sdk bot added ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. bug Something isn't working as documented labels Jan 7, 2026
@lgrammel
Copy link
Collaborator

lgrammel commented Jan 7, 2026

Thanks! The behavior should match generateText:

 pnpm tsx src/generate-text/openai-timeout
DOMException [TimeoutError]: The operation was aborted due to timeout

You can verify by running

~/repositories/ai/examples/ai-core main *46 ··································· 11:08:57
 pnpm tsx src/stream-text/openai-timeout

@lgrammel lgrammel changed the title fix: throw timeout error when streamText times out fix(ai): throw timeout error when streamText times out Jan 7, 2026
@shubham-021
Copy link
Contributor Author

Thanks! The behavior should match generateText:

 pnpm tsx src/generate-text/openai-timeout
DOMException [TimeoutError]: The operation was aborted due to timeout

You can verify by running

~/repositories/ai/examples/ai-core main *46 ··································· 11:08:57
 pnpm tsx src/stream-text/openai-timeout

I think this well aligned now

pnpm tsx src/stream-text/openai-timeout
DOMException [TimeoutError]: The operation was aborted due to timeout

Comment on lines +10116 to +10117
// Simulate a model response that takes longer than the timeout
await new Promise(r => setTimeout(r, 100));
Copy link
Collaborator

Choose a reason for hiding this comment

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

using timeouts in tests is not recommended. it slows down test exection.

can this be solved with fake timers (vi faketimers)?

Copy link
Contributor Author

@shubham-021 shubham-021 Jan 7, 2026

Choose a reason for hiding this comment

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

i tried using faketimer , but it is not simulating the blocker perfectly , giving test timeout.
Can you help me here , what i initially thought was we can plant a promise inside doStream method which doesnt resolve and then advance the timer with more than timeout time , but that gives a test timeout.

@lgrammel lgrammel merged commit af0955e into vercel:main Jan 7, 2026
17 of 18 checks passed
@shubham-021 shubham-021 deleted the fix/streamText-timeout-error branch January 8, 2026 08:48
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

streamText should throw timeout when timeout occurs (throws NoOutputGeneratedError)

2 participants