Repository navigation
[CB-0] [sdk-superfan] Let the signal interrupt the retry wait - #245
Draft
spicysouvlaki wants to merge 1 commit into
Draft
spicysouvlaki wants to merge 1 commit into
spicysouvlaki wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What happened
#205: aborting during a retry backoff still waits out the full
Retry-Afterdelay before rejecting (~500 ms, not ~20 ms).Why
retryRequest()callsawait 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 throwsAPIUserAbortErroras it already does.Tests
Retry-After: 60, aborted after 10 ms. Main hits the 5 s jest timeout. This branch rejects withAPIUserAbortErrorin about 14 ms../scripts/lint,./scripts/test(202 passed),./scripts/buildall pass.Risk and rollout
src/core.tsis generated, so this is a sealed edit.sleepis exported, and its new parameter is optional. It ships with the next SDK release.Fixes #205
🤖 Generated with Claude Code