fix(translation): accept SSE data fields with no space after the colon - #447
fix(translation): accept SSE data fields with no space after the colon#447pucedoteth wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan includes up to 12 reviews per rolling hour; 11 remain after this review. WalkthroughThe SSE parser now accepts ChangesSSE parsing
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This change broadens SSE parsing to accept valid data fields without a space while preserving exact field matching and terminator handling. No actionable merge-blocking risk remains after normal checks and review. Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
The frame parser matched `data: ` with `strip_prefix`, so a `data:` line
without the space was dropped. The frame then decoded to `SseFrame::Empty`
and the event was silently lost, including a `data:[DONE]` terminator.
Per the SSE spec the field name is everything before the first colon and
a single leading space is stripped from the value, so the space is
optional framing rather than part of the delimiter. Parse the field name
and value around the first colon instead, keeping any space beyond the
first as payload, and treat a bare `data` line as an empty value.
Matching on the field name also stops a line such as `database: {...}`
from being read as a `data` field, which the old prefix match already
handled correctly and is now covered by a test.
Closes NVIDIA-NeMo#399
Signed-off-by: pucedoteth <119044801+pucedoteth@users.noreply.github.com>
89b0bed to
f7ad9ab
Compare
Closes #399.
Problem
parse_json_sse_framematched thedatafield with a literal prefix that includes the space:The SSE spec treats that space as optional framing, not part of the delimiter:
So
data:{"delta":"hi"}is a well-formed frame that this parser dropped. The frame then folded to an empty string and decoded toSseFrame::Empty, silently discarding the event — including adata:[DONE]terminator, which stopped being recognised as the end of the stream.Fix
Split on the first colon and match the field name, stripping at most one leading space from the value:
The
Nonearm covers the spec's other case — a field line with no colon is the field name with an empty value.Matching the field name rather than a prefix also keeps a line like
database: {...}from being read as adatafield. The oldstrip_prefix("data: ")already got that right by accident; it is now covered by a test so the new parsing can't regress it.Comment lines are unaffected: they are filtered before this point, and
:commentsplits to a field name of"", which does not matchdataeither way.Tests
Three tests added to the existing module in
sse.rs:parses_a_data_line_without_a_space_after_the_colon— the reported casedone_marker_is_recognised_without_a_space—data:[DONE]still terminates the streamfield_names_are_matched_exactly—database:is not adatafieldThe first two fail on
main:I also wrote a fourth test asserting that only one leading space is framing, then deleted it: this parser hands the value to
serde_json, which ignores leading whitespace, so the distinction is not observable here. The behaviour is still spec-correct, it just isn't something this function can demonstrate, and I would rather not leave a test that passes for the wrong reason.Gates
cargo fmt --all --checkcargo clippy --workspace --all-targets -- -D warningscargo test --workspace --exclude switchyard-pyuv run ruff check .All checks passed!uv run mypy switchyardSuccess: no issues found in 21 source filesTwo pre-existing failures in my environment, both verified identical on a clean checkout of
mainand unrelated to this change:cargo test --workspacefails to linkswitchyard-py(pyo3symbol(s) not found for architecture arm64— missing Python symbols in my local toolchain). Hence the--excludeabove; I did not touch that crate.uv run pytest tests/failstests/e2e/test_closed_book_proxy_integration.py, an e2e test that needs live services.Commit is signed off per DCO.
Summary by CodeRabbit