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
Copy file name to clipboardExpand all lines: docs/specification/draft/basic/utilities/cancellation.mdx
+39-9Lines changed: 39 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,9 +15,12 @@ indicate that a previously-issued request should be terminated.
15
15
When a party wants to cancel an in-progress request, it sends a `notifications/cancelled`
16
16
notification containing:
17
17
18
-
- The ID of the request to cancel
18
+
- For non-task requests: The ID of the request to cancel
19
+
- For task cancellation: The ID of the task to cancel
19
20
- An optional reason string that can be logged or displayed
20
21
22
+
### Cancelling Non-Task Requests
23
+
21
24
```json
22
25
{
23
26
"jsonrpc": "2.0",
@@ -29,23 +32,49 @@ notification containing:
29
32
}
30
33
```
31
34
35
+
### Cancelling Tasks
36
+
37
+
For task-augmented requests, once the `CreateTaskResult` is returned, the original request is complete and `requestId` becomes ambiguous. Therefore, task cancellation **MUST** use `taskId`:
38
+
39
+
```json
40
+
{
41
+
"jsonrpc": "2.0",
42
+
"method": "notifications/cancelled",
43
+
"params": {
44
+
"taskId": "786512e2-9e0d-44bd-8f29-789f320fe840",
45
+
"reason": "User requested cancellation"
46
+
}
47
+
}
48
+
```
49
+
32
50
## Behavior Requirements
33
51
34
-
1. Cancellation notifications **MUST** only reference requests that:
52
+
### General Requirements
53
+
54
+
1. Cancellation notifications **MUST** only reference requests or tasks that:
35
55
- Were previously issued in the same direction
36
56
- Are believed to still be in-progress
37
57
2. The `initialize` request **MUST NOT** be cancelled by clients
38
58
3. Receivers of cancellation notifications **SHOULD**:
39
-
- Stop processing the cancelled request
59
+
- Stop processing the cancelled request or task
40
60
- Free associated resources
41
-
- Not send a response for the cancelled request
61
+
- For non-task requests: Not send a response for the cancelled request
- Processing has already completed (for non-task requests) or reached a terminal status (for tasks)
66
+
- The request or task cannot be cancelled
46
67
5. The sender of the cancellation notification **SHOULD** ignore any response to the
47
68
request that arrives afterward
48
69
70
+
### Task-Specific Requirements
71
+
72
+
1. For task cancellation, `taskId`**MUST** be provided (not `requestId`)
73
+
2.`requestId`**MUST NOT** be used for task cancellation once `CreateTaskResult` has been returned
74
+
3. When a receiver receives a `notifications/cancelled` notification with a `taskId`, it **SHOULD** immediately move the task to `cancelled` status
75
+
4. If a cancellation notification arrives after a task has already reached a terminal status (`completed`, `failed`, or `cancelled`), receivers **SHOULD** ignore the notification
76
+
5. Requestors **SHOULD** poll with `tasks/get` after sending a cancellation notification to confirm the task has transitioned to `cancelled` status
77
+
49
78
## Timing Considerations
50
79
51
80
Due to network latency, cancellation notifications may arrive after request processing
@@ -77,9 +106,10 @@ sequenceDiagram
77
106
78
107
Invalid cancellation notifications **SHOULD** be ignored:
79
108
80
-
- Unknown request IDs
81
-
- Already completed requests
109
+
- Unknown request IDs or task IDs
110
+
- Already completed requests or tasks in terminal status
82
111
- Malformed notifications
112
+
- Using `requestId` for task cancellation (should use `taskId` instead)
83
113
84
114
This maintains the "fire and forget" nature of notifications while allowing for race
Copy file name to clipboardExpand all lines: docs/specification/draft/basic/utilities/tasks.mdx
+5-2Lines changed: 5 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -420,7 +420,10 @@ stateDiagram-v2
420
420
### Task Cancellation
421
421
422
422
1. Requestors **MAY** send `notifications/cancelled` at any time during task execution.
423
-
1. When a receiver receives a `notifications/cancelled` notification for the JSON-RPC request ID of a task-augmented request, the receiver **SHOULD** immediately move the task to the `cancelled` status and cease all processing associated with that task.
423
+
1. For task cancellation, the `notifications/cancelled` notification **MUST** include a `taskId` field:
424
+
1. The `taskId`**MUST** correspond to a task previously created in the same direction.
425
+
1. Once a task-augmented request returns `CreateTaskResult`, the original request is complete and `requestId` becomes ambiguous. Therefore, `requestId`**MUST NOT** be used for task cancellation.
426
+
1. When a receiver receives a `notifications/cancelled` notification with a `taskId`, the receiver **SHOULD** immediately move the task to the `cancelled` status and cease all processing associated with that task.
424
427
1. Due to the asynchronous nature of notifications, receivers **MAY** not cancel task processing instantaneously. Receivers **SHOULD** make a best-effort attempt to halt execution as quickly as possible.
425
428
1. If a `notifications/cancelled` notification arrives after a task has already reached a terminal status (`completed`, `failed`, or `cancelled`), receivers **SHOULD** ignore the notification.
426
429
1. After a task reaches `cancelled` status and its `keepAlive` duration has elapsed, receivers **MAY** delete the task and its metadata.
0 commit comments