You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Mechanisms for request cancellation"
4
+
---
5
+
6
+
ACP uses JSON-RPC 2.0 for making requests and getting responses.
7
+
8
+
The JSON-RPC specification doesn't define any standard mechanism for request cancellation and keeps it up to the implementation.
9
+
10
+
## `request/cancel` Notification
11
+
12
+
In order to provide a consistent approach to cancellation, ACP defines a `request/cancel` notification that can be sent to cancel requests if the recipient declared support.
13
+
14
+
- A party **MAY** declare `{ cancellationCapabilities: {} }` in their capabilities to handle `request/cancel` notifications for their requests.
15
+
- If an implementation declares support, it **MUST** handle `request/cancel` notifications for its requests.
16
+
- The other party **MAY** send `request/cancel` to cancel requests if the recipient declared support.
17
+
- If an implementation does not declare support, `request/cancel` notifications **SHOULD** be ignored.
18
+
- Either party **MAY** send `request/cancel` regardless of if they declare support themselves, as long as the recipient supports cancellation.
19
+
- Until capabilities are exchanged, requests **MUST NOT** be cancelled. The `initialize` request cannot be cancelled as it occurs before capability exchange.
20
+
21
+
Cancellation will remain optional as it might not be implementable in all clients or servers. For example if the implementation uses a single threaded synchronous programming language then there is little it can do to react to a `request/cancel` notification.
22
+
23
+
When a `request/cancel` notification is received by a supporting implementation, the implementation:
24
+
25
+
-**MUST** cancel the corresponding request activity and all nested activities
26
+
-**MAY** choose how quickly to honor cancellation requests. For example, they may finish sending any pending notifications before responding
27
+
-**MUST** send one of these responses for the original request:
28
+
- A valid response with appropriate data (such as partial results or cancellation marker)
29
+
- An error response with code [`-32800` (Request Cancelled)](./schema#errorcode)
30
+
31
+
The calling side **MAY** implement graceful cancellation processing by waiting for the response from the remote side.
32
+
33
+
Cancellation **MAY** also be done explicitly on a per-feature basis within the protocol to cover specific scenarios (e.g., cancellation of a [prompt turn](./prompt-turn#cancellation))
34
+
35
+
## Internal Cancellation
36
+
37
+
Requests can also be cancelled internally by the executing party without receiving `request/cancel`:
38
+
39
+
-**Client-side examples**: User closes IDE, switches to different project, file becomes unavailable
Copy file name to clipboardExpand all lines: docs/rfds/request-cancellation.mdx
+45-41Lines changed: 45 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ This creates the following inconveniences:
20
20
21
21
## What we propose to do about it
22
22
23
-
Implement an **optional**`$/cancelRequest` notification method (inspired by the Language Server Protocol) that uses JSON-RPC 2.0 notification format, allowing either party (client or agent) to cancel any outstanding request by its ID.
23
+
Implement an **optional**`request/cancel` notification method (inspired by the Language Server Protocol) to both Agent and Client that uses JSON-RPC 2.0 notification format, allowing either party (client or agent) to cancel any outstanding request by its ID.
24
24
25
25
The mechanism will be:
26
26
@@ -39,10 +39,10 @@ Once implemented, this enables:
39
39
-**SDK integration layer**: Default mechanism that ACP SDKs can automatically wire to native language cancellation (C# CancellationToken, Kotlin Job, Go context.Context, JavaScript AbortController, etc.)
40
40
- Individual JSON-RPC request cancellation without affecting other concurrent requests
41
41
- Universal fallback for any request when feature-specific cancellation methods don't exist
42
-
- Consistent cancellation behavior from both external `$/cancelRequest` and internal cancellation triggers
42
+
- Consistent cancellation behavior from both external `request/cancel` and internal cancellation triggers
43
43
- Standard error response (`-32800`) or partial results when requests are cancelled regardless of cancellation source
44
44
45
-
The mechanism complements existing `session/cancel`for prompt turns while providing granular per-request control.
45
+
In a future version, we could potentially deprecate the `session/cancel`notification in favor of the more general approach, as it would still provide the same functionality but with more flexibility and consistency.
Supplying `{}` will indicate that cancellation is supported, while following the same pattern elsewhere for allowing more granular capabilities in the future.
70
+
69
71
#### Cancellation Method
70
72
71
-
Add the `$/cancelRequest` notification method to the JSON-RPC protocol:
73
+
Add the `request/cancel` notification method to the JSON-RPC protocol:
72
74
73
75
```typescript
74
76
interfaceCancelNotification {
75
-
method:"$/cancelRequest";
77
+
method:"request/cancel";
76
78
params: {
77
79
requestId:string|number; // ID of request to cancel
When internal cancellation occurs, the executing party **SHOULD**:
122
126
123
-
1. Stop the request processing immediately
124
-
2. Send the same `-32800` (Cancelled) error response as if `$/cancelRequest` was received
125
-
3. Ensure consistent behavior regardless of cancellation source
127
+
1. Send the same `-32800` (Cancelled) error response as if `request/cancel` was received
128
+
2. Ensure consistent behavior regardless of cancellation source
126
129
127
130
### Error Code
128
131
129
132
Add standard JSON-RPC error code `-32800` for cancelled requests:
130
133
131
134
- Code: `-32800`
132
-
- Message: "Cancelled"
133
-
- Meaning: The request was cancelled
135
+
- Message: "Request cancelled"
136
+
- Meaning: Execution of the method was aborted either due to a cancellation request from the caller or because of resource constraints or shutdown.
134
137
135
138
## Frequently asked questions
136
139
137
140
### What alternative approaches did you consider, and why did you settle on this one?
138
141
139
142
The core need is to add **granular cancellation** as a general mechanism for individual JSON-RPC requests, while **feature-specific cancellation methods** (like `session/cancel`) remain useful for cases requiring additional domain semantics.
140
143
141
-
We selected the **LSP-style `$/cancelRequest`** approach because:
144
+
We selected the **LSP-style `request/cancel`** approach because:
142
145
143
146
- Serves as a **default cancellation layer** that SDK implementations can easily map to native language cancellation mechanisms
144
147
- Proven pattern familiar to developers from LSP ecosystem
@@ -148,9 +151,9 @@ We selected the **LSP-style `$/cancelRequest`** approach because:
148
151
149
152
### How does this relate to existing cancellation mechanisms like `session/cancel`?
150
153
151
-
The `$/cancelRequest` mechanism is complementary to feature-specific cancellation:
154
+
The `request/cancel` mechanism is complementary to feature-specific cancellation:
152
155
153
-
-`$/cancelRequest`: Generic cancellation for any JSON-RPC request by ID
156
+
-`request/cancel`: Generic cancellation for any JSON-RPC request by ID
154
157
-`session/cancel`: Feature-specific cancellation with additional semantics (e.g., cancels entire prompt turn context, triggers specific cleanup logic)
155
158
156
159
Both mechanisms serve different purposes:
@@ -161,16 +164,16 @@ Both mechanisms serve different purposes:
161
164
- Structured cleanup for complex operations
162
165
- Context-aware cancellation logic
163
166
164
-
**Generic `$/cancelRequest`** provides:
167
+
**Generic `request/cancel`** provides:
165
168
166
169
- Default cancellation layer that bridges programming language cancellation mechanisms (C# CancellationToken, Kotlin Job, Go context.Context, etc.) with ACP
167
170
- Universal fallback for any request when no feature-specific method exists
168
171
- Simple ID-based targeting for SDK convenience
169
172
- Standardized error responses
170
173
171
-
Implementations can use both: feature-specific methods for rich semantics, and `$/cancelRequest` for simple per-request cancellation.
174
+
Implementations can use both: feature-specific methods for rich semantics, and `request/cancel` for simple per-request cancellation.
172
175
173
-
Note: it is possible that `session/cancel` could be replaced by the more generic `$/cancelRequest` in future versions of the protocol.
176
+
Note: it is possible that `session/cancel` could be replaced by the more generic `request/cancel` in future versions of the protocol.
174
177
175
178
#### Example: Cascading Cancellation Flow
176
179
@@ -191,8 +194,8 @@ sequenceDiagram
191
194
Client->>Agent: session/cancel (sessionId)
192
195
193
196
Note over Client,Agent: 4. Agent cascades cancellation internally
Note over Client,Agent: 5. Client confirms individual cancellations
198
201
Client->>Agent: response to id=2 (error -32800 "Cancelled")
@@ -226,10 +229,10 @@ This ensures complete cleanup and prevents resource leaks.
226
229
227
230
Cancellation support is **optional** in the current protocol version and declared through capabilities:
228
231
229
-
- Implementations **MAY** support handling cancellation by declaring `supportsRequestCancellation: true`
230
-
- If an implementation declares support, it **MUST** handle `$/cancelRequest` notifications for its requests
231
-
- If an implementation does not declare support, `$/cancelRequest` notifications should be ignored
232
-
- The other party can send `$/cancelRequest` regardless of their own declared support
232
+
- Implementations **MAY** support handling cancellation by declaring `cancellationCapabilities: {}`
233
+
- If an implementation declares support, it **MUST** handle `request/cancel` notifications for its requests
234
+
- If an implementation does not declare support, `request/cancel` notifications should be ignored
235
+
- The other party can send `request/cancel` regardless of their own declared support
233
236
- The `initialize` request **CANNOT** be cancelled regardless of capability support
234
237
- Any requests after `initialize`**CAN** be cancelled if the recipient declared support
235
238
@@ -239,20 +242,21 @@ When cancellation is supported:
239
242
- Implementations **MAY** choose how quickly to honor cancellation requests
240
243
- Implementations **MAY** return partial results instead of errors when appropriate
241
244
242
-
**Future consideration**: There is a proposal to make basic `$/cancelRequest` support **mandatory** in the next major protocol version to ensure consistent cancellation behavior across all ACP implementations and improve SDK developer experience.
245
+
Cancellation will remain optional as it might not be implementable in all clients or servers. For example if the implementation uses a single threaded synchronous programming language then there is little it can do to react to a `request/cancel` notification.
0 commit comments