Skip to content

feat(server): add request cancellation and deadline lifecycle - #315

Merged
MisterVVP merged 6 commits into
feat/async-serverfrom
feat/request-lifecycle-268
Oct 28, 2026
Merged

MisterVVP merged 6 commits into
feat/async-serverfrom
feat/request-lifecycle-268

Conversation

@MisterVVP

@MisterVVP MisterVVP commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

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 at include/a2a/server/engine/request_execution.h, with implementation and state in src/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.

  • Add a non-copyable RequestExecution owner and copyable RequestExecutionContext with an immutable snapshot of the existing RequestContext, monotonic deadline and C++20 cancellation token.
  • Choose exactly one terminal outcome atomically. Completion checks deadline expiry; cancellation observers run inline without an SDK mutex and retain safe state during reentrancy/owner destruction. Pending owner destruction signals shutdown.
  • Require the caller's scheduler to drive deadline notification. The API starts no timer or worker thread and leaves synchronous APIs unchanged.
  • Add 15 deterministic lifecycle tests covering metadata lifetime, pre-cancellation, late/removed observers, in-progress observer destruction, completion/cancellation races, deadline boundaries, shutdown and releasing the final owner from an observer. Include this optional target in the TSAN runner when available.
  • Probe C++20 cancellation support and export 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

  • Contains substantive content written by a human
  • Contains substantive content generated by an AI agent

Testing

Current-head validation: the engine target builds, all 15 lifecycle tests pass, and formatting, targeted clang-tidy, and mdbook build book pass. 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:

  • Clean Debug SDK build and CTest: zero failures across 790 cases (two TLS fixture skips).
  • 15 lifecycle tests pass with ThreadSanitizer and AddressSanitizer/UndefinedBehaviorSanitizer (detect_leaks=0; LeakSanitizer is restricted in this environment).
  • Repository formatting checks and mdbook build book pass.
  • Native cancellation capability probe passes; the forced-unavailable CMake graph excludes the new source/test and exports A2A_HAS_REQUEST_EXECUTION=0. TSAN target selection and shell syntax are verified in both configurations.
  • Unmodified upstream TCK d4d6fae7887f88ef607fb461c13e3b0e1802f19b passes 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 in book/src/compatibility/conformance.md; 21 MUST requirements have no upstream executable fixtures. This is not a claim of 100% TCK compliance.
  • Python validation-tool dependency audit reports no known vulnerabilities. The native OSV scan was attempted but its API endpoint is denied by the environment network policy; SDK dependency manifests are unchanged.
  • Performance smoke: gRPC/HTTP+JSON, in-memory store, two requests at concurrency one, no warmup/duration; 54 result rows and zero errors (Debug SDK build).
  • ./scripts/run_clang_tidy.sh build and A2A_VERIFY_POSTGRES=1 A2A_VERIFY_BUILD_DIR=build ./scripts/verify_changes.sh both exit 0. The exact CI clang-format --dry-run --Werror mechanism 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.sh passed locally before the final namespace/file relocation; scoped checks passed for the latest change
  • Docs updated if behavior changed

@MisterVVP MisterVVP added the AI agent AI agent contribution label Oct 27, 2026 — with ChatGPT Codex Connector

Copy link
Copy Markdown
Owner Author

@MisterVVP, PR 1 of #268 is ready for your review against feat/async-server. Validation results and the documented TCK baseline are in the PR description.

@MisterVVP MisterVVP self-assigned this Oct 28, 2026
Comment thread include/a2a/server/request_execution.h Resolved
@MisterVVP

Copy link
Copy Markdown
Owner Author

@codex review this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T08:44:39.811198Z 4cfaa84 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 4cfaa84de1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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

@MisterVVP
MisterVVP merged commit 44d927b into feat/async-server Oct 28, 2026
22 checks passed
@MisterVVP
MisterVVP deleted the feat/request-lifecycle-268 branch October 28, 2026 09:18
MisterVVP added a commit that referenced this pull request Oct 28, 2026
## 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI agent AI agent contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant