Replace line iter with bytes to lines wrapper#663
Conversation
Signed-off-by: Samuel Monson <smonson@redhat.com>
jaredoconnell
left a comment
There was a problem hiding this comment.
This does seem more like a workaround, but if this fixes the bug we can try it.
|
So this doesn't fully fix the issue but I think merge it anyways because it fixes a separate issue. We have been over-counting event iterations due to counting each newline when we really should have been counting each |
Signed-off-by: Samuel Monson <smonson@redhat.com>
dbutenhof
left a comment
There was a problem hiding this comment.
This approach won't break anything worse than before, so if it avoids problems on even a subset of cases, it's a win. I agree: let's go for it.
|
Next release we can look at https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation for building a better parser. |
## Summary Partially reverts #663 to iterating over lines, but keeps the skipping of blank newlines. ## Details #663 switched the HTTP backend to iterating over byte strings. The problem is that is did not handle the case where a line was split over multiple iterations. ## Test Plan Run a benchmark with known errored request rate (preferably 0) and ensure that there are no failed requests due to `orjson.JSONDecodeError: unexpected end of data`. --- - [x] "I certify that all code in this PR is my own, except as noted below." ## Use of AI - [ ] Includes AI-assisted code completion - [ ] Includes code generated by an AI application - [ ] Includes AI-generated tests (NOTE: AI written tests should have a docstring that includes `## WRITTEN BY AI ##`)
Summary
Read bytes stream rather then lines stream and manually split on double newline
\n\n.Details
Some models (gpt-oss) don't escape their newlines which causes
httpx.iter_linesto split in the wrong spot. Note that is could potently could still be a problem if a model emits a\n\ntoken. so we may need a more robust solution in the future.Test Plan
See original issue.
Related Issues
Use of AI
## WRITTEN BY AI ##)