Skip to content

fix: remove double-wrapping from converse-stream Event Stream payloads (closes #162)#163

Merged
jpr5 merged 9 commits intomainfrom
fix/converse-stream-double-wrap
May 8, 2026
Merged

fix: remove double-wrapping from converse-stream Event Stream payloads (closes #162)#163
jpr5 merged 9 commits intomainfrom
fix/converse-stream-double-wrap

Conversation

@jpr5
Copy link
Copy Markdown
Contributor

@jpr5 jpr5 commented May 8, 2026

Summary

Systematic spec conformance audit and fixes across 6 providers. Every fix includes new tests with negative assertions ("does NOT have the wrong shape") to prevent regressions.

Fixes

  1. Converse stream: double-wrapped Event Stream payloads — All 6 event types (messageStart, contentBlockDelta, etc.) emitted payloads wrapped with the event type name. The :event-type binary header already carries it; AWS SDK expected flat payloads. Caused silent failures in boto3/Strands Agents. (Closes Bug: converse-stream Event Stream payloads are double-wrapped, causing KeyError in AWS SDK #162)

  2. Responses API: missing item_id — `response.output_text.done`, `response.content_part.added`, and `response.content_part.done` were missing `item_id` that the real OpenAI API includes. SDK drift shapes updated.

  3. Chat Completions: missing logprobs — All streaming chunks and non-streaming choices now include `logprobs: null`. Drift allowlist entry removed so future omissions are caught.

  4. Ollama: missing created_at on /api/chat — 6 builder functions (text, tool call, content+tools + streaming variants) now include `created_at`. The `/api/generate` path already had it.

  5. Gemini + Gemini Live: wrong error status codes — Test fixtures used Anthropic-style `rate_limit_error`; Gemini Live handler hardcoded `ERROR`. Now uses Google canonical gRPC codes (`RESOURCE_EXHAUSTED`, `INTERNAL`).

  6. Converse-stream drift test — New drift test with binary frame parsing, flat-payload validation, negative assertions, and 3-way SDK shape comparison.

Root cause

The existing test suite validated "code does what code does" instead of "code does what the spec says." Tests were written to match builder output, not the real API shapes. The converse-stream double-wrap bug was the worst case — tests actively asserted the buggy shape.

Test plan

  • `pnpm test` — 2831 passed
  • `npx tsc --noEmit` — clean
  • New tests added for every fix (anti-regression + negative assertions)
  • Drift shapes and allowlists updated
  • Converse-stream drift test with binary frame parsing

closes #162)

Converse stream event builders emitted payloads wrapped with the
event type name (e.g. { messageStart: { role: "assistant" } }). The
:event-type header already carries the event name, so AWS SDK
(botocore) expected flat payloads (e.g. { role: "assistant" }). The
redundant wrapping caused botocore to silently return empty dicts,
producing KeyError in downstream frameworks like Strands Agents.

Affected functions: buildBedrockStreamTextEvents,
buildBedrockStreamToolCallEvents,
buildBedrockStreamContentWithToolCallsEvents.
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 8, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@copilotkit/aimock@163

commit: 77b0985

@jpr5 jpr5 merged commit dcda28d into main May 8, 2026
22 checks passed
@jpr5 jpr5 deleted the fix/converse-stream-double-wrap branch May 8, 2026 09:50
Sign up for free to 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.

Bug: converse-stream Event Stream payloads are double-wrapped, causing KeyError in AWS SDK

1 participant