Context
PR #34 introduced a parser for OpenAI-compatible provider SSE chunks. A later review found that the parser joins repeated data: fields without inserting the newline separator required by the SSE event model.
Review source: #34
Problem
In crates/mizan-providers/src/lib.rs, parse_stream_events currently appends each data: field directly with push_str.
For valid SSE events that contain multiple data: lines, the parser reconstructs a different payload than the upstream sent. That can turn a valid provider stream into an invalid JSON payload and surface as a provider error.
This is lower risk than the buffering issue because OpenAI-compatible JSON chunks are often single-line, but provider compatibility matters if we want many upstreams and local servers to work cleanly.
Technical Direction
- Follow SSE semantics for repeated
data: fields by joining them with \n before decoding the event payload.
- Keep comment line handling (
:) and blank-line event boundaries intact.
- Keep
[DONE] handling unchanged.
- Add focused parser tests for multi-line
data: fields.
- Consider whether parser helpers should be split so incremental streaming work can reuse the same line/event assembly logic.
Acceptance Criteria
Priority
P2. Do after the P1 buffering fix unless this falls out naturally while refactoring the parser for incremental streaming.
Context
PR #34 introduced a parser for OpenAI-compatible provider SSE chunks. A later review found that the parser joins repeated
data:fields without inserting the newline separator required by the SSE event model.Review source: #34
Problem
In
crates/mizan-providers/src/lib.rs,parse_stream_eventscurrently appends eachdata:field directly withpush_str.For valid SSE events that contain multiple
data:lines, the parser reconstructs a different payload than the upstream sent. That can turn a valid provider stream into an invalid JSON payload and surface as a provider error.This is lower risk than the buffering issue because OpenAI-compatible JSON chunks are often single-line, but provider compatibility matters if we want many upstreams and local servers to work cleanly.
Technical Direction
data:fields by joining them with\nbefore decoding the event payload.:) and blank-line event boundaries intact.[DONE]handling unchanged.data:fields.Acceptance Criteria
data:fields are reconstructed with newline separators.[DONE]events are still ignored as terminal markers.cargo fmt,cargo clippy --workspace --all-targets -- -D warnings, andcargo test --workspacepass.Priority
P2. Do after the P1 buffering fix unless this falls out naturally while refactoring the parser for incremental streaming.