fix(core): prevent streamText abort unhandled rejections#1334
Conversation
🦋 Changeset detectedLatest commit: 18c2b11 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthrough
ChangesLazy Sanitized Text Promise
🎯 2 (Simple) | ⏱️ ~12 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This comment has been minimized.
This comment has been minimized.
Deploying voltagent with
|
| Latest commit: |
18c2b11
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b6908fb5.voltagent.pages.dev |
| Branch Preview URL: | https://fix-streamtext-abort-lazy-pr.voltagent.pages.dev |
PR Checklist
Please check if your PR fulfills the following requirements:
Bugs / Features
What is the current behavior?
Agent.streamText()eagerly materializes the AI SDKtext,usage, andfinishReasonlazy result promises while constructing VoltAgent's wrapped stream result.When a caller only consumes the stream, for example through
toUIMessageStream(), and then aborts the run, those unconsumed promises can reject without handlers and emit globalunhandledRejectionevents.What is the new behavior?
VoltAgent preserves lazy access for
text,usage, andfinishReasononstreamText()results. The sanitized text promise is now created only whenresult.textis accessed.This keeps stream-only consumers from needing defensive
.catch()handlers for fields they never read and aligns the wrapper more closely with AI SDK v6's lazy stream result contract.fixes (issue): N/A
Notes for reviewers
Validation run locally:
pnpm --filter @voltagent/core buildpnpm --filter @voltagent/core test:single src/agent/agent.spec.ts -t "does not eagerly materialize lazy stream result promises"pnpm exec biome check packages/core/src/agent/agent.ts packages/core/src/agent/agent.spec.ts .changeset/quiet-stream-abort.mdSummary by cubic
Fixes unhandled promise rejections when aborting
Agent.streamText()by keepingtext,usage, andfinishReasonlazy. Stream-only consumers (e.g.,toUIMessageStream()) can abort safely, matching AI SDK v6’s lazy stream contract.text,usage, andfinishReasonas getters on the wrapper.result.textis accessed; contain guardrail finalizer errors so they don’t leak if text isn’t read.textStream/fullStreambehavior without forcing promise creation.Written for commit 18c2b11. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes