Skip to content

Add HTTP stream kind tracking, SSE framing improvements, and finite-stream diagnostics - #233

Merged
MisterVVP merged 2 commits into
dev-optimize-streaming-response-latenciesfrom
dev-optimize-server-side-sse-event-delivery
Sep 1, 2026
Merged

MisterVVP merged 2 commits into
dev-optimize-streaming-response-latenciesfrom
dev-optimize-server-side-sse-event-delivery

Conversation

@MisterVVP

@MisterVVP MisterVVP commented Aug 31, 2026 •

Copy link
Copy Markdown
Owner

Motivation

  • Distinguish finite versus live HTTP server streams so connection lifecycle and diagnostics can treat them differently.
  • Reduce repeated JSON/SSE envelope allocations and ensure consistent SSE framing for streaming JSON-RPC and REST endpoints.
  • Collect and expose finite-stream lifecycle metrics in the TCK SUT and performance tooling.

Description

  • Introduce HttpStreamKind enum and add stream_kind fields to RestResponse and HttpServerResponse, and propagate it via HttpServerResponseBuilder::FromRestResponse.
  • Mark streaming responses as kFinite or kLive in rest_transport.cpp and json_rpc_server_transport.cpp, and adjust HTTP connection handling to count finite-stream connections, completed finite streams, and connections reused after finite streams in tests/sut/tck_sut.cpp.
  • Change TaskSubscriptionService event storage to std::deque<std::shared_ptr<const lf::a2a::v1::StreamResponse>> to avoid expensive copies and return values by dereferencing shared pointers when delivering events.
  • Unify and optimize SSE framing logic by introducing BuildSseEvent/BuildSseJsonRpcPrefix/BuildSseJsonRpcEvent helpers, and use a reusable std::string chunk buffer when streaming SSE for both REST and JSON-RPC transports.
  • Extend the performance runner to parse additional HTTP diagnostics fields (http_finite_stream_connections, http_completed_finite_streams, http_finite_streams_per_connection, http_connections_reused_after_finite_stream), include them in CSV fieldnames, and document them in the performance README.
  • Update tests to assert new stream_kind values and add a unit test for reading the new finite-stream diagnostics in performance_runner_test.py.

@MisterVVP MisterVVP added the codex Automatic label added by codex agent. Should not be used label Aug 31, 2026 — with ChatGPT Codex Connector
@MisterVVP MisterVVP self-assigned this Aug 31, 2026
@MisterVVP MisterVVP added AI agent AI agent contribution performance Performance improvement related tasks based on benchmark results. Performance tests changes. and removed codex Automatic label added by codex agent. Should not be used labels Aug 31, 2026
…le (#235)

- Replace the coroutine-wrapped blocking wait with a genuinely
wake-driven coroutine state machine while preserving the coroutine-based
architecture.
- Provide a small internal awaitable/readiness primitive so
publication/cancel/shutdown can resume suspended subscription coroutines
without polling.
- Reduce shared mutable timeout state and remove blocking waits inside
the coroutine to enable future async server I/O integration.

- Preserve and strengthen `StreamResponseCoroutine` as the coroutine
abstraction by adding a promise-side condition variable and completion
notification, plus `Next()`/`NextFor()` adapters that wait on
coroutine-produced values rather than calling a blocking subscriber
wait. (files: `include/a2a/server/stream_response_coroutine.h`,
`src/server/task_subscription_service.cpp`)
- Introduce a small internal awaitable `SubscriberEventAwaitable` that
registers a continuation under the subscriber mutex and is resumed by
publication/cancellation/shutdown; `RunSubscription()` now `co_await`s
this awaitable instead of calling a blocking `WaitForPublishedEvent()`.
(file: `src/server/task_subscription_service.cpp`)
- Remove the shared `wait_timeout` mutation from subscriber state and
make synchronous `Next()` / `NextFor()` compatibility adapters call the
coroutine `Next()`/`NextFor()` which use the promise condition variable
for timeout semantics. (files:
`include/a2a/server/task_subscription_service.h`,
`src/server/task_subscription_service.cpp`)
- Add `SignalSubscriber()` to capture and resume continuations outside
of subscriber locks, and `WaitForResumes()` plus an `active_resumes`
counter so session destruction waits for any in-flight resume to finish
(prevents resume-after-destroy and double-resume races). (files:
`include/a2a/server/task_subscription_service.h`,
`src/server/task_subscription_service.cpp`)
- Preserve the queued `std::shared_ptr<const StreamResponse>` fan-out
representation and avoid copying semantics changes in the hot path.
(file: `include/a2a/server/task_subscription_service.h`)
- Keep coroutine readability and lifecycle semantics:
`RunSubscription()` still co_yields the initial current-task event and
then loops awaiting subscriber events, yielding published updates and
returning on terminal/closed. (file:
`src/server/task_subscription_service.cpp`)

---------

Co-authored-by: Vladimir Pavlov <[email protected]>
@MisterVVP
MisterVVP force-pushed the dev-optimize-server-side-sse-event-delivery branch from 6bb439a to 082e0c9 Compare September 1, 2026 06:44
@MisterVVP
MisterVVP marked this pull request as ready for review September 1, 2026 07:23
@MisterVVP
MisterVVP merged commit 38901c7 into dev-optimize-streaming-response-latencies Sep 1, 2026
19 checks passed
@MisterVVP
MisterVVP deleted the dev-optimize-server-side-sse-event-delivery branch September 1, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI agent AI agent contribution performance Performance improvement related tasks based on benchmark results. Performance tests changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant