Repository navigation
fix(streaming): handle an initial UTF-8 byte-order mark - #1983
Open
sylvesterkaczmarek wants to merge 1 commit into
Open
sylvesterkaczmarek wants to merge 1 commit into
sylvesterkaczmarek wants to merge 1 commit into
Conversation
Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
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
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.
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.