Repository navigation
Description
Proposal
Add SSE streaming support to HTTP+JSON and JSON-RPC clients
Context
Repository: https://github.com/MisterVVP/a2a-cpp
Current PR: https://github.com/MisterVVP/a2a-cpp/pull/136
Related issue: https://github.com/MisterVVP/a2a-cpp/issues/112
Implementation guideline:
https://github.com/a2aproject/A2A/blob/main/docs/topics/streaming-and-async.md
The SDK already exposes transport-neutral streaming through A2AClient::SendStreamingMessage, A2AClient::SubscribeTask, StreamObserver, and StreamHandle.
gRPC already supports wire-level streaming. The remaining client gap is HTTP-based streaming:
HttpJsonTransportalready has SSE parsing and an injectableHttpStreamRequester, but its default client path does not provide a production streaming requester.JsonRpcTransport::SendStreamingMessageandJsonRpcTransport::SubscribeTaskcurrently return an unsupported-operation error.- Performance and integration tests therefore cannot exercise streaming over HTTP+JSON or JSON-RPC.
Goal
Implement production-quality SSE client streaming for:
- HTTP+JSON;
- JSON-RPC over HTTP.
Then add deterministic unit, functional, interoperability, and performance-driver tests for:
SendStreamingMessage;SubscribeToTask;- incremental event delivery;
- clean terminal completion;
- cancellation;
- protocol and transport errors.
Keep the task limited to streaming-client support and its tests. Do not expand it into push notifications, server redesign, or advanced multi-subscriber performance scenarios.
Protocol requirements
Follow the A2A streaming guidance:
- Servers advertise support through
capabilities.streaming: true. SendStreamingMessagestarts work and subscribes to updates in one call.- Successful HTTP streams return
HTTP 200withContent-Type: text/event-stream. - Each SSE
datafield contains the protocol response. - Events may contain:
Task;TaskStatusUpdateEvent;TaskArtifactUpdateEvent;- any other valid
StreamResponsevariant in the current schema.
- The server closes the stream after a terminal or interrupted state.
SubscribeToTaskis used to reconnect to an active task after a broken stream.- Network chunks are arbitrary. Never assume one SSE event or one JSON object per chunk.
Repository requirements
Before changing code:
- Read
AGENTS.md. - Read
cpp_conventions.md. - Follow the Google C++ Style Guide.
- Preserve the existing coroutine and streaming architecture.
- Avoid endless loops and unbounded waits.
- Prefer shared HTTP/SSE infrastructure over transport-specific duplication.
- Do not patch the external A2A TCK.
Required implementation
1. Add a production default HTTP streaming requester
Implement a default HttpStreamRequester backed by the shared libcurl HTTP infrastructure.
Add an API such as:
[[nodiscard]] HttpStreamRequester MakeDefaultHttpStreamRequester();Requirements:
- use libcurl streaming/write callbacks;
- pass bytes incrementally to
HttpStreamChunkHandler; - preserve status and response headers;
- support cancellation via
StreamCancelled; - stop promptly on cancellation;
- honor configured timeouts;
- apply request headers, auth, extensions, content type, accepted media type, A2A version, and mTLS behavior consistently;
- reuse shared curl initialization and connection infrastructure where practical;
- avoid global serialization;
- avoid busy waiting;
- return structured
core::Errorvalues; - release all curl resources through RAII;
- remain safe when the stream handle is destroyed while the request is active.
Do not regress normal non-streaming requests.
2. Enable default HTTP+JSON SSE streaming
Update HttpJsonTransport::CreateDefault so it configures both:
- the normal
HttpRequester; - the production
HttpStreamRequester.
A default transport must support:
SendStreamingMessage(...)
SubscribeTask(...)without dependency injection.
HTTP+JSON requirements:
SendStreamingMessageuses the REST streaming endpoint, currently/message:stream;SubscribeTaskuses the server's task-subscription endpoint;- send
Accept: text/event-stream; - serialize requests using existing protobuf JSON helpers;
- validate the HTTP status;
- validate
Content-Typecase-insensitively and allow parameters such astext/event-stream; charset=utf-8; - map non-2xx responses to
OnError; - treat invalid content type as a protocol error;
- call
OnCompletedexactly once after clean server closure; - do not report cancellation as normal completion;
- make
OnErrorandOnCompletedmutually exclusive.
3. Add JSON-RPC SSE streaming support
Extend JsonRpcTransport to accept and retain an HttpStreamRequester.
Preserve source compatibility where practical through overloads or defaults.
Update JsonRpcTransport::CreateDefault to configure normal and streaming requesters.
Implement:
JsonRpcTransport::SendStreamingMessage(...)
JsonRpcTransport::SubscribeTask(...)For each operation:
- Generate a request ID using the configured generator.
- Serialize a JSON-RPC 2.0 request envelope.
- POST it to the resolved JSON-RPC endpoint.
- Send:
Content-Type: application/json;Accept: text/event-stream.
- Parse SSE frames incrementally.
- Parse each
datafield as a JSON-RPC response envelope. - Validate:
jsonrpc == "2.0";- response ID matches the request ID;
- exactly one of
resultorerroris present; resultdecodes to the expected stream response.
- Deliver decoded events through
StreamObserver::OnEvent. - Convert JSON-RPC error envelopes to structured
core::Errorvalues and callOnError. - Complete only after a clean stream close.
Use existing shared method-name constants. Do not duplicate protocol strings.
4. Share SSE lifecycle logic
Avoid separate copies of:
- worker startup;
- cancellation;
- parser feeding;
- parser finalization;
- callback terminal-state enforcement;
- handle activity state;
- HTTP response validation.
Extract focused internal helpers where appropriate, for example:
BuildStreamingHttpRequest
RunSseRequest
ValidateSseResponse
DispatchRestSseEvent
DispatchJsonRpcSseEvent
CompleteStreamOnce
FailStreamOnce
Keep this internal unless public API expansion is necessary.
5. Preserve StreamHandle semantics
Verify and enforce:
IsActive()is true only while the request is active;Cancel()is idempotent;- handle destruction requests cancellation and joins safely;
- callbacks do not occur after destruction completes;
OnCompleted()is called at most once;OnError()is called at most once;- errors are not followed by completion;
- cancellation does not deadlock;
- cancellation from an observer callback is either safely supported or explicitly prevented and tested.
Keep the observer lifetime contract accurate.
6. Handle SSE framing correctly
Use and extend the existing SSE parser as needed.
Support and test:
\n\ndelimiters;\r\n\r\ndelimiters;- chunks split at arbitrary byte positions;
- multiple events in one chunk;
data:with an optional leading space;- multiline
data:fields; - comment/heartbeat lines beginning with
:; - optional
event:fields; - empty chunks;
- a final complete event before closure;
- malformed payloads;
- incomplete events at premature closure.
Never parse raw network chunks directly as JSON.
7. Capability behavior
Do not create a separate Agent Card cache solely for this task.
Use the existing discovery/capability layer if capability checks already belong there. Otherwise document that transport instances validate server behavior while capability checks remain the caller or client-factory responsibility.
Tests
8. SSE parser tests
Add or expand tests for:
- one complete event;
- an event split across chunks;
- splitting at every byte boundary;
- multiple events in one chunk;
- CRLF framing;
- multiline data;
- comments/heartbeats;
- malformed fields;
- incomplete final frames;
- parser finalization.
9. Default HTTP streaming requester tests
Use a deterministic local HTTP server.
Cover:
- correct request body and headers;
- incremental chunks;
- returned status and headers;
- cancellation;
- timeout;
- chunk-handler failure;
- connection failure;
- clean server close;
- cleanup after success and failure.
Do not use internet access.
10. HTTP+JSON transport tests
Cover both streaming operations:
- valid task event;
- valid status update;
- valid artifact update;
- multiple events;
- arbitrary chunk splitting;
- successful completion;
- cancellation;
- non-2xx response;
- missing or invalid content type;
- malformed JSON;
- malformed SSE;
- correct error callback;
- auth, extensions, timeout, and mTLS behavior;
- correct endpoints and methods;
CreateDefaultprovides a working stream requester.
11. JSON-RPC transport tests
Cover:
- correct request envelope;
- correct streaming and subscribe method names;
- unique request IDs;
- matching and mismatched response IDs;
- missing response ID;
- invalid JSON-RPC version;
- both
resultanderror; - neither
resultnorerror; - JSON-RPC error envelopes;
- valid task/status/artifact events;
- malformed results;
- arbitrary SSE chunk splitting;
- clean completion;
- cancellation;
CreateDefaultprovides a working stream requester;- existing unary behavior remains unchanged.
12. Functional tests with the real C++ SUT
For both HTTP+JSON and JSON-RPC:
Send streaming message
- Start the local SUT.
- Construct the default transport.
- Call
SendStreamingMessage. - Wait with a bounded timeout.
- Verify at least one event.
- Verify the expected terminal result or update.
- Verify
OnCompleted. - Verify no error callback.
Subscribe to task
- Create a non-terminal task.
- Call
SubscribeTask. - Publish an update.
- Verify the observer receives it.
- Transition the task to a terminal state.
- Verify terminal delivery and completion.
Cancellation
- Start an active stream.
- Cancel through
StreamHandle. - Verify prompt unblocking.
- Verify no later events after cancellation settles.
Use explicit deadlines only.
13. Cross-runtime interoperability
Add at least one mixed-runtime or protocol-fixture SSE test for each HTTP-based transport.
The test must prove the C++ client accepts spec-compliant SSE not generated by its own server implementation.
Extend an existing Python fixture only as much as necessary.
14. Performance-driver coverage
Update the wire performance driver so these scenarios run for all three transports:
SendStreamingMessage_FiniteStream;SubscribeToTask_FirstEventLatency.
Remove the temporary exclusion for jsonrpc and http_json.
Requirements:
- use production default clients;
- reuse clients per worker where safe;
- consume finite streams completely;
- measure first-event latency;
- count events;
- fail on malformed, missing, or incomplete streams;
- use bounded operation timeouts.
Do not add advanced multi-subscriber, disconnect, or terminal-completion performance scenarios in this task.
15. Documentation
Update client, streaming, and performance documentation.
Document:
- HTTP+JSON SSE support;
- JSON-RPC SSE support;
SendStreamingMessage;SubscribeTask;- observer callback threading;
- handle cancellation and lifetime;
- streaming capability expectations;
- terminal completion;
- resubscription;
- timeout configuration;
- concise examples for both HTTP transports.
Remove the statement that JSON-RPC and HTTP+JSON streaming clients are unsupported.
Non-goals
Do not include:
- push notifications;
- callback servers;
- advanced wire subscription performance scenarios;
- server transport redesign;
- unrelated gRPC changes;
- performance thresholds;
- external TCK patches;
- unrelated refactoring.
Acceptance criteria
-
HttpJsonTransport::CreateDefaultsupports SSE without injection. -
JsonRpcTransport::CreateDefaultsupports SSE without injection. - HTTP+JSON
SendStreamingMessageworks end to end. - HTTP+JSON
SubscribeTaskworks end to end. - JSON-RPC
SendStreamingMessageworks end to end. - JSON-RPC
SubscribeTaskworks end to end. - JSON-RPC SSE envelopes and response IDs are validated.
- Task, status, and artifact events are decoded.
- Arbitrarily split chunks are parsed correctly.
- Clean closure calls
OnCompletedexactly once. - Errors call
OnErrorexactly once and are not followed by completion. - Cancellation is prompt, idempotent, and deadlock-free.
- Handle destruction safely stops active work.
- Unit tests cover parser, requester, transports, errors, and cancellation.
- Functional tests use default clients and the local SUT.
- At least one cross-runtime or protocol-fixture SSE test exists.
- Wire performance streaming runs for gRPC, HTTP+JSON, and JSON-RPC.
- Unary client behavior does not regress.
- gRPC streaming does not regress.
- Documentation is updated.
- Repository validation and mandatory TCK checks pass.
Validation
Run the repository-required checks from AGENTS.md.
At minimum:
mapfile -t CPP_FILES < <(git ls-files '*.h' '*.hpp' '*.c' '*.cpp')
if [ "${#CPP_FILES[@]}" -gt 0 ]; then
clang-format --dry-run --Werror "${CPP_FILES[@]}"
fi
./scripts/verify_changes.shRun focused tests for:
SSE parser
default HTTP streaming requester
HTTP+JSON transport
JSON-RPC transport
client functional streaming
cross-runtime HTTP streaming
performance runner
wire performance driver
Run a performance smoke matrix:
A2A_PERF_TRANSPORTS=grpc,jsonrpc,http_json \
A2A_PERF_STORE_BACKENDS=inmemory \
A2A_PERF_REQUESTS=2 \
A2A_PERF_CONCURRENCY=1 \
A2A_PERF_WARMUP_SECONDS=0 \
A2A_PERF_DURATION_SECONDS=0 \
A2A_PERF_REPORT_DIR=perf-artifacts-streaming-smoke \
./scripts/run_performance_tests.shVerify successful wire rows exist for:
SendStreamingMessage_FiniteStream / grpc
SendStreamingMessage_FiniteStream / jsonrpc
SendStreamingMessage_FiniteStream / http_json
SubscribeToTask_FirstEventLatency / grpc
SubscribeToTask_FirstEventLatency / jsonrpc
SubscribeToTask_FirstEventLatency / http_json
Run the mandatory TCK flow from AGENTS.md and confirm 100% mandatory conformance before pushing.
Deliverables
- Production default libcurl streaming requester.
- Default SSE support in
HttpJsonTransport. - SSE support in
JsonRpcTransport. - Shared safe stream lifecycle logic.
- Unit tests.
- Functional tests.
- Cross-runtime or protocol-fixture tests.
- Wire performance coverage for basic streaming on all three transports.
- Updated documentation.
- Passing repository validation and TCK conformance.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity