Repository navigation
perf(streaming): reuse synchronous stream worker threads with bounded idle executor - #226
Merged
Conversation
…e-worker reservation (#227) ### Motivation - Two regressions caused timeouts after the reusable synchronous stream-worker change: gRPC `StreamHandle::Cancel()` inferred executor-backed execution from `worker_.joinable()` leading to waits that never complete after the owned worker was joined, and `StreamWorkerExecutor::Submit()` could observe the same idle worker multiple times and overcommit a single idle worker. - The intent is to make execution model explicit and make idle-worker assignment accurate without reverting the reusable synchronous stream-worker optimization. ### Description - Add an explicit `ExecutionMode` (enum) on `StreamHandle` and initialize/preserve it on construction and moves, and use it to decide whether to wait on `State::completion_condition` instead of inferring from `std::thread::joinable()`; this makes repeated `Cancel()` idempotent and avoids the gRPC destructor/blocking deadlock. (changes in `include/a2a/client/client.h` and `src/client/client.cpp`). - Fix idle-worker reservation in `StreamWorkerExecutor` by decrementing `idle_workers_` on `Submit()` when assigning a pending task to an idle worker and removing a redundant decrement in the worker loop so each idle worker is reserved for at most one submitted task. (change in `src/client/stream_worker_executor.cpp`). - Extend a focused unit test to cover repeated `Cancel()` on gRPC streams to prevent regressions. (change in `tests/unit/grpc_transport_test.cpp`). - Modified files: `include/a2a/client/client.h`, `src/client/client.cpp`, `src/client/stream_worker_executor.cpp`, and `tests/unit/grpc_transport_test.cpp`.
MisterVVP
marked this pull request as ready for review
August 27, 2026 19:21
MisterVVP
merged commit Aug 27, 2026
f26c4fa
into
dev-optimize-streaming-response-latencies
19 checks passed
MisterVVP
deleted the
dev-implement-reusable-synchronous-stream-worker-executor-jskguk
branch
August 27, 2026 19:21
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
StreamWorkerExecutorthat immediately creates a worker when no idle worker is available and retains at mostkMaximumRetainedIdleStreamWorkersidle workers (default 64).StreamHandleprivate state to use a per-stream completion token (completion_mutex,completion_condition,execution_thread_id,completed) so handles wait on task completion instead of owning an OS thread, preservingCancel(),IsActive(), move semantics and avoiding self-join deadlocks.StartSseStream/SendStreamingMessage/SubscribeTask) so sessions are executed on executor workers and per-stream completion is signalled on task exit; leave gRPC worker model unchanged.