Skip to content

fix(vercel-ai-sdk): don't retry provider errors the AI SDK marks as not retryable - #466

Merged
moetemp merged 4 commits into
mainfrom
fix/vercel-ai-sdk-non-retryable-errors
Nov 12, 2026
Merged

moetemp merged 4 commits into
mainfrom
fix/vercel-ai-sdk-non-retryable-errors

Conversation

@moetemp

@moetemp moetemp commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What changed?

This PR stops Temporal from retrying provider errors that the AI SDK marks as not retryable.

  • An APICallError with isRetryable: false (a 400 or a 401, for example) now fails the three model Activities with a non-retryable ApplicationFailure. The original error is the cause.
  • The same rule applies to an APICallError in a streamed error part.
  • The message for an error part uses getErrorMessage, so an object doesn't print as [object Object].
  • The failure types don't change. A thrown provider error keeps APICallError, and a streamed error part keeps Error.

Fixes #AI-948

Why?

A bad API key or a malformed request fails the same way on every attempt. With the default retry policy, the Activity retried it forever.

I used isRetryable because the AI SDK's own maxRetries logic uses it too.

A user who relied on retries for a 401, during a key rotation for example, now gets a failed Workflow on the first attempt. Recorded histories replay the same.

How did you test it?

  • Unit tests. A 401 gets one attempt and fails the Workflow. A 503 is still retried.
  • make lint and make test pass in typescript/vercel-ai-sdk.
  • Not run against a real provider. All tests use in-process fake providers.

@brianstrauch brianstrauch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One retry-policy compatibility issue with retryable streamed errors.

@brianstrauch brianstrauch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One remaining provider error-type compatibility issue.

A 400 or 401 from the provider fails the same way on every attempt, and the default retry policy never stops.
A retry policy with Error in nonRetryableErrorTypes stopped these failures before, and a new type would make it retry them.
A handler that matches the type of a failed model call must continue to match. Only the retry verdict changes.
@moetemp
moetemp force-pushed the fix/vercel-ai-sdk-non-retryable-errors branch from b5e2271 to 45edc38 Compare November 12, 2026 07:27
@moetemp
moetemp requested a review from brianstrauch November 12, 2026 07:31
@moetemp
moetemp merged commit 7a3fecb into main Nov 12, 2026
27 checks passed
@moetemp
moetemp deleted the fix/vercel-ai-sdk-non-retryable-errors branch November 12, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants