fix: emit complete SSE chunks immediately - #302
Open
OllieinCanada wants to merge 1 commit into
Open
Conversation
Signed-off-by: Oliver Slapinski <olliefromcanada@gmail.com>
OllieinCanada
marked this pull request as ready for review
August 15, 2026 23:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #301
Summary
Emit complete SSE events immediately when their blank-line delimiter ends at a network chunk boundary.
Root cause
The delimiter scanner skipped the final two-byte candidate, so
\n\nand\r\rat the end of a chunk were not recognized until more data arrived. The line decoder also retained a terminal carriage return even after the SSE chunker had identified a complete event block.Fix
Tests
A deterministic in-memory async stream verifies that events terminated by
\n\n,\r\r, and\r\n\r\nare emitted before the reader asks for another network chunk.Validation:
git diff --checkpassedNo external API or credentials were used.
Note
Low Risk
Internal streaming parser fix with focused regression tests; no API or auth changes.
Overview
Fixes delayed SSE delivery when a complete event’s blank-line delimiter (
\n\n,\r\r, or\r\n\r\n) lands at the end of a network chunk.findDoubleNewlineIndexnow scans through the last possible two-byte delimiter position (buffer.length - 1instead ofbuffer.length - 2), so trailing\n\n/\r\rat a chunk edge are recognized immediately._iterSSEMessagesflushes theLineDecoderafter each complete SSE block fromiterSSEChunks, so a terminal carriage return is not held until the next read.Adds regression tests in
streaming-utils.test.tsthat assert an event is yielded before the stream reader is asked for a second chunk for all three delimiter styles.Reviewed by Cursor Bugbot for commit 3575fa6. Bugbot is set up for automated code reviews on this repo. Configure here.