fix(proxy/ProviderClient): honour Retry-After on 429 in callProviderWithRetry#5676
Open
Chen17-sq wants to merge 1 commit into
Open
fix(proxy/ProviderClient): honour Retry-After on 429 in callProviderWithRetry#5676Chen17-sq wants to merge 1 commit into
Chen17-sq wants to merge 1 commit into
Conversation
…ithRetry Closes Helicone#5672. valhalla/jawn's ProviderClient retried 429 responses with the same exponentialDelay it uses for 5xx, never consulting the Retry-After header. With async-retry's defaults this means three retries fire well within most providers' cooldown windows, each one earning another 429. Add a small parseRetryAfter helper that accepts the RFC 7231 delta-seconds and HTTP-date forms, returns the wait in milliseconds, and caps the result at 60 s so a hostile or misconfigured provider cannot freeze the proxy for an unbounded amount of time. Past dates and malformed values return null and the caller falls back to its existing backoff. Inside the retry callback, after detecting a 429, the proxy now sleeps for the parsed Retry-After value (when present) before throwing, so async-retry's exponential backoff applies on top of the provider-mandated minimum rather than racing it. 5xx behaviour is unchanged. The worker variant at worker/src/lib/clients/ProviderClient.ts has the same retry pattern and would benefit from the same treatment in a follow-up; this PR stays narrowly scoped to the file the issue cites.
Contributor
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
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.
Closes #5672.
Summary
valhalla/jawn'scallProviderWithRetryretried 429 responses with the sameasync-retryexponentialDelayit uses for 5xx, never consulting the provider'sRetry-Afterheader. With the defaults that means three retries fire well within most providers' cooldown windows, each one earning another 429 — exactly the loop the original report calls out.This PR keeps the rest of the retry machinery untouched and adds two pieces:
parseRetryAfterA small pure helper that accepts either RFC 7231 form:
Retry-After: 30→30_000ms.Retry-After: Wed, 21 Oct 2026 07:28:00 GMT→ milliseconds remaining fromnow.It returns
nullfor missing, malformed, or already-in-the-past values so the caller can transparently fall back to the existing backoff. The result is also clamped to 60 s so a hostile or misconfigured upstream cannot freeze the proxy for an unbounded amount of time.Retry loop change
Inside the
async-retrycallback, when a 429 is received the proxy now sleeps for the parsedRetry-Aftervalue (when present) before throwing.async-retry's exponential backoff still applies on top, so the provider-mandated minimum can only ever lengthen the wait, never shorten one of the existing retries.5xx behaviour is unchanged: 5xx responses still throw immediately and rely on the exponential backoff alone.
Scope
valhalla/jawn/src/lib/proxy/ProviderClient.ts(+50 lines).valhalla/jawn/src/lib/proxy/__tests__/ProviderClient.test.tscovering the helper end-to-end (delta-seconds, HTTP-date, negative cases, the 60 s cap).worker/src/lib/clients/ProviderClient.tshas the same retry pattern and would benefit from the same treatment in a follow-up. I intentionally kept this PR narrow to the file the issue cites; happy to spin off the worker patch in a second PR if you'd prefer that shape.Tested