Skip to content

Add HTTP SSE streaming clients (libcurl-backed) and JSON-RPC SSE support - #145

Merged
MisterVVP merged 47 commits into
mainfrom
dev-add-sse-streaming-support-to-clients
Jul 20, 2026
Merged

MisterVVP merged 47 commits into
mainfrom
dev-add-sse-streaming-support-to-clients

Conversation

@MisterVVP

@MisterVVP MisterVVP commented Jul 11, 2026 •

Copy link
Copy Markdown
Owner

Motivation

  • Provide production-quality SSE client streaming for HTTP+JSON and JSON-RPC so A2AClient::SendStreamingMessage and A2AClient::SubscribeTask work end-to-end over HTTP.
  • Reuse the shared libcurl HTTP infrastructure for streaming to avoid duplicate transport-specific implementations and to support deterministic testing and the wire performance driver.
  • Enforce correct SSE/HTTP/JSON(-RPC) protocol validation, cancellation, and safe stream lifecycle semantics so observers see exactly one terminal callback and no callbacks after handle destruction.

Description

  • Add a libcurl-backed streaming API a2a::http::Client::StreamRequest and a default factory MakeDefaultHttpStreamRequester() that implements HttpStreamRequester using incremental write callbacks, progress/cancellation checks, header/status preservation, and RAII cleanup.
  • Wire the default stream requester into HttpJsonTransport::CreateDefault(...) so HTTP+JSON streaming works without injectable requesters, and validate Content-Type: text/event-stream and HTTP status before delivering events.
  • Extend JsonRpcTransport with an injectable/retained HttpStreamRequester, implement StartSseStream(...) and use it for SendStreamingMessage and SubscribeTask, including JSON-RPC envelope construction, per-request ID generation/validation, incremental SSE parsing, and mapping JSON-RPC errors to core::Error.
  • Share SSE lifecycle helpers and parsing/dispatch logic (BuildJsonRpcEnvelope, DispatchJsonRpcSseEvent, RunJsonRpcSseWorker, HasSseContentType, terminal-state helpers) to ensure consistent behavior and single-call terminal callback enforcement across transports.
  • Update the wire performance driver and Python runner to include streaming scenarios for grpc, jsonrpc, and http_json, and update docs to describe HTTP+JSON and JSON-RPC SSE support, examples, and observer/threading/cancellation semantics.

@MisterVVP MisterVVP added the AI agent AI agent contribution label Jul 11, 2026 — with ChatGPT Codex Connector
@MisterVVP
MisterVVP marked this pull request as draft July 11, 2026 21:27
@MisterVVP MisterVVP self-assigned this Jul 11, 2026
### Motivation
- Provide production-quality SSE client streaming for HTTP+JSON and JSON-RPC so `A2AClient::SendStreamingMessage` and `A2AClient::SubscribeTask` work end-to-end over HTTP.
- Reuse the shared libcurl HTTP infrastructure for streaming to avoid duplicate transport-specific implementations and to support deterministic testing and the wire performance driver.
- Enforce correct SSE/HTTP/JSON(-RPC) protocol validation, cancellation, and safe stream lifecycle semantics so observers see exactly one terminal callback and no callbacks after handle destruction.

### Description
- Add a libcurl-backed streaming API `a2a::http::Client::StreamRequest` and a default factory `MakeDefaultHttpStreamRequester()` that implements `HttpStreamRequester` using incremental write callbacks, progress/cancellation checks, header/status preservation, and RAII cleanup.
- Wire the default stream requester into `HttpJsonTransport::CreateDefault(...)` so HTTP+JSON streaming works without injectable requesters, and validate `Content-Type: text/event-stream` and HTTP status before delivering events.
- Extend `JsonRpcTransport` with an injectable/retained `HttpStreamRequester`, implement `StartSseStream(...)` and use it for `SendStreamingMessage` and `SubscribeTask`, including JSON-RPC envelope construction, per-request ID generation/validation, incremental SSE parsing, and mapping JSON-RPC errors to `core::Error`.
- Share SSE lifecycle helpers and parsing/dispatch logic (`BuildJsonRpcEnvelope`, `DispatchJsonRpcSseEvent`, `RunJsonRpcSseWorker`, `HasSseContentType`, terminal-state helpers) to ensure consistent behavior and single-call terminal callback enforcement across transports.
- Update the wire performance driver and Python runner to include streaming scenarios for `grpc`, `jsonrpc`, and `http_json`, and update docs to describe HTTP+JSON and JSON-RPC SSE support, examples, and observer/threading/cancellation semantics.

### Testing
- Built the project with `cmake --build build -j2` and ran focused unit/integration tests: `json_rpc_transport_test` (streaming/SSE filters), `http_json_streaming_integration_test`, `sse_parser_test`, and `http_client_test`, all of which passed.
- Ran the Python performance runner unit tests `tests/scripts/performance_runner_test.py` and an end-to-end performance smoke (`A2A_PERF_TRANSPORTS=grpc,jsonrpc,http_json ... ./scripts/run_performance_tests.sh`) which produced expected wire rows for `SendStreamingMessage_FiniteStream` and `SubscribeToTask_FirstEventLatency` across transports with no errors.
- Ran repository validation: `./scripts/run_clang_format.sh` (format), `./scripts/run_clang_tidy.sh build` (lint), and the project `./scripts/verify_changes.sh`; initial clang-tidy issues found during development were fixed and the final validation completed successfully.
- Note: the mandatory TCK flow could not be executed locally because the checked-out TCK tooling did not expose a supported mandatory-suite entrypoint; the change is documented and the repository requires TCK mandatory conformance before push/merge in CI.
…cked streaming requester

### Motivation

- Provide production-quality SSE streaming for HTTP+JSON and JSON-RPC transports using the shared libcurl outbound HTTP stack so `SendStreamingMessage` and `SubscribeTask` work over HTTP without custom stream requesters.
- Centralize stream request plumbing, cancellation, and SSE validation to avoid duplicate logic and enable default requester injection similar to buffered calls.
- Update performance scenario selection and docs to reflect expanded transport streaming coverage.

### Description

- Added streaming abstractions: `HttpStreamRequester`, `HttpStreamChunkHandler`, `StreamCancelled`, and `MakeDefaultHttpStreamRequester()` and wired them into `HttpJsonTransport` and `JsonRpcTransport` constructors and `CreateDefault()` factories.
- Implemented libcurl-backed streaming support in the HTTP client by adding `Client::StreamRequest`, curl write/progress callbacks, and `StreamCallbackContext` for chunk delivery and cancellation/error propagation.
- Implemented SSE validations and dispatch: added `HasSseContentType`, SSE dispatch/error handling, and JSON-RPC SSE envelope parsing with `BuildJsonRpcEnvelope`, `DispatchJsonRpcSseEvent`, and `StartSseStream` to `JsonRpcTransport` so JSON-RPC over SSE is decoded into `StreamResponse` events.
- Updated `HttpJsonTransport` streaming flow to use the default stream requester, validate `text/event-stream` `Content-Type`, and dispatch SSE events to `StreamObserver` callbacks on the transport worker thread.
- Minor API updates: exposed `JsonRpcTransport` as a friend in `StreamHandle`, added stream-requester-taking overloads for transports, and updated `a2a::http` headers/structures to support streaming operations.
- Documentation updates to indicate SSE streaming uses the libcurl-backed default outbound HTTP requester and to document HTTP/JSON-RPC streaming semantics.
- Performance tooling changes to include streaming scenarios for HTTP transports and to restrict push-config wire scenarios to gRPC; updated test expectations accordingly.

### Testing

- Ran unit tests including `tests/unit/json_rpc_transport_test.cpp`, which exercises JSON-RPC SSE envelope parsing and error handling, and they passed.
- Ran integration tests including `tests/integration/http_json_streaming_integration_test.cpp` that validate SSE `Content-Type`, cancellation, error mapping, and they passed.
- Ran Python performance runner tests (`tests/scripts/performance_runner_test.py`) to verify scenario selection changes and they passed.
@MisterVVP

Copy link
Copy Markdown
Owner Author

@codex review this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 893b18396e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/http/http_client.cpp Resolved
Comment thread scripts/performance_runner.py Resolved
@MisterVVP MisterVVP added the human Human contribution label Jul 12, 2026
@MisterVVP

Copy link
Copy Markdown
Owner Author

@codex review this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c78ac16da4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/client/http_json_transport.cpp Resolved
Comment thread src/client/json_rpc_transport.cpp Resolved
@MisterVVP

Copy link
Copy Markdown
Owner Author

@codex review this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5085684f02

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/http/http_client.cpp Resolved
Comment thread src/client/json_rpc_transport.cpp Resolved
@MisterVVP

Copy link
Copy Markdown
Owner Author

Review threads are going to be addressed in new PR and merged into dev-add-sse-streaming-support-to-clients, then we can continue with more reviews here

…/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>
@MisterVVP

Copy link
Copy Markdown
Owner Author

@codex review this PR

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: ac860ac6d9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@MisterVVP

Copy link
Copy Markdown
Owner Author

Looks fine, but it makes sense to branch #143 from this and write perf tests.

### Motivation

- Enable full wire-level streaming performance coverage for
`SendStreamingMessage_FiniteStream` and
`SubscribeToTask_FirstEventLatency` across gRPC, HTTP+JSON and JSON-RPC
and capture wire-level streaming metrics (event counts, first-event
latency, completion latency).

### Description

- Record streaming metrics by extending `ScenarioResult` with
`event_count`, `first_event_latencies`, and `completion_latencies`, and
add an `OperationOutcome` return type for streaming-aware operations in
`RunMeasuredScenario` (`tests/performance/a2a_performance_driver.h`).
- Collect first-event and completion timestamps in the wire observer and
return those values from `ExecuteWireStreaming` and
`ExecuteWireSubscribeFirstEvent`
(`tests/performance/a2a_wire_performance_driver.cpp`).
- Emit streaming metrics into JSON report objects and add first-event /
stream-completion latency columns to generated CSV output
(`tests/performance/a2a_performance_common.cpp`,
`scripts/performance_runner.py`).
- Update performance runner tests to assert streaming rows include
`event_count`, `first_event_latency_ms`, and
`stream_completion_latency_ms` and CSV headers
(`tests/scripts/performance_runner_test.py`).
- Add a small helper to simplify a JSON-RPC streaming unit test and
reduce cognitive complexity for `clang-tidy`
(`tests/unit/json_rpc_transport_test.cpp`).
- Update documentation to reflect that finite streaming and first-event
subscription are covered on all wire transports and that streaming rows
record event counts and latency histograms
(`docs/performance-testing.md`).
@MisterVVP
MisterVVP marked this pull request as ready for review July 14, 2026 11:29
MisterVVP and others added 19 commits July 19, 2026 21:19
…/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>
### Motivation

- Enable full wire-level streaming performance coverage for
`SendStreamingMessage_FiniteStream` and
`SubscribeToTask_FirstEventLatency` across gRPC, HTTP+JSON and JSON-RPC
and capture wire-level streaming metrics (event counts, first-event
latency, completion latency).

### Description

- Record streaming metrics by extending `ScenarioResult` with
`event_count`, `first_event_latencies`, and `completion_latencies`, and
add an `OperationOutcome` return type for streaming-aware operations in
`RunMeasuredScenario` (`tests/performance/a2a_performance_driver.h`).
- Collect first-event and completion timestamps in the wire observer and
return those values from `ExecuteWireStreaming` and
`ExecuteWireSubscribeFirstEvent`
(`tests/performance/a2a_wire_performance_driver.cpp`).
- Emit streaming metrics into JSON report objects and add first-event /
stream-completion latency columns to generated CSV output
(`tests/performance/a2a_performance_common.cpp`,
`scripts/performance_runner.py`).
- Update performance runner tests to assert streaming rows include
`event_count`, `first_event_latency_ms`, and
`stream_completion_latency_ms` and CSV headers
(`tests/scripts/performance_runner_test.py`).
- Add a small helper to simplify a JSON-RPC streaming unit test and
reduce cognitive complexity for `clang-tidy`
(`tests/unit/json_rpc_transport_test.cpp`).
- Update documentation to reflect that finite streaming and first-event
subscription are covered on all wire transports and that streaming rows
record event counts and latency histograms
(`docs/performance-testing.md`).
… streaming_client example (#149)

### Motivation
- Close remaining coverage and example gaps for streaming (SSE parsing,
StreamHandle lifecycle, and production default-client usage) so the
HTTP+JSON and JSON-RPC streaming implementations have deterministic
tests and a runnable example.
- Provide a production-quality example that demonstrates
`HttpJsonTransport::CreateDefault(...)` and
`JsonRpcTransport::CreateDefault(...)` usage with bounded waits and
explicit cancellation semantics.

### Description
- Added extensive SSE parser unit tests in
`tests/unit/sse_parser_test.cpp` covering complete events, every-byte
splits, multi-event chunks, CRLF framing, `data:` spacing variants,
multiline `data:`, comments/heartbeats, ignored `id:`/`retry:`, empty
chunks, finalization, malformed fields, missing separators, callback
failure propagation, and empty-stream finalization.
- Added transport-neutral `StreamHandle` lifecycle regression tests in
`tests/unit/stream_handle_lifecycle_test.cpp` covering `IsActive()`,
idempotent `Cancel()`, double-cancel safety, destruction
cancellation/join behavior, at-most-once completion, and mutual
exclusion of error/completion.
- Reworked the public example `examples/apps/streaming_client/main.cpp`
to use production default HTTP+JSON and JSON-RPC transports, add a CLI
(`--transport`, `--endpoint`, `--operation`, `--task-id`,
`--timeout-ms`, `--cancel-after-first-event`), bounded observer waits,
and deterministic cancellation behavior.
- Updated example documentation
`examples/apps/streaming_client/README.md` and `docs/streaming-usage.md`
with build/run instructions and example commands, and updated the
example runner `scripts/run_examples.sh` to smoke-test
`streaming_client` via `--help` to avoid requiring a live server in
smoke runs.
- Registered the new test target in `tests/CMakeLists.txt`.

---------

Co-authored-by: Vladimir Pavlov <[email protected]>
…ests (#153)

### Motivation
- Prove libcurl-backed SSE streams can be cancelled promptly by the
client cancellation callback without relying on server closure.
- Ensure JSON-RPC SSE streams use unique request IDs and that
cross-stream response IDs are rejected exactly once.
- Verify no observer callbacks occur after a `StreamHandle` has been
destroyed and returned.

### Description
- Add a deterministic loopback SSE server and cancellable invocation
helper, and test that flipping the `is_cancelled` callback stops
`a2a::http::Client::StreamRequest()` promptly and prevents delivery of
later chunks (`tests/unit/http_client_test.cpp`).
- Add controlled JSON-RPC streaming harness that captures request
envelopes, generates sequential request IDs, verifies distinct IDs per
stream, rejects cross-stream responses with a single protocol error, and
accepts matching responses (`tests/unit/json_rpc_transport_test.cpp`).
- Add a late-callback requester and a test that destroys an active
`StreamHandle` then lets the requester attempt a late event to confirm
no observer callbacks happen after destruction returns
(`tests/unit/stream_handle_lifecycle_test.cpp`).
- Use bounded waits and synchronization primitives
(`std::condition_variable`, `std::atomic`, `std::future`) instead of
sleeps, and tidy up small return/value style issues to satisfy linters.
…:MisterVVP/a2a-cpp into dev-add-sse-streaming-support-to-clients
#154)

Update documentation, improve devex for windows users

## Summary

## Authorship and AI usage

Select every option that applies to substantive content included in this
pull request:

- [x] Contains substantive content written by a human
- [x] Contains substantive content generated by an AI agent

## Testing

## Checklist
- [x] `./scripts/verify_changes.sh` passed locally
- [x] Docs updated if behavior changed

---------

Co-authored-by: Vladimir Pavlov <[email protected]>
@MisterVVP

Copy link
Copy Markdown
Owner Author

@codex review this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 61c2dcbef6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread examples/apps/streaming_server/main.cpp Resolved
Comment thread examples/apps/streaming_server/main.cpp Resolved
Comment thread examples/apps/streaming_server/main.cpp Resolved
@MisterVVP

Copy link
Copy Markdown
Owner Author

@codex review this PR

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 5ea87ab3eb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@MisterVVP

Copy link
Copy Markdown
Owner Author

Looks good to go. New version and tag should be released after merge.

@MisterVVP
MisterVVP merged commit f8dfb54 into main Jul 20, 2026
17 checks passed
@MisterVVP
MisterVVP deleted the dev-add-sse-streaming-support-to-clients branch July 20, 2026 06:11
@github-project-automation github-project-automation Bot moved this from Todo to Done in a2a-cpp SDK Roadmap Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI agent AI agent contribution human Human contribution

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Feature]: Add SSE streaming support to HTTP+JSON and JSON-RPC clients

1 participant