fix(hono): resolve "ReadableStream is locked" error in AI SDK#384
Conversation
|
@nadaniels is attempting to deploy a commit to the HRCD Projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Thank you for following the naming conventions! 🙏 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR fixes the ChangesStreaming ReadableStream Lock Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 install timed out. The project may have too many dependencies for the sandbox. 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 |
🔗 Linked issue
Closes #382
📚 Description
Using
createUIMessageStreamResponseorcreateAgentUIStreamResponsefrom the Vercel AI SDK inside a Hono route would throwERR_INVALID_STATE: ReadableStream is lockedwhen running under@hono/node-server.Root cause: The middleware called
createObservedBody(c.res.body)(which callsbody.getReader(), locking the stream) and then relied on Hono'scomposeto updatec.reswith the wrapped response via the middleware return value. However, Hono skips that update whencontext.finalizedis alreadytrue— which is always the case after a route handler returns aResponse. This leftc.respointing at the original response whose body was now locked, so@hono/node-server's subsequentresponse.body.getReader()call threw.Fix: Explicitly assign
c.res = await finishResponse(c.res, ...)instead of returning the wrapped response, soc.resis always updated regardless ofcontext.finalized.Added additional regression tests
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests