Agent-to-Agent Protocols › Cancellation and the cancel-before-completion race

Michael BrenndoerferDecember 1, 20263 min read
Language AI HandbookAll chapters
Part 49 of 67Long-Horizon Agents and Interoperability
Chapter 378Agent-to-Agent Protocols › Cancellation and the cancel-before-completion race
Reading section 8 of 14 · Cancellation and the cancel-before-completion race · 3 minSection 8 of 14 · 3 min

Section 8 of 14 · 3 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

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]
CollapseExpand
Timeline diagram of caller and agent events showing cancel losing to completion.
Two interleaved timelines for the cancel-before-completion race. The caller sends a cancel (t2) while the agent finishes work (t3). Because the agent's completed transition commits before the cancel is processed (t4), the task's terminal state is completed and the simulated cancel does not change it.

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!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy