Skip to content

fix(auto-instrumentation): Use sync channel for AI SDK CJS streamText/streamObject in v4+#1768

Merged
Stephen Belanger (Qard) merged 1 commit intomainfrom
fix/ai-sdk-cjs-sync-channels
Apr 9, 2026
Merged

fix(auto-instrumentation): Use sync channel for AI SDK CJS streamText/streamObject in v4+#1768
Stephen Belanger (Qard) merged 1 commit intomainfrom
fix/ai-sdk-cjs-sync-channels

Conversation

@Qard
Copy link
Copy Markdown
Contributor

Summary

  • The CJS bundle entries for streamText and streamObject used kind: "Async" for all versions (>=3.0.0), but DefaultStreamTextResult/DefaultStreamObjectResult have no .then(), so asyncEnd never fires when the transformer wraps via promise.then()
  • Splits the CJS entries to mirror the existing ESM split (which was already correct in main):
    • >=3.0.0 <4.0.0: kind: "Async" — v3, where the function was genuinely async
    • >=4.0.0: kind: "Sync" + sync channel — v4+, after the sync refactor
  • The traceSyncStreamChannel handlers for streamTextSync/streamObjectSync already exist in ai-sdk-plugin.ts (they were added when the ESM path was fixed), so no plugin change is needed

Test plan

  • ai-sdk-plugin.test.ts — 96 tests pass
  • Pre-existing test failures in transformation.test.ts / loader-hook.test.ts confirmed unrelated (same failures on main)

🤖 Generated with Claude Code

…/streamObject in v4+

The CJS bundle entries for streamText and streamObject used kind: "Async"
for all versions (>=3.0.0), but DefaultStreamTextResult/DefaultStreamObjectResult
have no .then(), so asyncEnd never fires with wrapPromise's async wrapping.

Split the CJS entries to mirror the existing ESM split:
- >=3.0.0 <4.0.0: kind "Async" (v3, where the function was genuinely async)
- >=4.0.0: kind "Sync" + sync channel (v4+, after the sync refactor)

The traceSyncStreamChannel handlers for streamTextSync/streamObjectSync
already exist in ai-sdk-plugin.ts (added when ESM was fixed), so no
plugin change is needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Qard Stephen Belanger (Qard) merged commit a0f4f12 into main Apr 9, 2026
54 of 55 checks passed
@Qard Stephen Belanger (Qard) deleted the fix/ai-sdk-cjs-sync-channels branch April 9, 2026 18:46
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