Skip to content

feat(javascript): wait and retry on 429 with Retry-After - #6965

Merged
MarioAlexandruDan merged 14 commits into
mainfrom
cursor/api-545-429-retry-after-a30b
Sep 3, 2026
Merged

MarioAlexandruDan merged 14 commits into
mainfrom
cursor/api-545-429-retry-after-a30b

Conversation

@MarioAlexandruDan

@MarioAlexandruDan MarioAlexandruDan commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

🧭 What and Why

🎟 JIRA Ticket: API-545

HTTP 429 is not a host-failover case. JavaScript now waits on the same host and retries: Retry-After as a positive whole number of seconds, waited in full per the spec (no client-side max wait), otherwise 1s; maxRateLimitRetries defaults to 3 (0 fails on the first 429). 5xx / timeout / network retries are unchanged. Other languages skip the new CTS until sibling tickets.

Changes included:

  • Hand-written JS transporter (client-common) intercepts 429 before the 4xx-not-retryable path, waits with setTimeout, and re-queues the same host
  • requestStream waits and retries on 429 using StreamRequestError (Retry-After from node-http and fetch requesters)
  • Shared CTS mock on ports 6697 / 6698 plus createClient plumbing for maxRateLimitRetries; the retry-after route replies with a 2s wait so the CTS can tell header parsing apart from the 1s fallback
  • JS-only CTS via onlyLanguages: ["javascript"] (not a denylist of current languages)
  • JSDoc on maxRateLimitRetries and a retry-strategy note pointing at the JavaScript transporter

Deferred: docs-new customize page (other repo), live e2e (no staging rate limit)

πŸ§ͺ Test

  • yarn test in clients/algoliasearch-client-javascript/packages/client-common β€” 20 files, 152 tests
  • Requester tests: node-http 17 passed, fetch 14 passed
  • CI=1 yarn cli cts generate javascript
  • CI=1 yarn cli cts run javascript --no-e2e β€” 27 files, 1123 tests

Honor Retry-After as a positive whole number of seconds (otherwise 1s),
keep the host up, and cap retries with maxRateLimitRetries (default 3).
Shared mock on 6697/6698, createClient plumbing for maxRateLimitRetries,
and JS-only CTS covering Retry-After, missing header, exhausted retries,
fail-fast, and HTML 429 with retries disabled.
Register rateLimit.test.ts on the node project and attach the exhausted
retry rejection handler before fake timers fire.
Prove fake-timer waits before the second request, retry requestStream on
429 with Retry-After, generate JS-only CTS via onlyLanguages, and point the
retry-strategy docs at the JavaScript transporter.
@MarioAlexandruDan MarioAlexandruDan self-assigned this Sep 1, 2026
@MarioAlexandruDan
MarioAlexandruDan requested a review from a team as a code owner September 1, 2026 13:35
@algolia-api-clients-automation-bot

algolia-api-clients-automation-bot Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

πŸ’₯ Breaking changes detected !!

Either this PR or a previous PR not released yet introduced breaking changes, be careful when merging.
You can find the details in the 'client java@21' CI job.

No code generated

If you believe code should've been generated, please, report the issue.

πŸ“Š Benchmark results

Benchmarks performed on the method using a mock server, the results might not reflect the real-world performance.

Language Req/s
javascript 2157
go 1843
python 1713
php 1568
csharp 1410
scala 1100
java 1007
ruby 900
swift 499

@aikido-pr-checks

aikido-pr-checks Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Summary by Aikido

Security Issues: 0 Quality Issues: 0 Resolved Issues: 0

πŸš€ New Features

  • Added same-host HTTP 429 waiting and retrying with configurable limits
  • Added JavaScript CTS rate-limit scenarios, mocks, and validation

⚑ Enhancements

  • Supported Retry-After parsing and fallback delays across regular requests
  • Extended streaming requests to retry rate limits with response headers
  • Updated JavaScript tests and bundle budgets for retry functionality

πŸ”§ Refactors

  • Centralized fetch response-header conversion and introduced stream request errors

More info

@MarioAlexandruDan
MarioAlexandruDan marked this pull request as draft September 1, 2026 13:38
The algoliasearch common client snapshot compared the full transporter
object and failed in CI after 429 retries started exposing the default.
Shared transporter 429 wait/retry grew gzip UMD sizes enough to fail
bundlewatch. Raise maxSize for the affected packages.
@github-actions

github-actions Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Log wait duration and retries left on the same-host 429 path, record
triesLeft after re-queuing the host, and retry requestStream only around
sendStream so mid-stream errors cannot replay events.
@MarioAlexandruDan
MarioAlexandruDan marked this pull request as ready for review September 2, 2026 10:39
A misbehaving intermediary answering 429 with a huge Retry-After could
park requests in setTimeout for hours; cap the honored wait at 60s so
other languages copy a bounded reference implementation.
… wait

The retry-after mock used to reply Retry-After: 1, the same 1s a client
that ignores the header entirely would wait; reply with 2s and assert the
delay per route so sibling-language ports must actually parse the header.
Also drop the dead javascript entry from the now-skipped HTML error test.
…not in the run

Only the mock-was-hit floor stays gated on JavaScript; any language that
hit the mock gets its call counts and delays asserted, so sibling ports
cannot silently skip validation.
The send and sendStream paths built the same header record inline; use a
single toResponseHeaders helper, mirroring the node-http requester.
Reverts 3b32dbf. The API-545 spec explicitly rules out a client max
wait: the server sends the full rate-limit window, and truncating a
longer Retry-After would retry inside the same window, collect another
429, and burn the remaining budget. Waits are honored in full again and
the reference doc no longer advertises a cap to the upcoming ports.

@eric-zaharia eric-zaharia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@MarioAlexandruDan
MarioAlexandruDan merged commit 86409a3 into main Sep 3, 2026
38 checks passed
@MarioAlexandruDan
MarioAlexandruDan deleted the cursor/api-545-429-retry-after-a30b branch September 3, 2026 07:44
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-javascript that referenced this pull request Sep 3, 2026
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.

2 participants