Repository navigation
Make subscription coroutines wake-driven and awaitable - #235
Merged
MisterVVP merged 5 commits intoSep 1, 2026
Conversation
MisterVVP
marked this pull request as draft
August 31, 2026 15:52
MisterVVP
marked this pull request as ready for review
September 1, 2026 06:40
MisterVVP
merged commit Sep 1, 2026
6bb439a
into
dev-optimize-server-side-sse-event-delivery
19 checks passed
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Description
StreamResponseCoroutineas the coroutine abstraction by adding a promise-side condition variable and completion notification, plusNext()/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)SubscriberEventAwaitablethat registers a continuation under the subscriber mutex and is resumed by publication/cancellation/shutdown;RunSubscription()nowco_awaits this awaitable instead of calling a blockingWaitForPublishedEvent(). (file:src/server/task_subscription_service.cpp)wait_timeoutmutation from subscriber state and make synchronousNext()/NextFor()compatibility adapters call the coroutineNext()/NextFor()which use the promise condition variable for timeout semantics. (files:include/a2a/server/task_subscription_service.h,src/server/task_subscription_service.cpp)SignalSubscriber()to capture and resume continuations outside of subscriber locks, andWaitForResumes()plus anactive_resumescounter 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)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)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)