Preserve SSE events when CRLF separators span response chunks - #1036
Preserve SSE events when CRLF separators span response chunks#1036PeterDaveHello wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThe parser now preserves trailing-newline state and partial-line offsets across ChangesEventSource parser chunk handling
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
PR Summary by QodoPreserve SSE events when CRLF separators span response chunks
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTo customize comments, go to the Qodo configuration screen, or learn more in the docs. Previous review resultsReview updated until commit 532be8a Results up to commit d54be0b
|
Greptile SummaryThe PR preserves pending CRLF state across
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains in the changed parser behavior.
|
| Filename | Overview |
|---|---|
| src/utils/eventsource-parser.mjs | Persists the pending CRLF state between chunks, resets it with parser state, and resumes scanning from the correct buffer-relative offset. |
| tests/unit/utils/eventsource-parser.test.mjs | Adds focused regression and chunk-boundary equivalence tests for CRLF, LF, CR, mixed separators, and empty chunks. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[feed response chunk] --> B{Pending LF after CR?}
B -->|Yes, next byte is LF| C[Consume LF as part of CRLF]
B -->|No| D[Scan buffered SSE line]
C --> D
D --> E{Complete line found?}
E -->|No| F[Retain partial line and parser state]
E -->|Yes| G[Parse field or dispatch event]
F --> A
G --> H{More buffered input?}
H -->|Yes| B
H -->|No| A
Reviews (2): Last reviewed commit: "Preserve SSE events across arbitrary res..." | Re-trigger Greptile
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR fixes SSE parsing when \r\n line endings are split across multiple feed() chunks, and adds a unit test to prevent regressions.
Changes:
- Persist
discardTrailingNewlineacrossfeed()calls so a\narriving in a later chunk is correctly discarded after a trailing\r. - Add a unit test that feeds CRLF boundaries across multiple chunks and asserts correct event data output.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/unit/utils/eventsource-parser.test.mjs | Adds a regression test covering CRLF separators split across chunks. |
| src/utils/eventsource-parser.mjs | Moves discardTrailingNewline into parser state so CRLF handling works across feed() calls. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Response chunks may split a CRLF pair, so pending-CR state must survive feed() calls. The scanner must also resume at the current unconsumed position; otherwise a consumed CR can restore stale state and swallow a real event delimiter. Persist the pending delimiter state, scan only unconsumed input, and cover mixed line endings, empty chunks, and every single split point in a representative stream.
d54be0b to
532be8a
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/unit/utils/eventsource-parser.test.mjs`:
- Around line 82-125: Run npm run lint and fix the reported ESLint error in
src/content-script/index.jsx before committing. Keep the parser tests unchanged,
and only leave the lint failure unresolved if the pull request documents the
reason.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e40ad88c-3a5f-4241-a6fe-5d95f85f2847
📒 Files selected for processing (2)
src/utils/eventsource-parser.mjstests/unit/utils/eventsource-parser.test.mjs
🚧 Files skipped from review as they are similar to previous changes (1)
- src/utils/eventsource-parser.mjs
|
Security review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Code review by qodo was updated up to the latest commit 532be8a |
Problem
Response chunk boundaries are independent of SSE line boundaries. When a CRLF sequence is split after the
\r, the parser must remember that the next\nbelongs to the same line ending instead of treating it as an empty event delimiter.Persisting that state alone is not sufficient if the scanner restarts from the beginning of the buffer after consuming a line. Re-reading an earlier
\rcan recreate stale pending-CR state and swallow a real blank line from the next chunk.Changes
feed()calls and clear it onreset().Validation
node --test tests/unit/utils/eventsource-parser.test.mjs— 19 tests passed.node --checkpassed for the changed JavaScript modules.Summary by CodeRabbit
Bug Fixes
Tests