Repository navigation
feat(server): add request cancellation and deadline lifecycle - #315
Conversation
|
@MisterVVP, PR 1 of #268 is ready for your review against |
|
@codex review this PR |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
## Summary Implements **Phase 2 / PR 2 of #268** against `feat/async-server`. Applications can initiate unary work and return immediately, then complete it from any thread through the new opt-in `a2a::server::engine::AsyncAgentExecutor` and `AsyncDispatcher`. - Supports SendMessage, GetTask, ListTasks, CancelTask, push-config create/get/list/delete, and extended agent cards through the existing provider. - Extracts one shared typed operation router and pipeline for sync/async payload checks, security, interceptor ordering, agent-card retrieval, and history projection. Required extensions use the existing validator. Public synchronous APIs remain source-compatible; each dispatch snapshots its interceptor list. - Uses a fixed worker pool and bounded in-flight admission. Pending application work holds no SDK worker. Executor initiation, hooks, policies/providers, and transport completion run on workers. The existing inline, non-blocking stop-observer contract is retained. - Delivers one terminal completion and one reverse-order AfterDispatch pass, including errors/cancellation. Completion receives an owned lifecycle context, so it is safe even before Dispatch returns its cancellation handle. Deadlines remain transport-driven, with start/completion checks. - Handles shutdown, late/duplicate replies, executor release, and dispatcher destruction from completion/cancellation observers. The existing security/store and agent-card provider facilities run on bounded workers; they retain their synchronous contracts. Adds API/threading documentation and immediate-result microbenchmarks. Native transport registration remains PR 3; #268 stays open. ## Authorship and AI usage - [ ] Contains substantive content written by a human - [x] Contains substantive content generated by an AI agent ## Testing - `A2A_VERIFY_POSTGRES=1 A2A_VERIFY_BUILD_DIR=build ./scripts/verify_changes.sh` — passed; **839 tests**. - Exact `./scripts/run_clang_tidy.sh build` and CI `clang-format --dry-run --Werror` mechanism — passed. New benchmark also passed targeted clang-tidy. - **49 fake-transport/component tests**, covering every operation, errors, metadata, security/history, extensions, admission, lifecycle races, and shutdown; 50 consecutive runs passed before the final test-guard cleanup. - TCK via `run_tck_sut.sh` / `run_tck_mandatory.sh` / `stop_tck_sut.sh`, with grpc/jsonrpc/http_json: **249 passed, 16 conditional skips on each of PostgreSQL and in-memory stores**. - `mdbook build book` — passed. - Required performance smoke: **54 rows, 0 errors**. - Python dependency audit — no known vulnerabilities. Native OSV scanning was attempted but this environment blocks `api.osv.dev`; SDK dependency versions are unchanged. The TCK retains the **previously approved baseline from PR #315**: **80.9% MUST / 80.0% overall coverage**, with 21 registered MUST requirements lacking upstream tests. All executable tests passed; this is not a claim of 100% specification compliance. Upstream TCK revision: `d4d6fae7887f88ef607fb461c13e3b0e1802f19b`. ## Performance evidence RelWithDebInfo, GCC 15, identical immediate in-memory GetTask response, one outstanding request, no interceptors/security; five repetitions with a 0.2 s minimum. The base comparison links the original dispatcher from `44d927b` with the same fixture and dependencies. | Path | Median wall time | | --- | ---: | | Original synchronous dispatcher | 0.408 µs | | Shared synchronous pipeline | 0.631 µs | | Async dispatcher, one SDK worker | 19.690 µs | The shared sync path adds approximately **0.22 µs (+55%)** in this microbenchmark, recorded explicitly for review. Async timing includes admission, lifecycle, queue scheduling and the benchmark's future-based reply handoff. These measurements cover immediate-result overhead; broader concurrency/latency evidence remains PR 4. The fake transport tests independently prove 32 pending operations can initiate on at most two SDK workers. ## Checklist - [x] `./scripts/verify_changes.sh` passed locally - [x] Docs updated if behavior changed
Summary
Introduce a transport-independent request lifecycle for pending asynchronous server operations, so applications can retain request metadata and distinguish client cancellation, deadline expiry, shutdown, success and application failure.
The complete request execution module uses
a2a::server::engine: public API atinclude/a2a/server/engine/request_execution.h, with implementation and state insrc/server/engine/.Implements PR 1 of #268. This PR leaves #268 open and keeps executor, dispatcher, transport, streaming and outbound-client integration for their planned follow-ups.
RequestExecutionowner and copyableRequestExecutionContextwith an immutable snapshot of the existingRequestContext, monotonic deadline and C++20 cancellation token.A2A_HAS_REQUEST_EXECUTION; omit the new implementation/tests on older standard libraries while preserving synchronous builds. Document availability, ownership, precedence, scheduling and observer lifetime guarantees in the server book.Authorship and AI usage
Testing
Current-head validation: the engine target builds, all 15 lifecycle tests pass, and formatting, targeted clang-tidy, and
mdbook build bookpass. The full SDK, TCK, sanitizer, and performance suites were not repeated for this final namespace/file relocation.Earlier full Linux validation, before the final namespace/file relocation:
detect_leaks=0; LeakSanitizer is restricted in this environment).mdbook build bookpass.A2A_HAS_REQUEST_EXECUTION=0. TSAN target selection and shell syntax are verified in both configurations.d4d6fae7887f88ef607fb461c13e3b0e1802f19bpasses across gRPC, JSON-RPC and HTTP+JSON on both in-memory and PostgreSQL stores: 249 passed, 16 conditional skips per store. MUST registry coverage remains 80.9%, matching the documented release baseline inbook/src/compatibility/conformance.md; 21 MUST requirements have no upstream executable fixtures. This is not a claim of 100% TCK compliance../scripts/run_clang_tidy.sh buildandA2A_VERIFY_POSTGRES=1 A2A_VERIFY_BUILD_DIR=build ./scripts/verify_changes.shboth exit 0. The exact CIclang-format --dry-run --Werrormechanism also passes (Clang 19).Local lifecycle benchmark (GCC 15,
-O2, median of 5 samples of 100,000 operations): metadata snapshot 72.7 ns/op; snapshot plus lifecycle/context/completion 159.1 ns/op. These measurements describe the new opt-in primitive, not network I/O or end-to-end async execution.Checklist
./scripts/verify_changes.shpassed locally before the final namespace/file relocation; scoped checks passed for the latest change