Skip to content

fix(studio): preserve Unicode separators in S3 JSON Lines transcripts - #16725

Merged
danielhanchen merged 2 commits into
unslothai:mainfrom
Max-Reisinger:fix/studio-s3-jsonl-unicode
Nov 6, 2026
Merged

danielhanchen merged 2 commits into
unslothai:mainfrom
Max-Reisinger:fix/studio-s3-jsonl-unicode

Conversation

@Max-Reisinger

Copy link
Copy Markdown
Contributor

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 .jsonl and multi-record .json manifests with LF and CRLF.

This draft overlaps #16723 and carries explicit CRLF regression coverage.

Verification

  • Four regression cases failed before the fix and passed afterward.
  • 70 tests passed across test_s3_audio_dataset.py and test_s3_dataset.py. An additional eight local diagnostics using Hugging Face datasets 4.3.0 passed.
  • Repository formatter, scoped Ruff check, and git diff --check passed.

@Max-Reisinger
Max-Reisinger marked this pull request as ready for review November 5, 2026 02:29
@danielhanchen danielhanchen self-assigned this Nov 6, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T11:08:38.569841Z 1315e07 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: bd3f38fd3b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 1315e07f8b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

danielhanchen added a commit to Imagineer99/unsloth that referenced this pull request Nov 6, 2026
@danielhanchen
danielhanchen merged commit 1b20b9e into unslothai:main Nov 6, 2026
tsautier pushed a commit to tsautier/unsloth that referenced this pull request Nov 15, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Studio S3 audio JSONL preparation fails on Unicode separators inside transcripts

2 participants