fix(hono): assign c.res directly for streaming responses to bypass finalized check#383
fix(hono): assign c.res directly for streaming responses to bypass finalized check#383HugoRCD wants to merge 1 commit into
Conversation
…nalized check Hono's compose skips updating context.res when context.finalized is already true (set by the route handler). The previous code returned the wrapped Response from the middleware, which Hono silently discarded, leaving c.res pointing at the original response whose body had been locked by createObservedBody. The @hono/node-server adapter then crashed trying to call getReader() on the locked stream. Fix: directly assign c.res with the result of finishResponse() instead of returning it, bypassing the finalized guard in Hono's compose. Generated with [Linear](https://linear.app/hrcd/issue/EVL-179/bug-hono-middleware-ai-sdks-createuimessagestreamresponse-crashes#agent-session-e7b0db01) Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
Thank you for following the naming conventions! 🙏 |
commit: |
When using
createUIMessageStreamResponse(or any streaming response) with the Hono middleware, the request crashed withTypeError: ReadableStream is locked.Root cause: Hono's
composefunction guardscontext.resupdates behind afinalizedcheck:The route handler sets
c.resfirst, makingcontext.finalized = true. When the evlog middleware later returned the wrapped Response, Hono silently discarded it.app.fetch()returned the originalc.reswhose body had already been locked bycreateObservedBody'sgetReader()call, so@hono/node-servercrashed trying to read it.Fix: Directly assign
c.reswith the result offinishResponse()instead of returning it from the middleware handler. This bypasses thefinalizedguard entirely.Two tests added: one verifies the response body remains consumable after middleware wraps it, and one confirms drain is deferred until the stream completes.