Skip to content

fix(gateway): enable retry support for gateway errors#15213

Merged
aayush-kapoor merged 2 commits into
mainfrom
aayush/gateway-retryable
May 12, 2026
Merged

fix(gateway): enable retry support for gateway errors#15213
aayush-kapoor merged 2 commits into
mainfrom
aayush/gateway-retryable

Conversation

@aayush-kapoor
Copy link
Copy Markdown
Collaborator

Background

#14216

Gateway errors (GatewayInternalServerError, GatewayRateLimitError, GatewayTimeoutError) were never retried by maxRetries because asGatewayError() converts the original APICallError into a GatewayError subclass before the retry logic sees it. The retry function only checked APICallError.isInstance(error), which always returned false for Gateway errors

Summary

  • Add isRetryable to GatewayError base class, derived from statusCode using the same logic as APICallError (408, 409, 429, >= 500)
  • Extend _retryWithExponentialBackoff to also check GatewayError.isInstance(error) && error.isRetryable
  • For retry-after header extraction, unwrap error.cause when the error is a GatewayError with an APICallError cause

Manual Verification

na

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • 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 #14216

Co-authored-by: Pini Shvartsman 7192105+PiniShv@users.noreply.github.com

@aayush-kapoor aayush-kapoor added the backport Admins only: add this label to a pull request in order to backport it to the prior version label May 12, 2026
@aayush-kapoor aayush-kapoor enabled auto-merge (squash) May 12, 2026 18:23
@aayush-kapoor aayush-kapoor merged commit 38ca8dc into main May 12, 2026
19 checks passed
@aayush-kapoor aayush-kapoor deleted the aayush/gateway-retryable branch May 12, 2026 18:46
@aayush-kapoor aayush-kapoor added backport Admins only: add this label to a pull request in order to backport it to the prior version and removed backport Admins only: add this label to a pull request in order to backport it to the prior version labels May 12, 2026
github-actions Bot added a commit that referenced this pull request May 12, 2026
## Background

#14216 

Gateway errors (GatewayInternalServerError, GatewayRateLimitError,
GatewayTimeoutError) were never retried by `maxRetries` because
`asGatewayError()` converts the original APICallError into a
GatewayError subclass before the retry logic sees it. The retry function
only checked APICallError.isInstance(error), which always returned false
for Gateway errors

## Summary

- Add `isRetryable` to `GatewayError` base class, derived from
`statusCode` using the same logic as `APICallError` (408, 409, 429, >=
500)
- Extend `_retryWithExponentialBackoff` to also check
`GatewayError.isInstance(error) && error.isRetryable`
- For retry-after header extraction, unwrap `error.cause` when the error
is a `GatewayError` with an `APICallError` cause

## Manual Verification

na

## Checklist

- [x] All commits are signed (PRs with unsigned commits cannot be
merged)
- [x] Tests have been added / updated (for bug fixes / features)
- [ ] Documentation has been added / updated (for bug fixes / features)
- [x] A _patch_ changeset for relevant packages has been added (for bug
fixes / features - run `pnpm changeset` in the project root)
- [x] I have reviewed this pull request (self-review)

## Related Issues

fixes #14216

Co-authored-by: Pini Shvartsman
<7192105+PiniShv@users.noreply.github.com>
@github-actions github-actions Bot removed the backport Admins only: add this label to a pull request in order to backport it to the prior version label May 12, 2026
@github-actions
Copy link
Copy Markdown
Contributor

✅ Backport PR created: #15220

aayush-kapoor pushed a commit that referenced this pull request May 12, 2026
This is an automated backport of #15213 to the release-v6.0 branch. FYI
@aayush-kapoor

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

AI Gateway breaks SDK retry: GatewayInternalServerError not recognized by maxRetries

2 participants