Repository navigation
fix(studio): preserve Unicode separators in S3 JSON Lines transcripts - #16725
Conversation
|
@codex review |
1 similar comment
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…lothai#17725) Studio's chat page streams through durable chat runs, and the run worker's `_SSEDecoder` split each SSE event with `str.splitlines()`. That also breaks at U+2028, U+2029 and U+0085, which JSON does not escape: both pydantic's `model_dump_json` and llama-server write them raw. A delta holding one of these characters is cut in two, `json.loads` fails on the first half, and the `except`/`continue` drops the chunk without a log line. The text is missing from the streamed reply and from the stored message, so it stays missing after a reload. Models emit these characters when they repeat text pasted from a web page or a PDF. This is the same character class as unslothai#16725 (S3 JSONL). The fix splits on `\n` only. The decoder already turns CRLF into LF and splits events on ` `, and the stream it reads is Studio's own LF-only SSE, so nothing else changes; multi-line `data:` fields are still joined with newlines. Feeding `_chat_chunk_sse` output into `_SSEDecoder` a few characters at a time, main drops the content chunk and keeps only the finish chunk; with the fix the content arrives intact. The new `tests/test_chat_generation_runs_sse_decoder.py` (each separator, LF and CRLF) fails 6 of 7 on main and passes 7 of 7 with the fix; together with `tests/test_chat_generation_runs.py` that is 80 passed, on Windows with Python 3.12. ## Same bug on the upstream streams (added by maintainer) httpx's `aiter_lines()` uses the same `str.splitlines()` rule, and every upstream SSE stream Studio reads went through it: the llama-server `/v1/chat/completions` and `/v1/messages` passthroughs (the API that agents launched with `unsloth start` and other clients use), external and managed-engine providers (vLLM writes these characters raw too), the subscription Responses client, and research runs. Reproduced on main through the real passthrough routes with a llama-server stream whose delta holds U+2028, U+2029 or U+0085: - `/v1/chat/completions` stream: the first half is forwarded as its own SSE event, so the client gets `Unterminated string` JSON and the rest of the delta is lost. - `/v1/messages` stream: the delta is dropped, the client receives empty text. Changes: - `core/inference/http_stream.py`: `aiter_sse_lines(response)`, a drop-in for `aiter_lines()` that splits only at CR, LF and CRLF (a trailing CR is held until the next chunk), and closes its inner `aiter_text()` iterator itself. Used at every upstream `aiter_lines()` call site and by `closing_response_lines`. Objects without `aiter_text` keep their own `aiter_lines()`. - The same split (`SSE_LINE_END`) in `_SSEDecoder`, in llama_cpp's `_sse_event_payload` (first-output detection missed a separator delta) and in the `/v1/chat/completions` and `/v1/messages` API monitors (an upstream error whose message held one was not flagged). Tests: `tests/test_http_stream_sse_lines.py` (line-for-line parity with httpx `aiter_lines()` at every chunk boundary of a mixed CR / LF / CRLF stream, separators kept at every cut, stream closed, llama payload and monitor cases) plus end-to-end passthrough cases in `test_openai_passthrough_respawn.py` and `test_anthropic_passthrough_respawn.py`, which fail on main and pass here. The backend files with fakes of `aiter_lines()` (research runs, managed engines, subscription Responses client, tool confirm) pass unchanged; the failure set of every other file that failed in a loaded full run is identical on main and on this branch. Per event the new iterator costs about 1 us over httpx's. --------- Co-authored-by: Daniel Han <[email protected]>
Fixes #16721.
S3 audio dataset preparation aborts when a JSON Lines transcript contains literal U+0085, U+2028, or U+2029. Python's
str.splitlines()treats those characters as record boundaries even inside JSON strings.Split on LF after text-mode newline normalization. The regression test checks that both rows retain their transcripts and point to the downloaded audio for
.jsonland multi-record.jsonmanifests with LF and CRLF.This draft overlaps #16723 and carries explicit CRLF regression coverage.
Verification
test_s3_audio_dataset.pyandtest_s3_dataset.py. An additional eight local diagnostics using Hugging Face datasets 4.3.0 passed.git diff --checkpassed.