Skip to content

Vercel AI: streamText with tools fails with "ReadableStream is locked" on ai >= 7.0.168 #26403

Open

Description

@RulaKhaled

Since ai 7.0.168, Sentry breaks streamText calls that use tools. The call fails with TypeError: Invalid state: The ReadableStream is locked, and the caller gets no text. It happens with any tracesSampleRate, including 0, so it affects every app on these versions that has Sentry.init loaded, whether or not it traces.

Reported upstream in vercel/ai#24970. The reporter traced the failure to Sentry's ai:telemetry subscriber.

Affected versions (@sentry/node 11.12.0, @ai-sdk/azure 4.0.126, Node 20.20, fake-SSE script from vercel/ai#24970):

ai Result
7.0.163 works
7.0.166 works
7.0.167 never published
7.0.168 ReadableStream is locked
7.0.173 (latest) ReadableStream is locked

The same script without Sentry returns the text.

Cause: deferStreamedModelCallEnd in packages/server-utils/src/integrations/vercel-ai/vercel-ai-dc-subscriber.ts:339 replaces result.stream with a tapped stream. Since 7.0.168, ai publishes redactTelemetryCredentials(result) on the channel instead of the result itself. When that returns a copy, the copy shares the original ReadableStream. Our tapModelCallStream locks the original and assigns the tapped stream only to the copy. streamLanguageModelCall then calls pipeThrough on the original, which is locked.

vercel-ai-orchestrion-subscriber.ts:530 replaces value.stream on doStream results the same way. I haven't checked whether that path is affected.

Upstream fix: vercel/ai#24984 (open, awaiting maintainer review) makes the redacted copy forward stream to the real result. Applying its replaceProperties change to the built 7.0.173 fixes the repro with @sentry/node 11.12.0 at tracesSampleRate 1 and 0.

Our v6_v7/scenario-stream-tools.mjs didn't catch this because it uses MockLanguageModelV3, whose result has no request body for ai to redact, so no copy is made.

Activity

  1. linear-code commented on Nov 16, 2026

    @linear-code
  2. self-assigned this
    on Nov 16, 2026
  3. changed the title [-]Vercel AI: streamText with tools fails with "ReadableStream is locked" on ai >= 7.0.169[/-] [+]Vercel AI: streamText with tools fails with "ReadableStream is locked" on ai >= 7.0.168[/+] on Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions