Skip to content

[CB-0] [sdk-superfan] Let the signal interrupt the retry wait - #245

Draft
spicysouvlaki wants to merge 1 commit into
mainfrom
wschmitt/abort-retry-sleep
Draft

spicysouvlaki wants to merge 1 commit into
mainfrom
wschmitt/abort-retry-sleep

Conversation

@spicysouvlaki

@spicysouvlaki spicysouvlaki commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

What happened

#205: aborting during a retry backoff still waits out the full Retry-After delay before rejecting (~500 ms, not ~20 ms).

Why

retryRequest() calls await sleep(timeoutMillis) without checking the signal. The signal is only checked when the next attempt starts.

Fix

sleep() takes an optional signal and resolves early on abort. It clears its timer and listener either way. makeRequest() then throws APIUserAbortError as it already does.

Tests

  • New: a 429 with Retry-After: 60, aborted after 10 ms. Main hits the 5 s jest timeout. This branch rejects with APIUserAbortError in about 14 ms.
  • ./scripts/lint, ./scripts/test (202 passed), ./scripts/build all pass.

Risk and rollout

src/core.ts is generated, so this is a sealed edit. sleep is exported, and its new parameter is optional. It ships with the next SDK release.

Fixes #205

🤖 Generated with Claude Code

retryRequest() awaited sleep(timeoutMillis) without looking at the caller's
signal, which was only checked when makeRequest() started the next attempt.
An abort during a Retry-After wait (up to whatever the server asks for)
stayed pending for the full delay.

sleep() now takes an optional signal and resolves early on abort, removing
its listener and timer either way. makeRequest() then sees the aborted
signal and throws APIUserAbortError as before.

Measured: new test with a 429 and Retry-After: 60 aborted after 10 ms. On
main it hits the 5 s jest timeout; with this change it rejects with
APIUserAbortError in ~14 ms.

src/core.ts is generated; this edit is sealed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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.

AbortSignal is ignored while waiting for retry backoff

1 participant