Skip to content

fix(sse): normalize CR/LF line endings in frame parser - #98

Open
xdeng-dev wants to merge 1 commit into
Continuum-AI-Corp:mainfrom
xdeng-dev:fix/sse-crlf-parsing
Open

xdeng-dev wants to merge 1 commit into
Continuum-AI-Corp:mainfrom
xdeng-dev:fix/sse-crlf-parsing

Conversation

@xdeng-dev

@xdeng-dev xdeng-dev commented Sep 14, 2026

Copy link
Copy Markdown

Orca-Code-Review — push 1

Severity Count
P0 0
P1 0
P2 0
P3 0

✅ no blocking findings

The W3C SSE spec allows \r\n, \r, or \n as line separators. Some upstream providers (Azure-hosted OpenAI models in particular) send \r\n\r\n as the frame delimiter.

Without normalization, OpenAIFrameStream._iter() never finds the \n\n boundary and buffers the entire response in memory until the connection closes — at which point it yields nothing to the protocol adapter. The client sees an empty stream.

Fix: normalize \r\n\n and \r\n in the buffer after each append, so all three line-ending forms are handled correctly.

Tests added:

  • test_sse_parses_crlf_frame_boundaries — CRLF-only frames
  • test_sse_parses_mixed_line_endings — mixed CRLF + LF
  • test_sse_parses_cr_only_line_endings — bare CR (classic Mac-style)

The W3C SSE spec allows \r\n, \r, or \n as line separators. Some upstream
providers (notably Azure-hosted OpenAI models) send \r\n\r\n as the frame
delimiter instead of \n\n. Without normalization the parser never detects
the frame boundary and buffers the entire response until the connection
closes, yielding nothing to the protocol adapter.

Normalize the buffer to \n after each append so all three line-ending
forms are handled correctly. Add regression tests covering CRLF,
mixed, and bare-CR frame boundaries.

@orcacode-review orcacode-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐳 OrcaCode Review

No findings — nothing to flag in this PR. Great work!

OrcaCode Review — Route Smarter. Ship Safer. Spend Less.
Engine-reported: 405 calls · 27M tokens · 99% cached

❤️ Share · Install OrcaCode Review

Free on GitHub — the review runs on your own OrcaRouter key. If it helped, a shout-out goes a long way.

Share: X · Reddit · LinkedIn
Follow: X · Discord · LinkedIn · OrcaRouter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant