Skip to content

Make subscription coroutines wake-driven and awaitable - #235

Merged
MisterVVP merged 5 commits into
dev-optimize-server-side-sse-event-deliveryfrom
dev-make-server-subscriptions-coroutine-driven
Sep 1, 2026
Merged

MisterVVP merged 5 commits into
dev-optimize-server-side-sse-event-deliveryfrom
dev-make-server-subscriptions-coroutine-driven

Conversation

@MisterVVP

@MisterVVP MisterVVP commented Aug 31, 2026 •

Copy link
Copy Markdown
Owner

Motivation

  • 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.

Description

  • 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_awaits 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)

@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 marked this pull request as draft August 31, 2026 15:52
@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
@MisterVVP
MisterVVP marked this pull request as ready for review September 1, 2026 06:40
@MisterVVP
MisterVVP merged commit 6bb439a into dev-optimize-server-side-sse-event-delivery Sep 1, 2026
19 checks passed
@MisterVVP
MisterVVP deleted the dev-make-server-subscriptions-coroutine-driven branch September 1, 2026 06:40
MisterVVP added a commit that referenced this pull request Sep 1, 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]>
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