Skip to content

Add jitter to the rate-limit retry - #9

Merged
stefanoverna merged 1 commit into
mainfrom
add-retry-jitter
Sep 4, 2026
Merged

stefanoverna merged 1 commit into
mainfrom
add-retry-jitter

Conversation

@stefanoverna

Copy link
Copy Markdown
Member

Summary

  • A burst of concurrent calls sharing the same API token (e.g. a static site build rendering pages in parallel) hitting a 429 used to all read the same X-RateLimit-Reset and retry on the exact same tick, immediately re-triggering the same rate limit.
  • Retries now add a random extra wait on top of the required one — capped at 5s regardless of how long the base wait already is, since a few seconds of spread is enough to desynchronize concurrent retries without needlessly stretching the ~60s wait of the per-minute bucket.
  • Added .changeset for a patch release.

Test plan

  • npx vitest --run — all suites pass, including new withJitter() unit tests
  • npx biome check src — clean

https://claude.ai/code/session_01PY2yju9C9qdHdroj3zhbvc

A burst of concurrent calls hitting the same 429 (e.g. a static build
rendering pages in parallel with the same token) used to all read the same
X-RateLimit-Reset and retry on the exact same tick, immediately
re-triggering the same rate limit. Retries now add a random extra on top of
the required wait (capped at 5s, since a few seconds of spread is enough
regardless of how long the base wait already is).

Claude-Session: https://claude.ai/code/session_01PY2yju9C9qdHdroj3zhbvc
@stefanoverna
stefanoverna merged commit f0d3603 into main Sep 4, 2026
2 checks passed
@stefanoverna
stefanoverna deleted the add-retry-jitter branch September 4, 2026 09:01
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.

1 participant