$/cancel_request notification
To make cancellation consistent, ACP defines a $/cancel_request notification that can be sent to cancel requests. Its requestId identifies a request that the sender of $/cancel_request issued. Receivers match it only against requests they received from that sender, since each side chooses its own request IDs.
$/cancel_request notification.
When a $/cancel_request notification is received by a supporting implementation, the implementation:
- MAY cancel the corresponding request activity and all nested activities related to that request
- MAY finish sending any pending notifications before responding
- MUST still send a response for the original request
$/cancel_request for a request ID that is unknown or already answered, and MUST NOT send a second response for it.
If the receiver does cancel the request, it sends one of these responses:
- A successful response, where the method defines one for cancellation:
session/promptafter its user message is inserted (with itsmessageId),session/request_permissionwith thecancelledoutcome, orelicitation/createwith thecancelaction - An error response with code
-32800(Request cancelled)
$/cancel_request for a session/request_permission or elicitation/create request it has not answered SHOULD dismiss the prompt and answer with the cancelled outcome or the cancel action. The Agent has stopped waiting for the user’s choice.
A sender that stops waiting for a response, for example after a timeout or because the work that needed it ended, SHOULD send $/cancel_request for that request so the receiver can stop work or dismiss UI. The calling side MAY implement graceful cancellation processing by waiting for the response from the remote side.
Cancellation can also be done explicitly on a per-feature basis within the protocol to cover specific scenarios, such as cancellation of active session work, one tool call, or one terminal.
session/cancel and $/cancel_request have different scopes. Cancelling one
permission or elicitation request does not automatically cancel the whole
foreground workflow or determine its state. The Agent applies the aggregate
state-transition rules.
On session/cancel, the Agent stops waiting for pending permission requests of the cancelled foreground work and MUST cancel each of them with $/cancel_request. The Agent decides which requests belong to that work. Clients MAY answer such a request with the cancelled outcome without waiting for $/cancel_request. After cancellation completes, Agents SHOULD ignore late
answers rather than use them to resume the cancelled work. When cancellation stops active foreground work,
the Agent MUST send that work’s final updates, then report idle with stopReason: "cancelled" before starting new foreground work in the same session.
Listed background work can continue reporting updates afterward. No additional idle update is required if
no foreground work was active. See Elicitation Cancellation
for selective cancellation of related requests and external URL interactions.
Internal cancellation
Requests can also be cancelled internally by the executing party without receiving$/cancel_request:
- On the Client, the user closes the IDE or switches projects, or a file becomes unavailable.
- On the Agent, an internal timeout fires or resources run out.
- Send the same response it would send for
$/cancel_request: the method’s defined cancellation result where one exists (an inserted prompt’smessageId, acancelledpermission outcome, or an elicitationcancelaction), otherwise-32800(Request cancelled) - Ensure consistent behavior regardless of cancellation source
session/prompt with -32800 only before the user message is inserted. Once it is inserted, the Agent responds successfully with its messageId, and the work it started is stopped with session/cancel or ends with the matching stop reason. See Prompt Accepted.
Example: cascading cancellation flow
Sendingsession/cancel does not automatically cancel outstanding Agent-to-Client requests. The Agent sends $/cancel_request for the permission requests of the cancelled work, as specified in active session work cancellation, and the Client answers each one with the cancelled outcome.