Skip to content

fix(sdk): retry a rate limited runCommand after its Retry-After - #519

Open
xcscxr wants to merge 1 commit into
vercel:mainfrom
xcscxr:yuuki/retry-429-waited-command
Open

xcscxr wants to merge 1 commit into
vercel:mainfrom
xcscxr:yuuki/retry-429-waited-command

Conversation

@xcscxr

@xcscxr xcscxr commented Nov 28, 2026

Copy link
Copy Markdown

Fixes #518.

Since #374, runCommand without detached sends its POST with retry: { retries: 0 }, so a network error or a 5xx can't start a command twice (#363). That also turned off retrying a 429. This sends the POST again only after a 429, on the assumption writeCommandStdin already makes for rate limited writes: the API turned the request away without starting the command.

  • Each wait is the longer of Retry-After and the backoff the stdin writes use (400 ms × 2ⁿ). A missing Retry-After doesn't mean an immediate resend, and a server that keeps answering Retry-After: 1 gets 6 requests in about 13 seconds, not 21 in 20.
  • The waits add up to at most 20 seconds, the longest withRetry waits for one Retry-After. Stdin writes cap the number of retries instead; capping the total keeps the time runCommand spends waiting before it gives up to 20 seconds. When the next wait would pass it, runCommand rejects with the 429's APIError, as before.
  • After a network error or a 5xx, on any attempt, it rejects as before without sending again, and signal ends the wait.
  • stdinBackoff and waitBeforeStdinRetry are renamed to retryBackoff and waitBeforeRetry, since commands use them too now.

Detached runCommand is unchanged. It still goes through withRetry's default retries, which #363 and #364 are about.

Tests

The new tests in api-client.test.ts, under when the command is rate limited, fail without the change:

  • sends it again after Retry-After: with Retry-After: 3, sent at 0 and 3000 ms, then the command finishes
  • with Retry-After 10, 1 and 0, sent at 0/10/20 s (the cap is inclusive), 0/1/2/3.6/6.8/13.2 s and 0/0.4/1.2/2.8/6/12.4 s, then rejects with the 429
  • does not send it again after a server error: a 429, then a 503, rejects with the 503 after two requests
  • stops waiting when the signal aborts: rejects with the abort reason after one request

pnpm vitest run in packages/vercel-sandbox: 471 passed, 83 skipped (the suites behind RUN_INTEGRATION_TESTS), with dist built for package-exports.test.ts. pnpm typecheck passes.

Since vercel#374, runCommand without detached sends its POST with retries off, so a network error or a 5xx cannot start a command twice. That also stopped a 429 from being retried, though the API turned the request away without starting the command. Send the POST again only after a 429, waiting the longer of Retry-After and the backoff, for at most 20 seconds in total.

Fixes vercel#518

Signed-off-by: Yuuki <xcscxr@gmail.com>
@vercel

vercel Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

@xcscxr is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

runCommand without detached doesn't retry a 429

1 participant