fix: decode every complete SSE event already in the buffer #7

Merged
andreban merged 1 commits from fix/sse-decode-loop into main 2026-10-25 17:04:22 +00:00
Owner

Fixes #6

Summary

  • ServerSentEventsCodec::decode now loops over lines until an event is complete, and returns Ok(None) only when no full line is left in the buffer. Before, it returned Ok(None) after every non-empty line, which made FramedRead wait for the next network read even though the rest of the event was already buffered.
  • An invalid retry: value now skips to the next line (continue) instead of returning early, so the event it belongs to is still returned.
  • The field parsing is unchanged, and so is the EOF behaviour (the default decode_eof). This is the same fix as andreban/geologia#24.

Testing

  • New unit tests in src/network/event_source_tests.rs:
    • two events in one buffer are both returned
    • a partial event is held until its blank line arrives
    • an invalid retry doesn't stop the event from being returned
  • All three fail on the old decode and pass with the fix.
  • cargo clippy --all-targets -- -D warnings and cargo test pass.
  • cargo fmt --check fails on main already, in examples/*, src/client.rs and src/client_tests.rs, none of which this PR touches. The files changed here are formatted.
  • Not yet manually tested: run examples/text-from-text-streaming.rs against Vertex AI and check that chunks print as they arrive instead of in bursts.
Fixes #6 ## Summary - `ServerSentEventsCodec::decode` now loops over lines until an event is complete, and returns `Ok(None)` only when no full line is left in the buffer. Before, it returned `Ok(None)` after every non-empty line, which made `FramedRead` wait for the next network read even though the rest of the event was already buffered. - An invalid `retry:` value now skips to the next line (`continue`) instead of returning early, so the event it belongs to is still returned. - The field parsing is unchanged, and so is the EOF behaviour (the default `decode_eof`). This is the same fix as andreban/geologia#24. ## Testing - New unit tests in `src/network/event_source_tests.rs`: - two events in one buffer are both returned - a partial event is held until its blank line arrives - an invalid `retry` doesn't stop the event from being returned - All three fail on the old `decode` and pass with the fix. - `cargo clippy --all-targets -- -D warnings` and `cargo test` pass. - `cargo fmt --check` fails on `main` already, in `examples/*`, `src/client.rs` and `src/client_tests.rs`, none of which this PR touches. The files changed here are formatted. - **Not yet manually tested:** run `examples/text-from-text-streaming.rs` against Vertex AI and check that chunks print as they arrive instead of in bursts.
andreban added 1 commit 2026-10-25 17:01:48 +00:00
fix: decode every complete SSE event already in the buffer
Some checks failed
Rust / build (pull_request) Failing after 8m5s
166bdefa89
decode returned None after each non-empty line, which makes FramedRead wait for more bytes before decoding again, so each event was held until the next network read. Loop until an event is complete or the buffer has no full line left.
andreban merged commit e64a748d5c into main 2026-10-25 17:04:22 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: andreban/gemini-rs#7