Skip to content

fix(streaming): handle mixed SSE line endings - #2309

Merged
HAYDEN-OAI merged 3 commits into
openai:mainfrom
weivwang:fix/mixed-sse-line-endings
Aug 13, 2026
Merged

HAYDEN-OAI merged 3 commits into
openai:mainfrom
weivwang:fix/mixed-sse-line-endings

Conversation

@weivwang

@weivwang weivwang commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor
  • I understand that most of this repository is generated and my pull request may not be merged as-is

Changes being requested

Recognize SSE event delimiters formed by consecutive LF, standalone CR, or CRLF line endings, including valid mixed combinations. A CR immediately followed by LF is one CRLF line ending, not two.

The incremental line decoder now emits CR-terminated lines immediately and remembers whether to consume one optional following LF. This preserves prompt event delivery when transport chunks split CRLF, avoids phantom blank lines, and keeps the existing optimized SSE scan window unchanged.

This changes only the handwritten streaming decoder and its focused regression coverage.

Why

LineDecoder already recognized all three SSE line-ending forms, but findDoubleNewlineIndex() recognized only LF+LF, CR+CR, and CRLF+CRLF. A valid mixed-ending stream such as data: first\n\r\n could therefore remain buffered on an open connection until another recognized delimiter or EOF.

Standalone-CR event delimiters could also be delayed because the decoder previously waited for another byte before emitting the completed line. Emitting immediately and suppressing a following optional LF fixes both standalone-CR and fragmented mixed-ending delivery.

Verification

  • Focused decoder and streaming checks: 65 tests passed, including all eight distinguishable valid delimiter combinations fragmented into individual bytes.
  • pnpm test:unit: 66 files and 1,774 tests passed after updating the branch with the latest main.
  • pnpm lint passed.
  • pnpm exec tsc --noEmit --pretty false passed.
  • pnpm build passed for CommonJS and ESM, including package import smoke checks.
  • Regression coverage includes open-stream delivery, split CRLF, phantom-event prevention, mixed multiline events, and incomplete versus complete records at EOF.

Vitest can rewrite unrelated legacy Jest snapshot headers locally; those mechanical changes are not included in this PR.

@weivwang
weivwang marked this pull request as ready for review August 13, 2026 12:37
@weivwang
weivwang requested a review from a team as a code owner August 13, 2026 12:37

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8563f8ab8c

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

Comment thread src/internal/decoders/line.ts Resolved
Comment thread src/internal/decoders/line.ts Resolved
@HAYDEN-OAI HAYDEN-OAI added the sdk label Aug 13, 2026

@HAYDEN-OAI HAYDEN-OAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved after reviewing the coordinated SSE scanner and incremental line-decoder changes, confirming the eight valid delimiter combinations across fragmented open streams, and verifying the updated branch against current main.

@HAYDEN-OAI
HAYDEN-OAI enabled auto-merge August 13, 2026 18:07
@HAYDEN-OAI

Copy link
Copy Markdown
Contributor

Thanks for the contribution and for spotting the gap in our SSE line-ending handling! We updated the implementation to cover fragmented mixed delimiters and immediate carriage-return delivery, and your PR is now approved with auto-merge enabled pending the required workflow approvals and checks.

@HAYDEN-OAI
HAYDEN-OAI added this pull request to the merge queue Aug 13, 2026
Merged via the queue into openai:main with commit 24d5ada Aug 13, 2026
15 checks passed
@openai-sdks openai-sdks Bot mentioned this pull request Aug 13, 2026

This branch was previously deployed

1 inactive deployment
ci — 7f476254 Deployed Aug 13, 2026 by HAYDEN-OAI via examples #7296
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants