Repository navigation
Conversation
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.
Summary
Preserve Unicode characters inside streamed JSON responses instead of treating them as record separators.
HTTPX
iter_lines()/aiter_lines()use universalstr.splitlines()semantics. That splits valid JSON strings containing raw U+0085, U+2028 or U+2029 beforejson.loads(), producing an “Unterminated string” error. The new regressions reproduce this through publicClient.chat()andAsyncClient.generate()calls with deterministic one-byte chunks.This keeps HTTPX's public
iter_text()/aiter_text()decoding and changes only record framing to LF, accepting CRLF. Partial records are accumulated as pieces and joined once. Existing charset/default-encoding behavior is retained as backwards compatibility; Latin-1 is not being presented as NDJSON-conforming.Verification
On Python 3.11.11 / Pydantic 2.10.6:
git diff --check: passed.Scope / overlaps
The NDJSON framing rules use LF or CRLF; JSON strings permit these Unicode characters. CR-only framing and other non-NDJSON separators are no longer treated as record boundaries. Final records without a newline remain accepted.
This does not add blank-line skipping (#689/#393) or connection-error wrapping (#741). Those open PRs touch the same loops but retain universal line splitting; a rebase may be needed depending on merge order. No combined runtime compatibility with their complete branches is claimed.
AI assistance
Claude Code prepared the implementation and regressions. Codex independently reproduced the base failure, found and rejected a charset regression in the first proposal, and verified this refined patch before publication.