Repository navigation
fix(api): assemble SSE lines from bytes before decoding UTF-8 - #223
Merged
Merged
Conversation
The Anthropic raw stream and the Codex provider each decoded every network chunk with from_utf8_lossy before splitting lines, so a codepoint split across chunks became U+FFFD, and a chunk ending right after a field line's newline produced a synthetic empty line that dispatched the frame early (in a live headless run the turn ended with "Model repeatedly ended without completing the turn"). Replace both copies with one crate-private SseLines decoder that keeps unfinished bytes and emits exactly one decoded line per real LF. Both production loops take a byte stream so tests can drive them directly. Per-provider CR trimming, event mappings, lossy handling of malformed UTF-8 and discarding unfinished frames at EOF are unchanged. Nine tests drive the real raw and Codex parser loops across every split position, one-byte chunks, 2/3/4-byte characters and CRLF. Coven-Harness: Claude Code / claude-opus-5-5
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
11 of 12 tasks
11 of 12 tasks
This branch was successfully 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
Fix SSE parsing in both streaming paths (Anthropic raw client and Codex provider). Unicode split across network chunks is no longer replaced with U+FFFD, and a chunk boundary right after a field line no longer dispatches a frame early.
Context
crates/api/src/lib.rs(process_sse_stream),crates/api/src/providers/codex.rs(stream parsing), and new crate-privatecrates/api/src/sse_lines.rs.stream_parserplaceholder types, and bounding pending line length (unbounded, as before).Changes
from_utf8_lossyper chunk, thensplit('\n'). That caused two defects:SseLines::feedscans withsplit_inclusive(b'\n'), keeps unfinished bytes, emits one decoded line per actual LF, and reuses its buffer. It is used by both loops.tx.closed()select and main's inner per-chunktx.closed()select. Only the line assembly changes.Surface (production lines excluding test modules): API lib 1262 -> 1247 (-15), Codex 976 -> 968 (-8), new helper 22, net -1. Two duplicated chunk-to-line algorithms become one private boundary.
Validation
cargo test --locked -p claurst-api: 74 + 5 passed, 0 failed (includes the 9 new tests and fix(api): stop the SSE reader when its receiver is dropped or closed #215'sstream_lifecycle).cargo fmt --all -- --check,cargo check --workspace --locked,cargo clippy --workspace --all-targets --locked -- -D warnings: pass on this branch (current main).git diff --check: clean.cargo test --workspace: hosted Rust CI.PR Readiness