Agent-to-Agent Protocols › Cancellation and the cancel-before-completion race
Language AI HandbookAll chapters The Cancel Task operation asks the server to stop an ongoing task. It can return the updated task or an error such as TaskNotCancelableError. The server may be unable to cancel work that has already completed or reached a point where cancellation is unavailable. A client can use GetTask to check the resulting state when an acknowledgment is lost or the cancel loses the race.
The example serializes two actions on an in-memory worker. When completion commits first, a later cancel leaves the completed task and its artifact intact. When cancel commits first, the worker does not publish a later artifact. This first-terminal rule is our local state-machine policy. The network protocol does not revoke an external side effect another service already committed. A production caller needs that service's operation status or its documented rollback policy before making a promise about the outside effect.
VisualizationOut [6]Expand

The resolution, completed, is what both sides must record. The caller's application logic, seeing completed, proceeds as if the cancel never happened. A caller that instead assumed "I sent cancel, so it's dead" would be wrong, and if the completed task had side effects, dangerously wrong. The safest client pattern is: after issuing a cancel, read the updated task or reconcile with a subsequent GetTask result within a bounded observation period.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!