Skip to content

fix(server): let SubscribeToTask follow a task that awaits input - #444

Merged
muscariello merged 3 commits into
stack/04-a2a-version-rest-grpcfrom
stack/05-subscribe-interrupted-task
Nov 2, 2026
Merged

muscariello merged 3 commits into
stack/04-a2a-version-rest-grpcfrom
stack/05-subscribe-interrupted-task

Conversation

@muscariello

@muscariello muscariello commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Fixes #393. Replaces #395. Stacked on #443: review only the last three commits.

Cause: subscribe_to_task only follows a task whose execution is still registered. An execution that ends in INPUT_REQUIRED or AUTH_REQUIRED is unregistered when the executor returns, so subscribing to a stored task that waits for input returns TaskNotFoundError, although GetTask returns it. §3.1.6 allows SubscribeToTask on any non-terminal task.

Fix: ExecutionManager keeps a waiting registry of subscriptions that found no execution. The next execution's start hands each one its broadcast channel before the executor runs. A subscription that is dropped early removes its own entry. The second commit ends waiting subscriptions when their task is canceled, since CancelTask runs no execution for them. The third releases them on every exit of CancelTask once the task is canceled, also when applying an executor event, sending a push notification or the final reload fails. Errors for missing and terminal tasks are unchanged.

Review focus: this adds shared state behind a std::sync::Mutex (waiting) next to the existing executions lock. The lock order and the "never held across an await" claim should be checked by hand.

Unproven: the new tests were run locally (fmt, clippy and the workspace tests pass at the top of the stack). The TCK results quoted in #395 (69 passed instead of 64) were not.

@codecov

codecov Bot commented Nov 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

gulldan and others added 3 commits November 2, 2026 14:03
`subscribe_to_task` resubscribed only to a task whose execution was
still registered. An execution that ends in an interrupted state
(INPUT_REQUIRED, AUTH_REQUIRED) is unregistered as soon as the executor
returns, and the task-store fallback turned only a terminal stored task
into UnsupportedOperationError, so a stored task that waits for input
was reported as TaskNotFoundError. A2A §3.1.6 allows subscribing to
any non-terminal task, and the stream must open with the task as it
stands.

A subscription that finds no registered execution is now registered
with the execution manager, under its lock and before the store is
read, so an execution that registers from then on attaches it: `start`
subscribes every waiter before the executor runs, so none of that
turn's events is missed, and from there the stream is an ordinary
resubscription. The stream opens with the stored task and ends where
the execution it attached to ends. A missing task is still
TaskNotFoundError, a terminal one still UnsupportedOperationError, and
a waiter dropped first unregisters itself.

Tested with handler unit tests (a turn that asks for input and one that
completes; two subscribers polled only after the next turn ran; a
dropped subscription; the unchanged errors), `just ci` on Linux, and
the official TCK against an agent built on the patched crates, where
STREAM-SUB-001/002 and STREAM-ORDER-002..004 now pass instead of being
skipped.

Fixes: #393

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: gulldan <5641375+gulldan@users.noreply.github.com>
A subscription to a task between turns waits for the task's next
execution. Cancelling such a task runs no execution, so the cancel's events
never reached the waiting subscription and its stream stayed open after the
task was canceled. CancelTask now hands the task's final snapshot to the
subscriptions still waiting, on success and when the executor's cancel
fails; a terminal snapshot ends their streams. Subscriptions register before
reading the store, so one that read the task before the cancel is waiting by
then, and one that reads it later finds it terminal.

The waiter stream drops a missing attachment with filter_map instead of an
arm no path reaches, and the tests assert whole event sequences.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: gulldan <5641375+gulldan@users.noreply.github.com>
CancelTask ended the subscriptions waiting on a task between turns when it
succeeded and when the executor returned an error. It did not when applying
an event, sending a push notification or reloading the task failed: the task
was already canceled in the store, but those subscribers stayed registered.
A guard created once the task is canceled releases them however the call
returns.

Signed-off-by: Luca Muscariello <muscariello@ieee.org>
@muscariello
muscariello force-pushed the stack/05-subscribe-interrupted-task branch from 479b701 to 07015ad Compare November 2, 2026 14:28
@muscariello
muscariello removed this pull request from stack #442 November 2, 2026 15:00
@muscariello
muscariello added this pull request to stack #456 November 2, 2026 15:01
@muscariello
muscariello added this pull request to the merge queue Nov 2, 2026
Merged via the queue into main with commit 1515cb5 Nov 2, 2026
43 of 45 checks passed
@muscariello
muscariello deleted the stack/05-subscribe-interrupted-task branch November 2, 2026 17:44
@github-actions github-actions Bot mentioned this pull request Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

a2a-server: SubscribeToTask on an input-required task answers TaskNotFoundError

3 participants