AI SDK calls in SSE handlers fail with ReadableStream error when OTEL is enabled, despite the #471 fix.
Issue
Error: ReadableStream has already been used
Error: Connection lost
Observed in Model Arena demo within the SDK explorer where Anthropic provider shows the error and connection drops.
Workaround:
OTEL_SDK_DISABLED=true bun run dev
Potential Cause
The #471 fix wraps SSE handlers in ROOT_CONTEXT to bypass OTEL-instrumented fetch. This works for simpler cases but still fails when:
- Using
generateObject (not just generateText)
- Running multiple AI SDK calls in parallel within an SSE handler
Potential Fixes
- Check if
generateObject triggers different OTEL instrumentation paths than generateText
- Investigate whether parallel AI SDK calls inside SSE handlers need additional handling
- Verify ROOT_CONTEXT propagates correctly through Promise.all() with multiple provider calls
AI SDK calls in SSE handlers fail with ReadableStream error when OTEL is enabled, despite the #471 fix.
Issue
Observed in Model Arena demo within the SDK explorer where Anthropic provider shows the error and connection drops.
Workaround:
Potential Cause
The #471 fix wraps SSE handlers in
ROOT_CONTEXTto bypass OTEL-instrumented fetch. This works for simpler cases but still fails when:generateObject(not justgenerateText)Potential Fixes
generateObjecttriggers different OTEL instrumentation paths thangenerateText