fix: respect AbortSignal in run() — throw on pre-aborted and mid-polling abort#375
Open
MaxwellCalkin wants to merge 1 commit intoreplicate:mainfrom
Open
fix: respect AbortSignal in run() — throw on pre-aborted and mid-polling abort#375MaxwellCalkin wants to merge 1 commit intoreplicate:mainfrom
MaxwellCalkin wants to merge 1 commit intoreplicate:mainfrom
Conversation
…nd mid-polling abort Fixes replicate#370. The run() method previously ignored AbortSignal in three ways: 1. If the signal was already aborted before calling run(), the prediction started anyway instead of throwing immediately. 2. During polling, the signal was not passed to HTTP requests or the sleep timer, so abort could not interrupt in-flight requests or waits. 3. After cancellation, run() returned undefined instead of throwing an AbortError, so callers had no way to distinguish abort from failure. Changes: - Check signal.aborted before starting the prediction and throw AbortError - Pass signal through to predictions.create() so the initial HTTP request can be aborted by the signal - Pass signal to wait() and forward it to predictions.get() polling calls - Make sleep() in wait() abort-aware: listen for the abort event to resolve immediately instead of waiting the full interval - Throw AbortError after canceling the prediction, matching standard AbortSignal behavior (e.g. fetch) - Update TypeScript types to include signal option on wait() - Update existing abort test to expect thrown error, add pre-aborted test Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Fixes #370.
Summary
replicate.run()ignoresAbortSignalin three ways:signal.abortedis alreadytruebefore callingrun(), the SDK starts the prediction anyway instead of throwing immediately.predictions.create()orpredictions.get()during polling, so aborting could not cancel in-flight HTTP requests or interrupt sleep timers.run()returnedundefinedsilently instead of throwing anAbortError, making it impossible for callers to distinguish an abort from a failure or empty output.Changes
signal.abortedbefore starting the prediction and throwAbortErrorimmediatelysignalthrough topredictions.create()so the initial HTTP request respects the signalsignaltowait()and forward it to allpredictions.get()polling callssleep()inwait()abort-aware: listen for theabortevent to resolve immediately instead of waiting the full polling intervalAbortError(witherror.name = "AbortError") after canceling the prediction, matching standardAbortSignalbehavior (e.g., howfetchhandles abort)signaloption onwait()undefinedoutputTest plan
AbortErroris thrown after mid-polling abortAbortErroris thrown immediately for pre-aborted signalsDisclosure
This PR was authored by Claude Opus 4.6 (an AI assistant by Anthropic). I am exploring transparent AI contributions to open-source projects. Happy to address any feedback.
🤖 Generated with Claude Code