Skip to content

Fix SSE stream concurrency and validate metadata-before-body for HTTP/JSON and JSON-RPC streams - #147

Merged
MisterVVP merged 18 commits into
dev-add-sse-streaming-support-to-clientsfrom
dev-fix-unresolved-review-threads-in-pr-#145
Jul 13, 2026
Merged

MisterVVP merged 18 commits into
dev-add-sse-streaming-support-to-clientsfrom
dev-fix-unresolved-review-threads-in-pr-#145

Conversation

@MisterVVP

@MisterVVP MisterVVP commented Jul 13, 2026 •

Copy link
Copy Markdown
Owner

Motivation

  • Prevent long-lived SSE streams from serializing other streams on the same shared libcurl easy handle by avoiding holding the shared handle/mutex across curl_easy_perform.
  • Ensure JSON-RPC and HTTP+JSON SSE transports validate response metadata (A2A-Version, HTTP 2xx status, exact text/event-stream media type) before any SSE body chunk is parsed or dispatched.
  • Keep the shared HTTP helper approach so transports reuse common protocol utilities for header/media-type handling.

Description

  • Use a per-stream RAII-managed libcurl easy handle (CurlEasyHandle) in a2a::http::Client::StreamRequest(...) so long-lived streams do not block other streams and no shared mutex is held across curl_easy_perform(...).
  • Extend the streaming requester contract with a metadata callback: add HttpStreamMetadataHandler and change HttpStreamRequester to accept on_metadata before chunk callbacks so metadata can be delivered prior to any body.
  • Make libcurl stream path invoke the metadata callback after headers/status are known (via ValidateStreamMetadata) and before the first body chunk is forwarded.
  • In HttpJsonTransport and JsonRpcTransport streaming workers, validate metadata-first (A2A-Version via shared ValidateResponseVersion, HTTP 2xx range, and exact SSE media type using shared core::http::IsSseContentType) and only allow parser feeding after metadata passes validation.
  • Preserve cancellation semantics and single-terminal-callback contract (exactly one OnError or OnCompleted, no events after terminal callback).
  • Keep unary SendRequest(...) unchanged with shared handle semantics (only streaming was changed to keep diff small).
  • Add deterministic tests and test helpers: per-stream concurrency test proving two streams do not serialize, and adjustments to existing HTTP+JSON and JSON-RPC streaming tests to exercise metadata-before-body and text/event-streaming rejection paths.

@MisterVVP MisterVVP added the AI agent AI agent contribution label Jul 13, 2026 — with ChatGPT Codex Connector
@MisterVVP MisterVVP self-assigned this Jul 13, 2026
@MisterVVP
MisterVVP merged commit ac860ac into dev-add-sse-streaming-support-to-clients Jul 13, 2026
16 checks passed
@MisterVVP
MisterVVP deleted the dev-fix-unresolved-review-threads-in-pr-#145 branch July 13, 2026 22:16
MisterVVP added a commit that referenced this pull request Jul 19, 2026
…/JSON and JSON-RPC streams (#147)

### Motivation

- Prevent long-lived SSE streams from serializing other streams on the
same shared libcurl easy handle by avoiding holding the shared
handle/mutex across `curl_easy_perform`.
- Ensure JSON-RPC and HTTP+JSON SSE transports validate response
metadata (`A2A-Version`, HTTP 2xx status, exact `text/event-stream`
media type) before any SSE body chunk is parsed or dispatched.
- Keep the shared HTTP helper approach so transports reuse common
protocol utilities for header/media-type handling.

### Description

- Use a per-stream RAII-managed libcurl easy handle (`CurlEasyHandle`)
in `a2a::http::Client::StreamRequest(...)` so long-lived streams do not
block other streams and no shared mutex is held across
`curl_easy_perform(...)`.
- Extend the streaming requester contract with a metadata callback: add
`HttpStreamMetadataHandler` and change `HttpStreamRequester` to accept
`on_metadata` before chunk callbacks so metadata can be delivered prior
to any body.
- Make libcurl stream path invoke the metadata callback after
headers/status are known (via `ValidateStreamMetadata`) and before the
first body chunk is forwarded.
- In `HttpJsonTransport` and `JsonRpcTransport` streaming workers,
validate metadata-first (A2A-Version via shared
`ValidateResponseVersion`, HTTP 2xx range, and exact SSE media type
using shared `core::http::IsSseContentType`) and only allow parser
feeding after metadata passes validation.
- Preserve cancellation semantics and single-terminal-callback contract
(exactly one `OnError` or `OnCompleted`, no events after terminal
callback).
- Keep unary `SendRequest(...)` unchanged with shared handle semantics
(only streaming was changed to keep diff small).
- Add deterministic tests and test helpers: per-stream concurrency test
proving two streams do not serialize, and adjustments to existing
HTTP+JSON and JSON-RPC streaming tests to exercise metadata-before-body
and `text/event-streaming` rejection paths.

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI agent AI agent contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant