Skip to content

Avoid bun memory leak bug from TransformStream#4255

Draft
TheodoreSpeaks wants to merge 1 commit intostagingfrom
fix/memory-leak
Draft

Avoid bun memory leak bug from TransformStream#4255
TheodoreSpeaks wants to merge 1 commit intostagingfrom
fix/memory-leak

Conversation

@TheodoreSpeaks
Copy link
Copy Markdown
Collaborator

@TheodoreSpeaks TheodoreSpeaks commented Apr 22, 2026

Summary

Bun has a bug in TransformStream: oven-sh/bun#28035 causing high memory consumption due to no backpressure signal. We use this in

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

  • Validated that streaming responses still work fine with an agent block in a workflow locally.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 22, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 22, 2026 3:08am

Request Review

@TheodoreSpeaks
Copy link
Copy Markdown
Collaborator Author

@BugBot review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 22, 2026

PR Summary

Medium Risk
Touches core streaming execution flow and how streamed content is assembled/parsed, so regressions could affect SSE delivery or final output content under streaming/error conditions.

Overview
Reworks streaming block handling to avoid ReadableStream.tee()/TransformStream wrapping and instead drain the source stream once while simultaneously forwarding chunks to the client.

Adds StreamingExecution.onFullContent and updates the agent memory persistence path to append the final assembled streamed response via this callback; removes the prior wrapStreamForPersistence TransformStream-based implementation to mitigate Bun memory growth.

Reviewed by Cursor Bugbot for commit 43a727d. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 43a727d. Configure here.

} catch {}
}

const fullContent = chunks.join('')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial content persisted when stream consumer errors internally

Medium Severity

Content accumulation is now coupled to the client's consumption of the stream via the pull callback in clientSource. Previously, stream.tee() gave the executor an independent copy that was always fully consumed regardless of client-side failures. Now, if an onStream consumer encounters an internal error (e.g., SSE sendEvent throws) but catches it without re-throwing, onStream returns normally, drainError is not set, and the code proceeds to process and persist the partially accumulated content — setting incomplete text on executionOutput.content and invoking onFullContent with a truncated string. This can cause incomplete assistant responses to be persisted to memory via appendToMemory.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 43a727d. Configure here.

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