fix: propagate abort signals to outbound network calls#457
Merged
threepointone merged 2 commits intomainfrom Mar 22, 2026
Merged
fix: propagate abort signals to outbound network calls#457threepointone merged 2 commits intomainfrom
threepointone merged 2 commits intomainfrom
Conversation
Fix request cancellation by passing abort signals through outbound calls. Update ai-gateway-provider to forward options.abortSignal to fetch and binding.run and widen the binding.run type to accept an options object. Update tanstack-ai create-fetcher utilities to forward init.signal to binding.run (gateway and workers binding paths) and to build/run options consistently. Update workers-ai-provider chat, embedding, and image models to include abortSignal when calling binding.run so canceled requests are properly aborted. Update tests to reflect the optional options object shape and ensure extraHeaders handling remains correct. Adds a changeset documenting the patch.
Tweak CloudflareAiGateway typing and the callsite to avoid TypeScript conflicts while still forwarding an AbortSignal. The interface signature for CloudflareAiGateway.run was simplified to remove the options parameter, and the call to config.binding.run is now invoked through an explicit type assertion that accepts an optional { signal } argument. This preserves the runtime behavior of passing init.signal to gateway bindings without causing type errors.
🦋 Changeset detectedLatest commit: 09576b6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
bdstar81
approved these changes
Mar 22, 2026
bdstar81
approved these changes
Mar 22, 2026
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.
Summary
abortSignalto thefetchcall (API path) and tobinding.run()(binding path) so that cancelled requests are properly aborted.abortSignaltobinding.run()for chat, embedding, and image models, matching the existing behavior in transcription, speech, and reranking models.signalthrough tobinding.run()in bothcreateGatewayFetch(AI Gateway binding path) andcreateWorkersAiBindingFetch(Workers AI binding path).Details
None of the three packages were propagating the AI SDK's
abortSignal(or the fetchinit.signal) to their outbound network calls. This meant that when a user cancelled a request (e.g. stopped a streaming response), the underlying HTTP request or binding call would continue running until completion.The workers-ai-provider had partial coverage — transcription, speech, and reranking models already passed
signal: abortSignalvia anas AiOptionscast, but the most commonly used models (chat, embedding, image) did not.Test plan
tsc --noEmitpasses for all three packagesMade with Cursor