fix: remove double-wrapping from converse-stream Event Stream payloads (closes #162)#163
Merged
fix: remove double-wrapping from converse-stream Event Stream payloads (closes #162)#163
Conversation
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.
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Converse stream: double-wrapped Event Stream payloads — All 6 event types (messageStart, contentBlockDelta, etc.) emitted payloads wrapped with the event type name. The
:event-typebinary 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)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.
Chat Completions: missing logprobs — All streaming chunks and non-streaming choices now include `logprobs: null`. Drift allowlist entry removed so future omissions are caught.
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.
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`).
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