Skip to content

fix(a2a): parse multi-line SSE events - #1155

Open
mat973252-coder wants to merge 1 commit into
api7:mainfrom
mat973252-coder:zjz/fix-a2a-sse-frames
Open

fix(a2a): parse multi-line SSE events#1155
mat973252-coder wants to merge 1 commit into
api7:mainfrom
mat973252-coder:zjz/fix-a2a-sse-frames

Conversation

@mat973252-coder

@mat973252-coder mat973252-coder commented Sep 8, 2026

Copy link
Copy Markdown

Fixes #1143.

An A2A agent can split a JSON-RPC envelope across several data: fields in one SSE event. The relay previously parsed each line separately and terminated the stream on the first incomplete JSON fragment.

Buffer until the event's blank line, join its data fields with newlines, and parse the envelope once, following the SSE event-stream rules. This handles LF/CRLF framing and network chunk boundaries while ignoring comments and metadata. The existing 16 MiB limit now bounds the accumulated event. Existing compatibility for an unterminated final event is retained.

Malformed JSON is now reported when the complete event arrives, or at EOF, rather than after its first data line. Existing configurations need no changes.

Regression coverage includes multiline payloads, interspersed metadata, split CRLF/JSON writes, malformed JSON, and an oversized event made of individually small lines. The HTTP round-trip regression fails against the original reader with malformed JSON-RPC event and passes with this change.

Validation

Validated on Rust 1.93.1 in a Linux checkout, at commit 7f73bb63b569288a3284559dcbb28d741c911567:

  • cargo fmt --all --check passed.
  • cargo check --locked --workspace passed.
  • cargo clippy --locked --workspace -- -D warnings passed.
  • A2A: 34 unit tests and 23 HTTP integration tests passed.
  • cargo test --locked --workspace --no-fail-fast has one failing test: aisix-mcp::bridge::tests::connect_timeout_bounds_an_unreachable_upstream.

The same full-workspace test command, in the same environment, on unmodified upstream main (c8e96aa) fails only that same MCP test. It exceeds the test's eight-second bound while reaching the unreachable test address. No tests were skipped or weakened to hide this failure. Local proxy/network behavior affects this test, so this draft does not claim a green full-workspace test run; upstream CI still needs to validate it.

The separate repository E2E suite has not been run locally. This change is limited to the A2A reader and its tests.

Summary by CodeRabbit

  • Bug Fixes
    • Improved streaming event handling for responses split across multiple data fields or network chunks.
    • Correctly reassembles multiline event payloads, including streams using CRLF line endings and keep-alive messages.
    • Prevents oversized events from being processed and reports a clear stream error when the size limit is exceeded.

@CLAassistant

CLAassistant commented Sep 8, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 848ef253-620b-4e4a-ad27-f03ea2f78df7

📥 Commits

Reviewing files that changed from the base of the PR and between c8e96aa and 7f73bb6.

📒 Files selected for processing (2)
  • crates/aisix-a2a/src/bridge.rs
  • crates/aisix-a2a/tests/upstream_roundtrip.rs

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The SSE relay now buffers complete events, joins multiple data: fields with newlines, parses the combined JSON payload, and enforces the size limit across the full event. Tests cover multiline frames, chunk boundaries, CRLF input, comments, and oversized events.

Changes

SSE frame reassembly

Layer / File(s) Summary
Frame buffering and parsing
crates/aisix-a2a/src/bridge.rs
The reader buffers data until an SSE frame ends, enforces MAX_SSE_EVENT_BYTES across the complete frame, joins all data: fields, and parses the combined payload. Unit tests cover newline variants and malformed JSON.
Streaming integration coverage
crates/aisix-a2a/tests/upstream_roundtrip.rs
The streaming fixture emits multiline CRLF data across writes, including a split CRLF and comment line. A new test verifies that an oversized multiline event fails with a size-cap error.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 7f73b

A2A SSE streams can now carry JSON-RPC envelopes across multiple data fields without premature parse failures. The updated framing and size-limit behavior are covered by targeted unit and integration tests, with no current merge-blocking risk identified.

Suggested reviewers: jarvis9443, moonming

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: parsing multi-line SSE events for A2A.
Linked Issues check ✅ Passed The changes address issue #1143 by buffering complete SSE events, joining multiple data: fields with newlines, and parsing the combined JSON-RPC payload. The added tests cover multiline fields, framin…
Out of Scope Changes check ✅ Passed The source and test changes remain within the linked issue scope. The added regression tests directly validate multiline SSE parsing and event-size handling.
E2e Test Quality Review ✅ Passed PASS. The PR adds real HTTP integration coverage in crates/aisix-a2a/tests/upstream_roundtrip.rs: HttpBridge::send_stream talks to a locally spawned Axum upstream, and assertions verify three rela…
Security Check ✅ Passed No security-check failure was introduced. The commit changes only SSE parsing and regression tests in two A2A files. The parser buffers and caps events at 16 MiB, and malformed-event errors do not inc…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@mat973252-coder
mat973252-coder marked this pull request as ready for review September 8, 2026 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aisix-a2a: an SSE frame whose JSON-RPC envelope spans several data: lines fails the stream

2 participants