Skip to content

[Enhancement]: Add opt-in async server streaming and gRPC callback support #169

Open

Description

@MisterVVP

Problem

The synchronous gRPC streaming implementation supports existing applications and has received latency optimizations, but its compatibility path uses per-stream waiting machinery. The SDK also lacks a public, push-style asynchronous server-streaming contract. Merely moving a blocking ServerStreamSession::Next() call to another worker thread would preserve that scalability limitation.

Goal

Introduce an opt-in async streaming API and native gRPC callback-reactor streaming transport for SendStreamingMessage and SubscribeToTask. Preserve existing synchronous ServerStreamSession, AgentExecutor, Dispatcher, GrpcServerTransport and registration patterns.

Ownership and issue boundaries (v0.6.0)

Owns: Async server stream/session contract, demand and bounded backpressure, shared task subscription publication, and native gRPC callback reactors for both streaming operations.

Prerequisites and integration: Reuse #268 PR 1 transport-neutral cancellation/deadline model before finalizing the session contract; do not wait for #268 gRPC unary. #270 SSE subsequently consumes the stream API.

Must not absorb: Do not create a second cancellation context, blocking per-stream pump, HTTP/SSE socket handling (#270) or async unary dispatcher (#268). Maintain sync subscriptions.

Issue management: Keep this single issue; each checkbox below is intended as a separately reviewable PR. Do not implement later checkpoints in an earlier PR just to close the issue faster. Close the issue only after the final acceptance criteria pass.

Implementation PR checklist

  • PR 1 — Stream/session API and fake-sink tests: ownership, demand, ordered events, terminal outcome and cancellation races.
  • PR 2 — Shared task publication/subscription integration with mixed sync/async consumers and bounded buffering.
  • PR 3 — Native gRPC callback reactors for SendStreamingMessage and SubscribeToTask, with one in-flight write and once-only Finish/cleanup.
  • PR 4 — Native concurrency, slow-consumer, cancel/shutdown/interoperability tests, c64 thread/latency evidence, and opt-in docs.

PR merge rule: Each PR must have a narrow diff, behavior/lifecycle tests for its scope, and the applicable repository checks from AGENTS.md. Benchmark performance-sensitive changes against equivalent baseline configurations. Never describe blocking worker adaptation as non-blocking network/database I/O.

Detailed technical requirements and implementation phases

Phase 1 — Define and test the streaming API

  • Define AsyncServerStreamSession (or a similarly clear abstraction) and an opt-in async executor interface. The API must specify event ownership, one outstanding write/demand, event order, terminal completion, cancellation, and error propagation.
  • Prefer a single comprehensible completion model over mixing unrelated callbacks, futures and coroutines. The chosen design must compose with the request cancellation/deadline concepts of [Enhancement]: Add opt-in async unary server execution and cancellation #268 without making [Enhancement]: Add opt-in async unary server execution and cancellation #268's gRPC implementation a prerequisite.
  • Define how synchronous and asynchronous task subscriptions share the existing task publication core without duplicating stored event/history semantics.
  • Ensure cancellation and completion racing one another have exactly-once outcome semantics; callback/session lifetime is explicit.
  • Build contract tests using a fake transport/sink before changing gRPC transport scheduling.

Checkpoint: The API can be reviewed and tested without gRPC network changes.

Phase 2 — Native gRPC callback transport

  • Add a parallel asynchronous gRPC server path using callback reactors for the two streaming RPCs. Do not replace the synchronous transport.
  • Drive one write at a time, obey backpressure/demand, preserve event ordering, and send terminal status exactly once.
  • Propagate OnCancel() into the session promptly; call Finish() once and keep cleanup in OnDone() with safe object lifetime.
  • No blocking Next(), polling, sleep, watcher/pump thread, or application callback that blocks a gRPC callback thread.
  • Share metadata, required-extension handling, validation, protobuf conversion and error mapping with the synchronous path.

Checkpoint: The two async gRPC streams work correctly while legacy gRPC streams continue using their existing implementation.

Phase 3 — Interoperability and scalability

  • Exercise both sync and async subscription consumers against the same task publication flow.
  • Cover finite streams, long-lived subscriptions, concurrent stream cancellation, client disconnect, completion/cancel races, shutdown, and a slow consumer.
  • Validate thread scaling at representative concurrency (including c64), zero errors, first-event and completion latency; compare against the synchronous baseline with equivalent event counts.
  • Document how applications opt in and what API guarantees are provided.

Relationship to other issues

  • #270 owns the HTTP socket runtime and SSE framing. It may consume this async streaming API, but neither issue should implement the other's transport.
  • #268 owns async unary execution and general request cancellation/deadline semantics. Keep shared cancellation vocabulary consistent without combining implementations.
  • #269 concerns outbound clients, not server stream production.

Out of scope

  • Removing synchronous interfaces or requiring existing executors to implement async methods.
  • Creating a worker/pump thread per stream to adapt blocking sessions.
  • Implementing async unary RPCs, event-driven HTTP socket handling, or async PostgreSQL stores.
  • Redesigning the entire task/subscription model unless a narrowly justified shared invariant requires it.

Acceptance criteria

  • Existing synchronous streaming APIs and applications remain source-compatible.
  • Opt-in async streaming supports demand, ordered events, errors, cancellation, terminal delivery and safe shutdown.
  • Async gRPC uses callback reactors for both streaming operations, with at most one outstanding write per stream.
  • No per-stream SDK worker/watcher or blocking gRPC reactor operations exist on the async path.
  • Cancellation is immediate and idempotent; finish/cleanup happen exactly once under races.
  • Task subscriptions work in sync and async configurations using shared publication semantics.
  • Native concurrency and interoperability tests, mandatory TCK and required performance checks pass.
  • Benchmark evidence demonstrates bounded thread growth and documents the existing p95 ≤ 10 ms async completion target (or explicitly explains any inability to meet it under a comparable workload).

Activity

  1. added
    enhancement
    on Jul 23, 2026
  2. self-assigned this
    on Sep 13, 2026
  3. added this to the v0.6.0 milestone on Sep 21, 2026
  4. changed the title [-][Enhancement]: Add an opt-in asynchronous server-streaming API and gRPC callback transport[/-] [+][Enhancement]: Add opt-in async server streaming and gRPC callback support[/+] on Oct 11, 2026
  5. moved this from Todo to In Progress in a2a-cpp SDK Roadmapon Nov 1, 2026
  6. linked a pull request that will close this issueRelease v0.6.0 #322on Nov 1, 2026
  7. added a commit that references this issue on Nov 1, 2026
    2416a29
  8. moved this from In Progress to In Review in a2a-cpp SDK Roadmapon Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions