Repository navigation
feat(google-genai): retry transient chat requests before the response starts - #243
Draft
erzaehlsalex wants to merge 3 commits into
Draft
erzaehlsalex wants to merge 3 commits into
erzaehlsalex wants to merge 3 commits into
Conversation
Walks the cause chain (including AggregateError.errors) for undici and socket failure codes, so provider wrappers can classify network failures that carry no HTTP status as transient. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Node fetch failure such as a headers timeout or socket reset reached callers as a generic ProviderError, so it could not be told apart from a rejected request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… starts The OpenAI and Anthropic SDKs retry failed requests twice by default; the Google SDK only does so when retryOptions is set, and its built-in retry delays aborts and loses the error status. Retry rate limits, overload, 5xx and network failures here instead, up to maxRetries (default 2), honouring Retry-After up to 20 s. generateContentStream resolves on the response headers, so stream errors are never retried. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Google GenAI and Vertex chat models now retry transient request failures before the response starts. Network failures without an HTTP status are now classified as
ServiceUnavailableError.@core-ai/core-ai: newisTransportError(). It walks thecausechain, includingAggregateError.errors, for socket and Node fetch codes:UND_ERR_SOCKET,UND_ERR_HEADERS_TIMEOUT,UND_ERR_BODY_TIMEOUT,UND_ERR_CONNECT_TIMEOUT,ECONNRESET,ETIMEDOUTandEPIPE.@core-ai/google-genai:wrapGoogleErrormaps transport failures toServiceUnavailableError, right after the abort check. Before this they became a genericProviderError.generateContentandgenerateContentStreamgo through a newwithRequestRetry.RetryableProviderErrors (rate limit, overload, 5xx, transport) up tomaxRetriestimes, with a default of 2.Retry-Afterwhen that is at most 20 s. A longerRetry-Afterfails fast.AbortedError.maxRetriesprovider option;0disables retries. It also applies to a suppliedclient.@core-ai/google-vertex: passesmaxRetriesthrough.Only the call that opens the request is retried. The SDK resolves
generateContentStreamonce response headers arrive, so errors raised while consuming a stream are never retried and output can't be duplicated. The existing in-band stream error test now also asserts a single call.Why
@google/genaionly retries whenhttpOptions.retryOptionsis set, and core-ai never sets it.RESOURCE_EXHAUSTED, 3 ×UND_ERR_HEADERS_TIMEOUTand 1 × socket reset.retryOptions(p-retry 4.6.2):DOMExceptionAbortError, with 1 s and 2 s backoff, so cancelling lags about 3 s.Error('Retryable HTTP Error: …')instead of the response. The status is lost, andwrapGoogleErrorcan no longer produceRateLimitError.Tests
isTransportError: own code, nested cause,AggregateError, unrelated errors, cyclic causes.wrapGoogleError:TypeError('fetch failed')with anUND_ERR_HEADERS_TIMEOUTcause →ServiceUnavailableError.withRequestRetry:Retry-AftermaxRetries: 0maxRetriespassthrough and the default retry.npm run testpasses for@core-ai/core-ai,@core-ai/google-genaiand@core-ai/google-vertex.npm run release:check(build, lint, check-types) passes.npm run test:e2e:google-vertex) did not run, because no Vertex credentials are configured locally.Not in this PR (follow-ups)
mapStreamErrorspasses everyTypeErrorthrough as a language error. undici reports mid-stream socket and body timeouts asTypeError: terminated, so those still reach callers unmapped, for all providers.wrap*Errorhelpers could useisTransportErroras well.🤖 Generated with Claude Code