Repository navigation
fix(server): close cancellation streams on push failure - #554
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
muscariello
left a comment
There was a problem hiding this comment.
This closes a real gap: a cancel whose push delivery fails after CANCELED is committed returns early, and attached subscribers never see the end. Taking the write lock across the sequence assignment and the send, and dropping publishes once the snapshot is terminal, also stops a held-up older event from overwriting the cancellation. The gated push store test shows that race well.
- Subscribers get the push error, not the cancellation. On the failure path
active.publish(Err(&error), …)sends the delivery error to everyone watching, although the cancel succeeded and the delivery problem belongs to theCancelTaskcaller. The error is whatever the sender returned, for examplepush URL targets blocked hostasINVALID_PARAMS. Publishing the CANCELED status update (as #556 does) to subscribers and returning the push error only fromcancel_taskgives them the right final state. - One
?is patched, not the class.apply_event_to_task(…)?just above also returns beforefinish. A guard that finishes the attached execution on drop, next toReleaseOnDrop, would cover every early return. - This conflicts with #556 in
handler.rs; please rebase once that lands.
The cancel and push tests pass locally on this head.
Signed-off-by: andy <[email protected]>
Signed-off-by: andy <[email protected]>
Signed-off-by: andy <[email protected]>
cf3b3c9 to
ec7f2bb
Compare
muscariello
left a comment
There was a problem hiding this comment.
All three points are in, and the rebase is done. Subscribers now get the committed CANCELED update while the push error goes only to the caller. FinishCancelOnDrop covers the apply-error ?, the push failure and an aborted cancel call. After the rebase on #556, its empty-cancellation notification is folded into the guard (finish(!terminal_pushed)) and its regression test is kept. On this head a2a-server-lf passes (293 unit, 8 integration, 1 doc), the 30 cancel tests passed 25 runs in a row, and CI is green.
test_cancel_push_failure_ends_running_stream (a2aproject#554) read the stream's first item as the working status. Since the stream now begins with the Task object, the test takes the task id from that item and reads the working status second. Signed-off-by: Mohammad Hossein Khoshechin Jorshari <[email protected]>
…#587) * fix(a2a-server): begin a task stream with the task object Spec 3.1.2: "If the agent returns a `Task`, the stream MUST begin with the Task object". `send_streaming_message` relayed the executor's first event, and the examples, ITK and ACTS agents open with a status update. `start_execution` also returns the task the execution starts from (a new SUBMITTED task, or the stored task with the turn's message), taken before the executor starts. When the stream's first item is a status or artifact update, `send_streaming_message` emits that task first; it is the state before the update, so nothing is delivered twice. A first Task, a Message, an error, `send_message`, subscriptions and push notifications are unchanged. Fixes: a2aproject#585 Signed-off-by: Mohammad Hossein Khoshechin Jorshari <[email protected]> * docs(a2a-server): show the task first in the quickstart stream samples The streaming send now begins with the task. The quickstart's `SendStreamingMessage` sample has six events, the first a `task` in `TASK_STATE_SUBMITTED`, and the a2acli page's `send --stream` sample begins with a `State: SUBMITTED` block. Both match the greeter's output on this branch. Signed-off-by: Mohammad Hossein Khoshechin Jorshari <[email protected]> * test(a2a-server): expect the task first in the push-failure stream test test_cancel_push_failure_ends_running_stream (a2aproject#554) read the stream's first item as the working status. Since the stream now begins with the Task object, the test takes the task id from that item and reads the working status second. Signed-off-by: Mohammad Hossein Khoshechin Jorshari <[email protected]> * test(a2a-server): leave no unreachable line in the task-first tests The shape checks of the task-first tests, and the first-item check of the push-failure test, had a failure arm that never runs, which the patch coverage counted as uncovered lines. The tests now assert the stream's shape and take each item through one test macro, so the failure paths no longer occupy lines of their own. Signed-off-by: Mohammad Hossein Khoshechin Jorshari <[email protected]> --------- Signed-off-by: Mohammad Hossein Khoshechin Jorshari <[email protected]> Co-authored-by: Luca Muscariello <[email protected]>
Summary
When cancellation persists a task as
CANCELEDbut sending its cancellation event fails, the cancel request could return before notifying attached subscribers or removing the active execution. A stream could remain blocked, and an earlier event delayed in push delivery could subsequently restore an older active snapshot.CANCELEDstatus to attached subscribers and return the delivery error to the cancel caller.begin_cancelreturns, so errors applying cancel events and a dropped cancel future also finish the attached execution. The guard captures the runtime handle and resolves a pending registry lookup if necessary.The guard schedules asynchronous cleanup when dropped; it cannot guarantee cleanup after the Tokio runtime has shut down or when a custom
begin_cancelpersists its transition but is dropped before returning. The publicTaskStorecontract does not provide conditional updates, so this change does not guarantee atomicity between task persistence and cancellation for every custom store. An already in-flight webhook can also still arrive after cancellation.Rebased onto main after #556 merged, preserving its empty-cancellation notification and regression test.
Validation
cargo test -p a2a-server-lf --locked --offline: 293 unit tests, 8 integration tests, and 1 doc test passed.cargo clippy -p a2a-server-lf --all-targets --locked --offline -- -D warnings.cargo fmt --all -- --checkandgit diff --check.Tests used the local cached registry mirror and the installed macOS Command Line Tools SDK.