pi-mono/packages
robopipi[bot] f409847473
fix(mcp): cancel SSE response streams that fail the message-size limit (#11735)
When an SSE event went over `maxMessageBytes`, `consumeSseStream()`
threw the size-limit error, but its `finally` only released the reader
lock. Releasing the lock does not cancel the response body. If the
server kept the response open, for example with heartbeats, the failed
request held its HTTP connection until the server ended it or the whole
client was closed. The same applies to the GET notification stream,
which uses the same function.

On error, `consumeSseStream()` now cancels the reader before it rethrows
and releases the lock. A failure in `cancel()` is ignored, so the caller
still gets the original error.

Testing:
- New test in `packages/mcp/test/streamable-http.test.ts`: it feeds an
oversized event through a stream that stays open and checks that the
stream's `cancel` callback runs. It fails without the change and passes
with it.
- Full mcp package tests: 48/48 pass. `npm run check` is clean.
- Reproduction over loopback: a local `node:http` server sends a
512-byte event, then a heartbeat every 20 ms, and the client reads it
through `fetch` with `maxEventBytes: 128`, three times.
- Before: none of the three server responses closed, and the server made
28 more heartbeat writes.
  - After: all three closed, with no further writes.

Fixes #11729

Requested by @badlogic

Co-authored-by: triagent <triagent@localhost>
2026-11-03 14:22:16 +01:00
..
agent Anthropic message threads (#11545) 2026-11-03 14:07:57 +01:00
ai Anthropic message threads (#11545) 2026-11-03 14:07:57 +01:00
chord docs(chord): p2 on Chord v2 and the v1 deletion done 2026-11-03 12:15:48 +00:00
codemode Add [Unreleased] section for next cycle 2026-11-02 11:38:21 +01:00
coding-agent fix(mcp): refresh with the app's redirect URI, cancel sign-in during the lock wait 2026-11-03 14:17:21 +01:00
durable feat(chord): Chord v2 is the package's root 2026-11-02 22:36:55 +00:00
env fix(env): kill what a process program left running when it exits 2026-11-03 14:17:21 +01:00
evals Release v1.5.0 2026-11-02 11:38:21 +01:00
mcp fix(mcp): cancel SSE response streams that fail the message-size limit (#11735) 2026-11-03 14:22:16 +01:00
schema Add [Unreleased] section for next cycle 2026-11-02 11:38:21 +01:00
telemetry Add [Unreleased] section for next cycle 2026-11-02 11:38:21 +01:00
tui Add [Unreleased] section for next cycle 2026-11-02 11:38:21 +01:00