Skip to content

fix(packages/agents): prevent unhandled promise rejections in stream()#11

Merged
zrosenbauer merged 2 commits intomainfrom
fix/stream-unhandled-rejections
Mar 15, 2026
Merged

fix(packages/agents): prevent unhandled promise rejections in stream()#11
zrosenbauer merged 2 commits intomainfrom
fix/stream-unhandled-rejections

Conversation

@zrosenbauer
Copy link
Member

Summary

  • Add no-op .catch(() => {}) handlers on all 4 derived promises (output, messages, usage, finishReason) in both agent.stream() and flowAgent.stream()
  • When the underlying stream errors and consumers don't await all promises, this prevents Node.js UnhandledPromiseRejection warnings
  • Add tests in both agent.test.ts and flow-agent.test.ts verifying no unhandledRejection event fires

Test plan

  • pnpm test --filter=@funkai/agents passes
  • New tests verify no unhandled rejection warnings on stream error

Add no-op .catch() handlers on derived promises (output, messages,
usage, finishReason) in both agent.stream() and flowAgent.stream().
When the underlying stream errors and consumers don't await all
promises, this prevents Node.js UnhandledPromiseRejection warnings.

Co-Authored-By: Claude <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Mar 15, 2026

🦋 Changeset detected

Latest commit: 642743c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@funkai/agents Patch

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

@vercel
Copy link

vercel bot commented Mar 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
funkai Ready Ready Preview, Comment Mar 15, 2026 3:31am

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Mar 15, 2026

Warning

Rate limit exceeded

@zrosenbauer has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 14 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: cce9b498-8dcf-447c-94dc-45f04e35c7d5

📥 Commits

Reviewing files that changed from the base of the PR and between 0233e68 and 642743c.

📒 Files selected for processing (1)
  • .changeset/fix-stream-unhandled-rejections.md
📝 Walkthrough

Walkthrough

Adds unhandled rejection handlers to stream result promises in two agent implementations (base and flow) to prevent unhandledRejection warnings when consumers don't await derived promises. Includes corresponding test coverage validating this safety mechanism.

Changes

Cohort / File(s) Summary
Base Agent Rejection Handling
packages/agents/src/core/agents/base/agent.ts
Attaches catch handlers to streamResult.output, streamResult.messages, streamResult.usage, and streamResult.finishReason to swallow unhandled rejections.
Flow Agent Rejection Handling
packages/agents/src/core/agents/flow/flow-agent.ts
Attaches identical catch handlers to streamResult properties in both generate and stream paths.
Unhandled Rejection Safety Tests
packages/agents/src/core/agents/base/agent.test.ts, packages/agents/src/core/agents/flow/flow-agent.test.ts
Adds "stream() unhandled rejection safety" test suites verifying that ignoring derived promises doesn't emit unhandledRejection events.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: preventing unhandled promise rejections in stream() by adding no-op catch handlers.
Description check ✅ Passed The description clearly explains the changes, their purpose, and includes a test plan directly related to the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Co-Authored-By: Claude <noreply@anthropic.com>
@zrosenbauer zrosenbauer merged commit 62459e6 into main Mar 15, 2026
5 checks passed
@zrosenbauer zrosenbauer deleted the fix/stream-unhandled-rejections branch March 15, 2026 03:35
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.

1 participant