Repository navigation
Conversation
Decode SSE streams incrementally over iter_bytes()/aiter_bytes() and split strictly on CR, LF, or CRLF instead of relying on httpx iter_lines() (which splits on Unicode line separators such as U+2028, U+2029, and U+0085 inside JSON payloads). Fixes QoderAI#45
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
response.iter_lines()/aiter_lines()inStreamandAsyncStream(src/qca/common/_streaming.py) with incremental UTF-8 decoding overiter_bytes()/aiter_bytes(), splitting strictly on\r\n,\r, and\nper the WHATWG SSE specification.\r\n/ multi-byte UTF-8 sequences split across arbitrary chunk boundaries while preserving_InterruptibleSyncBodysync cancellation.tests/test_streaming.pyand an[Unreleased]changelog entry.Fixes #45
Why
httpx'siter_lines()delegates to Python'sstr.splitlines(), which splits on Unicode line separators such as\u2028,\u2029, and\x85. When agent output includes these valid JSON characters inside an SSEdata:payload, the frame was split mid-JSON and raisedAPIResponseValidationError.Verification
uv run make lint(ruff check .+ruff format --check)uv run make typecheck(mypy src/qca scripts)uv run make test(pytest -q)uv run make docs-check(python scripts/docs-check.py)--helpsmoke checks (no public signatures changed)Commands and results:
Impact
\u2028/\u2029/\x85no longer fail parsing)CHANGELOG.mdunderUnreleaseddocs-check.py, no public API doc drift)str.splitlines()behavior inhttpx.LineDecoder).env.live, logs, or generated test output committed