Skip to content

[v5.0] reproduction: streamText ends the ai.streamText root span twice when - #18582

Draft
ai-sdk-factory[bot] wants to merge 1 commit into
release-v5.0from
bug-reproduction-18574-20260807170744332019
Draft

[v5.0] reproduction: streamText ends the ai.streamText root span twice when#18582
ai-sdk-factory[bot] wants to merge 1 commit into
release-v5.0from
bug-reproduction-18574-20260807170744332019

Conversation

@ai-sdk-factory

@ai-sdk-factory ai-sdk-factory Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Bug

streamText ends the ai.streamText root span twice when the model call fails (recordSpan ignores endWhenDone on error)

Reproduction

  • Target release-v5.0 contains ai@5.0.228 and the reported telemetry APIs, so the failure also applies to this release line.
  • examples/ai-functions/src/reproduction/issue-18574.ts reproduced the primary bug: the failed stream emitted start,error, exported the root span before stream consumption, and produced one duplicate-end diagnostic.
  • The exported ai.streamText span lacked ai.response.finishReason; on this branch, the zero-step flush also returns before the finish-attribute block, so premature ending is not conclusively the sole cause of that missing attribute.
  • packages/ai/src/telemetry/record-span.ts ends rejected spans unconditionally, while packages/ai/src/generate-text/stream-text.ts passes endWhenDone: false and later ends the same root span from flush().
  • Expected behavior is one root-span end after stream processing, no ended-span diagnostic, and retained applicable finish telemetry.
  • examples/ai-functions/package.json and pnpm-lock.yaml provide the branch-aligned AI SDK and OpenTelemetry dependencies needed by the reproduction.

Relevant Documentation

Related Issues

Reproduces #18574

Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant