Skip to content

fix(streaming): decode CR-delimited server-sent events - #6439

Closed
oocheol wants to merge 2 commits into
lidge-jun:devfrom
oocheol:codex/sse-carriage-return-framing
Closed

oocheol wants to merge 2 commits into
lidge-jun:devfrom
oocheol:codex/sse-carriage-return-framing

Conversation

@oocheol

@oocheol oocheol commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The shared SSE decoder currently splits only at LF and drops or combines valid events framed with standalone CR. Recognize CR, LF and CRLF across chunk boundaries while preserving comments, EOF behavior and translator-budget cleanup.
  • Add focused regression coverage and update the source-owner contract plus English/Korean user documentation.
  • Independent branch from dev 8b23fe340a53799aac5ad7654582a75df7ade7c8; this PR contains only this change.

Verification

Validated on Windows with Bun 1.4.0 at current head 12d862cdf38b6088a93c32530917ca56f97f7182. The layout and file-size guards run from a fresh worktree with the default test budget; no guard, fixture directory, baseline cap, or timeout was changed.

  • bun run scripts/test.ts tests/responses/sse-carriage-return.test.ts tests/responses/sse-decoder.test.ts: PASS, 14 pass / 0 fail.
  • bun node_modules/typescript/bin/tsc --noEmit: PASS, exit 0.
  • bun scripts/structure-ssot.ts: PASS, exit 0.
  • bun scripts/privacy-scan.ts: PASS, exit 0.
  • bun run scripts/test.ts tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/file-size-ratchet.test.ts: PASS, 27 pass / 0 fail.

The first validation from the original Windows checkout failed on a pre-existing EPERM fixture directory and, in some runs, a five-second subprocess timeout. Those attempts remain historical failures; the fresh-worktree current-head guard result above replaces neither the failure record nor a required CI run. The first cold file-size scan for #6429 also exceeded five seconds, then passed at the same head on the same default budget. No inaccessible fixture was deleted and no test budget was raised.

Integration validation used actual local merges of all ten PR heads onto dev 03ed9a3b1c1535d25f8f47c3d6bf38db8ffc1fc9 (local-only assembled commit dd7d1fe254c3fc86144a2c3cce0ae483332b55bb). Owner-contract edits in runtime/config/usage now merge independently; shared observe.ts consumers merge without a source conflict. Additive EN/KO document-append conflicts and test-map insertion conflicts were reconciled by retaining both sections/registrations, not choosing one PR over another.

  • The combined 24-file focused regression set: 331 pass / 3 platform skips / 0 fail.
  • Combined layout and file-size guards: 27 pass / 0 fail with the default budget.
  • Combined typecheck, structure SSOT, privacy scan, generated operating surface check, and docs-site build: PASS.

Full bun run test and bun run test:changed remain unrun: nine small independently validated revisions plus a combined 24-file run share one Windows machine, so repeated full repository runs on each draft would be disproportionate. The explicit regression files cover the touched behavior and source-oracle consumers; broader platform/integration coverage remains for exact-head CI. Updated-head CI and automated review must be confirmed separately; older-head results, queued jobs, skipped jobs, and approval-pending runs are not passing evidence.

Review response: Documented the fixture collector and its assertion that decoder retention is released. Added function documentation addresses the warning in source; the remote coverage percentage is not claimed as rerun. All descriptions retain only the gate-managed canonical readiness checklist.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. No credential values, authentication policy, dependency installation, or workflow permissions are changed.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes
    • Server-sent event streams now correctly recognize LF, CRLF, and standalone CR line endings, including delimiters split across network chunks. Events can be delivered before the stream closes, and a final unterminated event is still processed.
  • Documentation
    • Updated English and Korean integration guides and technical documentation to describe supported streaming line endings.

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 1805fae4-af64-4f84-a6ea-8eb2a88351fe

📥 Commits

Reviewing files that changed from the base of the PR and between 780117f and 12d862c.

📒 Files selected for processing (1)
  • tests/responses/sse-carriage-return.test.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: e2071794-be14-443c-8803-5ad6034a690a

📥 Commits

Reviewing files that changed from the base of the PR and between 3d77e3d and 780117f.

📒 Files selected for processing (7)
  • docs-site/src/content/docs/guides/codex-integration.md
  • docs-site/src/content/docs/ko/guides/codex-integration.md
  • scripts/test-layout/layout.json
  • src/lib/sse-decoder.ts
  • structure/transports/byte-accounting.md
  • tests/fixtures/test-layout-expected.json
  • tests/responses/sse-carriage-return.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The SSE decoder now recognizes CR, LF, and CRLF line endings, including CRLF split across chunks. New tests cover delimiter handling and event dispatch. English and Korean guides and byte-accounting documentation describe the supported behavior.

Changes

SSE line endings

Layer / File(s) Summary
Delimiter recognition
src/lib/sse-decoder.ts
The decoder scans for CR and LF delimiters. It skips LF after CR, including when CRLF spans decoded chunks.
Behavior tests and documentation
tests/responses/sse-carriage-return.test.ts, scripts/test-layout/layout.json, tests/fixtures/test-layout-expected.json, docs-site/src/content/docs/guides/codex-integration.md, docs-site/src/content/docs/ko/guides/codex-integration.md, structure/transports/byte-accounting.md
Tests cover CR, LF, and CRLF framing, split delimiters, unterminated final events, and event delivery before stream closure. Documentation describes supported delimiters and related decoder behavior.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Suggested reviewers: lidge-jun

Merge Risk: ⚪ Minimal · up to 78011

The change appears ready for normal validation; no specific merge-blocking behavior has been identified.

Security Architecture Review

Security architecture risk: ⚪ Minimal · up to 78011

The change corrects event framing without introducing a new exposed interface or weakening the inspected validation and resource limits. No material security risk introduced or worsened by this change was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The relevant input surface is upstream SSE content processed through existing streaming-response paths. Malicious framing or oversized content would encounter the existing decoder budget and consumer validation; the change does not add a new listener or credential authority in the inspected paths.

Trust Boundaries and Controls

  • observed — Expanded delimiter recognition does not bypass the inspected downstream controls: chat outbound parses JSON and checks record shape, OpenAI passthrough validates objects and uses budgeted collectors, and Anthropic validates parsed records before recognized event-type dispatch.

Resilience and Maintainability Implications

  • observed — Yield and source-chunk finally blocks release their accounted allocations. The outer finally releases buffered line and event state, removes the abort listener, and attempts reader cancellation and lock release. Budget disposal remains the caller's responsibility.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (5 skipped: 5 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing SSE streaming to decode server-sent events delimited by standalone CR characters. It matches the implementation, tests, and documentat…
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (5 skipped: 5 unsupported.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (0/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 0/4).

Review readiness checklist

  • ⬜ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ⬜ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ⬜ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

0/4 boxes ticked.

This PR stays in draft until every box above is ticked.

@oocheol

oocheol commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Please review the current head 780117f87df233a3240a187ab827c03a41f3f1fc. The initial automatic review was skipped while the PR is in draft.

@coderabbitai review

@codex review

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@oocheol

oocheol commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Please review the current head 12d862cdf38b6088a93c32530917ca56f97f7182. The initial automatic review was skipped while the PR is in draft.

@coderabbitai review

@codex review

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

lidge-jun added a commit that referenced this pull request Oct 2, 2026
…ks (carry #6439) (#6446)

* fix(streaming): decode CR-delimited server-sent events

* fix: address review feedback for PR #6439

* fix(streaming): keep CR/LF delimiter search native and cover split CRLF framing

Carry follow-up for #6439. Replace the per-character delimiter loop with cached
indexOf cursors for the next CR and LF, so the shared decoder keeps native,
linear scanning on every provider stream. Add explicit cases for a CRLF split
between chunks (including an empty chunk in between), LFCR, many records in one
chunk for each framing, a UTF-8 code point split next to CR, and raw versus
escaped CR in data. Give the Korean guide section a Korean heading and record
the cursor search in the byte-accounting owner doc.

Co-authored-by: 정우철 <[email protected]>

---------

Co-authored-by: 정우철 <[email protected]>
@lidge-jun

Copy link
Copy Markdown
Owner

Thanks @oocheol — this landed on dev through the carry #6446 (with Co-authored-by credit), which keeps your CR/CRLF decoding and adds a split-CRLF case plus a linear scan. Closing as superseded.

@lidge-jun lidge-jun closed this Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants