Skip to content

fix: propagate abort signals to outbound network calls#457

Merged
threepointone merged 2 commits intomainfrom
fix-abort-signal
Mar 22, 2026
Merged

fix: propagate abort signals to outbound network calls#457
threepointone merged 2 commits intomainfrom
fix-abort-signal

Conversation

@threepointone
Copy link
Collaborator

Summary

  • ai-gateway-provider: Pass abortSignal to the fetch call (API path) and to binding.run() (binding path) so that cancelled requests are properly aborted.
  • workers-ai-provider: Pass abortSignal to binding.run() for chat, embedding, and image models, matching the existing behavior in transcription, speech, and reranking models.
  • @cloudflare/tanstack-ai: Pass signal through to binding.run() in both createGatewayFetch (AI Gateway binding path) and createWorkersAiBindingFetch (Workers AI binding path).

Details

None of the three packages were propagating the AI SDK's abortSignal (or the fetch init.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: abortSignal via an as AiOptions cast, but the most commonly used models (chat, embedding, image) did not.

Test plan

  • All ai-gateway-provider tests pass (13/13)
  • All workers-ai-provider tests pass (222/222)
  • All tanstack-ai tests pass (219/219)
  • tsc --noEmit passes for all three packages

Made with Cursor

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-bot
Copy link

changeset-bot bot commented Mar 22, 2026

🦋 Changeset detected

Latest commit: 09576b6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
ai-gateway-provider Patch
workers-ai-provider Patch
@cloudflare/tanstack-ai Patch

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 22, 2026

Open in StackBlitz

npx https://pkg.pr.new/cloudflare/ai/ai-gateway-provider@457
npx https://pkg.pr.new/cloudflare/ai/@cloudflare/tanstack-ai@457
npx https://pkg.pr.new/cloudflare/ai/workers-ai-provider@457

commit: 09576b6

@threepointone threepointone merged commit decf665 into main Mar 22, 2026
3 checks passed
@threepointone threepointone deleted the fix-abort-signal branch March 22, 2026 13:40
@github-actions github-actions bot mentioned this pull request Mar 22, 2026
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.

2 participants