Skip to content

P5: Support multi-line SSE data fields in provider stream parser #36

@wauputr4

Description

@wauputr4

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

  • Multi-line SSE data: fields are reconstructed with newline separators.
  • Single-line OpenAI-compatible stream chunks still parse exactly as before.
  • [DONE] events are still ignored as terminal markers.
  • Tests cover at least one valid multi-line SSE event and one normal single-line chunk event.
  • cargo fmt, cargo clippy --workspace --all-targets -- -D warnings, and cargo test --workspace pass.

Priority

P2. Do after the P1 buffering fix unless this falls out naturally while refactoring the parser for incremental streaming.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: providersProvider adapters and model routing integrationsbugSomething isn't workingrustPull requests that update rust code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions