Skip to content

fix(llm): reject Bedrock event-stream frames above the 16 MiB maximum - #44631

Open
pacocartones wants to merge 1 commit into
anomalyco:devfrom
pacocartones:fix/bedrock-event-stream-frame-limit
Open

fix(llm): reject Bedrock event-stream frames above the 16 MiB maximum#44631
pacocartones wants to merge 1 commit into
anomalyco:devfrom
pacocartones:fix/bedrock-event-stream-frame-limit

Conversation

@pacocartones

Copy link
Copy Markdown

Issue for this PR

Closes#44630

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

bedrock-event-stream.ts reads total_length from the frame prelude and waits for that many bytes. It's a 32-bit field, so a malformed response can declare up to 4 GiB. Nothing bounds the wait, and since the buffer is only compacted once a frame completes, appendChunk re-copies the whole accumulated window on every network chunk — cost is quadratic in bytes received. Measured with 16 KiB chunks after a 0xFFFFFFFF prelude: 16 MiB sent → 4.1 s / 166 MiB RSS; 64 MiB sent → 47.2 s / 650 MiB RSS. The stream then fails with the generic ended without a terminal finish event, so there's no diagnostic either.

AWS caps an event-stream message at 16 MiB. @smithy/eventstream-codec doesn't enforce it. This adds that check before the length gate, so an oversized prelude fails fast with the declared size in the message instead of buffering toward a frame that can never complete. Well-formed frames are unaffected — the check only fires above 16 MiB, which no valid Converse frame reaches.

How did you verify your code works?

Added a test to packages/llm/test/provider/bedrock-converse.test.ts that feeds a prelude declaring 0xFFFFFFFF through LLMClient.generate and asserts the framing error. Without the fix it fails with Provider stream ended without a terminal finish event; with it, it passes.

bun test in packages/llm: 298 pass on dev, 299 pass with this change, 0 fail. bun run typecheck clean.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

renekris added a commit to renekris/opencode-lowmem that referenced this pull request Aug 26, 2026
- pin note, seam-lookup range, and deferred-port re-verification now
reference v1.18.23 (post-split packages/ai|util tree still absent,
anomalyco#43769 stays blocked)
- watch-list gains the 2026-08-26 sweep candidates (anomalyco#39930, anomalyco#38939,
anomalyco#41950, anomalyco#33713, anomalyco#44631)
- fork-build.sh BASE lookup now excludes *-lowmem.* tags: after a fresh
upstream merge the previous fork tag ties the new base tag on commit
distance with a newer date and git describe stamps the OLD base
Sign up for freeto 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.

Bedrock event-stream framing buffers without bound when a frame prelude declares an oversized length

1 participant

@pacocartones