Skip to content

fix(hono): assign c.res directly for streaming responses to bypass finalized check#383

Closed
HugoRCD wants to merge 1 commit into
mainfrom
evl-179-7337
Closed

fix(hono): assign c.res directly for streaming responses to bypass finalized check#383
HugoRCD wants to merge 1 commit into
mainfrom
evl-179-7337

Conversation

@HugoRCD

@HugoRCD HugoRCD commented Jun 12, 2026

Copy link
Copy Markdown
Owner

When using createUIMessageStreamResponse (or any streaming response) with the Hono middleware, the request crashed with TypeError: ReadableStream is locked.

Root cause: Hono's compose function guards context.res updates behind a finalized check:

if (res && (context.finalized === false || isError)) {
  context.res = res;
}

The route handler sets c.res first, making context.finalized = true. When the evlog middleware later returned the wrapped Response, Hono silently discarded it. app.fetch() returned the original c.res whose body had already been locked by createObservedBody's getReader() call, so @hono/node-server crashed trying to read it.

Fix: Directly assign c.res with the result of finishResponse() instead of returning it from the middleware handler. This bypasses the finalized guard 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.

…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>
@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
evlog-docs Ready Ready Preview, Comment, Open in v0 Jun 12, 2026 6:47pm
just-use-evlog Ready Ready Preview, Comment Jun 12, 2026 6:47pm

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a7db100e-953d-4e0a-b724-29eef49c8d4f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch evl-179-7337

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.

❤️ Share

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

@github-actions github-actions Bot added the bug Something isn't working label Jun 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@pkg-pr-new

pkg-pr-new Bot commented Jun 12, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/evlog@383
npm i https://pkg.pr.new/@evlog/nuxthub@383

commit: baeb0cf

@HugoRCD HugoRCD closed this Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant