Skip to content

fix(streaming): handle an initial UTF-8 byte-order mark - #1983

Open
sylvesterkaczmarek wants to merge 1 commit into
anthropics:mainfrom
sylvesterkaczmarek:fix/initial-sse-byte-order-mark-20261005
Open

sylvesterkaczmarek wants to merge 1 commit into
anthropics:mainfrom
sylvesterkaczmarek:fix/initial-sse-byte-order-mark-20261005

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Fixes #1982.

Track the first decoded SSE line and remove at most its single leading U+FEFF before parsing fields. The shared decoder covers synchronous/asynchronous and stable/beta clients. Subsequent U+FEFF characters are preserved. This adds a first-line normalization block without rewriting event framing, resource methods or public signatures.

Validation

The 48 fixture-based cases cover prefixed/unprefixed streams, event/data as the first field, one-byte/two-byte/larger transport chunks and preservation of later U+FEFF characters. Against unchanged main: 24 failed, 24 passed.

Final validation ran ./scripts/test for tests/test_streaming.py and both tests/lib/streaming/test_messages.py and test_beta_messages.py, followed by the script's MCP v2 checks, on Python 3.14.7. Repository formatting, ./scripts/lint and git diff --check passed. Earlier related runs also exercised Python 3.13.15 with Pydantic v1/v2; the Python 3.10 floor was not validated locally.

Tested on macOS arm64 with mocked HTTP and recorded fixtures. The complete generated API suite and live services were not run. No dependency, lockfile, workflow or release-metadata changes.

Reference: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation. The Go SDK has a separate initial-BOM PR at anthropics/anthropic-sdk-go#455.

Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner October 5, 2026 18:09
@sylvesterkaczmarek

Copy link
Copy Markdown
Author

The regression and related tests and the repository lint checks pass locally, as detailed in the PR. Could a maintainer approve the pending Actions run?

This branch has not been deployed

No deployments
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.

A leading UTF-8 BOM prevents streaming messages from reading the first event

1 participant