SSE decoder holds each event until the next network read #6

Closed
opened 2026-10-25 17:01:37 +00:00 by andreban · 0 comments
Owner

Problem

stream_generate_content delivers events late, so streamed output arrives in bursts or all at once at the end instead of as it is generated.

ServerSentEventsCodec::decode (src/network/event_source.rs) reads one line per call and returns Ok(None) after any line that doesn't end an event (data:, event:, ...). FramedRead treats Ok(None) as "need more bytes", so it waits for the next network read before calling decode again, even when the empty line that ends the event is already in the buffer.

As a result, each event is held back until more bytes arrive. When one read holds several events, they come out one per later read, and whatever is left is only flushed when the stream ends.

Fix

Loop in decode until an event is complete or no full line is left in the buffer. This is the same fix as andreban/geologia#24.

## Problem `stream_generate_content` delivers events late, so streamed output arrives in bursts or all at once at the end instead of as it is generated. `ServerSentEventsCodec::decode` (`src/network/event_source.rs`) reads one line per call and returns `Ok(None)` after any line that doesn't end an event (`data:`, `event:`, ...). `FramedRead` treats `Ok(None)` as "need more bytes", so it waits for the next network read before calling `decode` again, even when the empty line that ends the event is already in the buffer. As a result, each event is held back until more bytes arrive. When one read holds several events, they come out one per later read, and whatever is left is only flushed when the stream ends. ## Fix Loop in `decode` until an event is complete or no full line is left in the buffer. This is the same fix as andreban/geologia#24.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: andreban/gemini-rs#6