Skip to content

AI SDK v5 Alpha 15 - Stop function (abort signal) with resumable-stream #6823

Open
@arthberman

Description

@arthberman

Description

Description:
I'm encountering an issue when using the stop function (via abortSignal) in combination with resumable-stream in AI SDK v5 Alpha 15. When I attempt to abort a streaming response, I receive the following error:

[ResponseAborted: ]
⨯ unhandledRejection: [ResponseAborted: ]
⨯ unhandledRejection: [ResponseAborted: ]

This seems to be an unhandled rejection related to the abort signal, but it's unclear if this is expected behavior or a bug.


Reproduction Steps:

  1. Set up a streaming request using streamText with an abortSignal.
  2. Use a resumable stream (see code below).
  3. Trigger the abort signal during the stream.

Code Example (extract from route.ts):

const result = streamText({
  _internal: {
    generateId: () => crypto.randomUUID(),
  },
  model: provider.languageModel(requestBody.data.modelId),
  messages: convertToModelMessages(messages),
  system: ChatSystemPrompt(),
  experimental_transform: smoothStream(),
  abortSignal: request.signal,
  onError: (error) => {
    console.error(error);
  },
  providerOptions: {
    bedrock: {
      reasoning_config: {
        type: "enabled",
        budget_tokens: 2048,
      },
    },
    google: {
      thinkingConfig: {
        includeThoughts: true,
        thinkingBudget: 2048,
      },
    },
    anthropic: {
      thinking: { type: "enabled", budgetTokens: 12000 },
    },
  },
  experimental_telemetry: {
    isEnabled: true,
  },
});

Additional Information:

  • The error appears as soon as the abort signal is triggered.
  • The error is not caught by the onError handler (both handlers from streamText and .toUIMessageStreamResponse).

Let me know if you need any more details or a minimal reproduction repository. Thank you!

AI SDK Version

-ai: 5.0.0-alpha.15

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai/uibugSomething isn't workingv5

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions