Add retry and response header options to HttpClient.withRateLimiter - #6827
Add retry and response header options to HttpClient.withRateLimiter#6827jaipaljadeja wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 6b2b895 The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
timesoption — bounds automatic 429 retries. Defaults to undefined (unlimited), 0 disables.responseHeadersoption — per-field header name overrides for rate-limit metadata inspection. Unset fields continue using built-in names.- Retry-count logic —
canRetrygate in both success and error paths, with response inspection running before the gate so the limiter learns from terminal 429s. - Tests — custom header parsing, bounded retries (success and error channels), custom Retry-After, terminal 429 feedback with
times: 0, header override isolation. - Type-level coverage — new options accepted in both data-first and data-last positions.
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
| const current = getState(key) | ||
| const canRetry = options.times === undefined || retries < options.times | ||
| function retry(retryAfter: Duration.Duration | undefined) { | ||
| if (options.disableResponseInspection) return loop(effect, request) |
There was a problem hiding this comment.
Yes, this was intentional.
retry only receives the value returned by inspectResponse. When disableResponseInspection is true, inspectResponse returns undefined, so retryAfter is always undefined.
In the previous code, this meant the expression below would take the : loop(effect, request) branch, which was the same call made by the separate check. So that check was redundant.
In the updated code, the same path now calls loop(effect, request, retries + 1) to carry the new retry count forward.

Type
Description
Adds two options to
HttpClient.withRateLimiter:timeslimits the number of automatic retries after a429response. It counts retries after the initial request, andtimes: 0disables automatic retries. Omitting it preserves the existing unlimited behavior.responseHeadersallows individual rate-limit response header names to be overridden. Fields that are not configured continue using the existing built-in names.When the retry limit is reached, the final
429is returned or failed through its original channel. Response inspection still runs before that happens, allowing the limiter to learn from the final response.Also updates the public API JSDoc and adds runtime and type-level coverage.
Validation:
pnpm lint-fixpnpm lintpnpm --filter effect test --run test/unstable/http/HttpClient.test.tspnpm test-types packages/effect/typetest/unstable/http/HttpClient.tst.tspnpm check