Skip to content

Commit 8558625

Browse files
authored
feat(schema): Stabilize request cancellation (#1549)
* feat(schema): Stabilize request cancellation * Unify language
1 parent e1edc4a commit 8558625

27 files changed

Lines changed: 488 additions & 149 deletions

agent-client-protocol-schema/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ workspace = true
2424
[features]
2525
unstable = [
2626
"unstable_auth_methods",
27-
"unstable_cancel_request",
2827
"unstable_elicitation",
2928
"unstable_llm_providers",
3029
"unstable_mcp_over_acp",
@@ -39,7 +38,6 @@ unstable = [
3938
# version, so it must be opted into explicitly.
4039
unstable_protocol_v2 = []
4140
unstable_auth_methods = []
42-
unstable_cancel_request = []
4341
unstable_elicitation = []
4442
unstable_llm_providers = []
4543
unstable_mcp_over_acp = []

agent-client-protocol-schema/src/v1/error.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,10 @@ impl Error {
9999
ErrorCode::InternalError.into()
100100
}
101101

102-
/// **UNSTABLE**
103-
///
104-
/// This capability is not part of the spec yet, and may be removed or changed at any point.
105-
///
106102
/// Request was cancelled.
107103
///
108104
/// Execution of the method was aborted either due to a cancellation request from the caller
109105
/// or because of resource constraints or shutdown.
110-
#[cfg(feature = "unstable_cancel_request")]
111106
#[must_use]
112107
pub fn request_cancelled() -> Self {
113108
ErrorCode::RequestCancelled.into()
@@ -183,11 +178,6 @@ pub enum ErrorCode {
183178
#[schemars(transform = error_code_transform)]
184179
#[strum(to_string = "Internal error")]
185180
InternalError, // -32603
186-
#[cfg(feature = "unstable_cancel_request")]
187-
/// **UNSTABLE**
188-
///
189-
/// This capability is not part of the spec yet, and may be removed or changed at any point.
190-
///
191181
/// Execution of the method was aborted either due to a cancellation request from the caller or
192182
/// because of resource constraints or shutdown.
193183
#[schemars(transform = error_code_transform)]
@@ -227,7 +217,6 @@ impl From<i32> for ErrorCode {
227217
-32601 => ErrorCode::MethodNotFound,
228218
-32602 => ErrorCode::InvalidParams,
229219
-32603 => ErrorCode::InternalError,
230-
#[cfg(feature = "unstable_cancel_request")]
231220
-32800 => ErrorCode::RequestCancelled,
232221
-32000 => ErrorCode::AuthRequired,
233222
-32002 => ErrorCode::ResourceNotFound,
@@ -246,7 +235,6 @@ impl From<ErrorCode> for i32 {
246235
ErrorCode::MethodNotFound => -32601,
247236
ErrorCode::InvalidParams => -32602,
248237
ErrorCode::InternalError => -32603,
249-
#[cfg(feature = "unstable_cancel_request")]
250238
ErrorCode::RequestCancelled => -32800,
251239
ErrorCode::AuthRequired => -32000,
252240
ErrorCode::ResourceNotFound => -32002,
@@ -275,7 +263,6 @@ fn error_code_transform(schema: &mut Schema) {
275263
"MethodNotFound" => ErrorCode::MethodNotFound,
276264
"InvalidParams" => ErrorCode::InvalidParams,
277265
"InternalError" => ErrorCode::InternalError,
278-
#[cfg(feature = "unstable_cancel_request")]
279266
"RequestCancelled" => ErrorCode::RequestCancelled,
280267
"AuthRequired" => ErrorCode::AuthRequired,
281268
"ResourceNotFound" => ErrorCode::ResourceNotFound,

agent-client-protocol-schema/src/v1/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ mod mcp;
1212
#[cfg(feature = "unstable_nes")]
1313
mod nes;
1414
mod plan;
15-
#[cfg(feature = "unstable_cancel_request")]
1615
mod protocol_level;
1716
mod tool_call;
1817

@@ -30,7 +29,6 @@ pub use mcp::*;
3029
#[cfg(feature = "unstable_nes")]
3130
pub use nes::*;
3231
pub use plan::*;
33-
#[cfg(feature = "unstable_cancel_request")]
3432
pub use protocol_level::*;
3533
pub use serde_json::value::RawValue;
3634
pub use tool_call::*;

agent-client-protocol-schema/src/v1/protocol_level.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@ use crate::IntoOption;
66

77
use super::{Meta, RequestId};
88

9-
/// **UNSTABLE**
10-
///
11-
/// This capability is not part of the spec yet, and may be removed or changed at any point.
12-
///
139
/// Notification to cancel an ongoing request.
1410
///
1511
/// See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/cancellation)
16-
#[cfg(feature = "unstable_cancel_request")]
1712
#[serde_as]
1813
#[skip_serializing_none]
1914
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
@@ -35,7 +30,6 @@ pub struct CancelRequestNotification {
3530
pub meta: Option<Meta>,
3631
}
3732

38-
#[cfg(feature = "unstable_cancel_request")]
3933
impl CancelRequestNotification {
4034
/// Builds [`CancelRequestNotification`] with the required notification fields set; optional fields start unset or empty.
4135
#[must_use]
@@ -67,13 +61,11 @@ impl CancelRequestNotification {
6761
#[non_exhaustive]
6862
pub struct GeneralMethodNames {
6963
/// Method name for protocol-level request cancellation notifications.
70-
#[cfg(feature = "unstable_cancel_request")]
7164
pub cancel_request: &'static str,
7265
}
7366

7467
/// Constant containing all agent method names.
7568
pub const PROTOCOL_LEVEL_METHOD_NAMES: GeneralMethodNames = GeneralMethodNames {
76-
#[cfg(feature = "unstable_cancel_request")]
7769
cancel_request: CANCEL_REQUEST_METHOD_NAME,
7870
};
7971

@@ -96,25 +88,19 @@ pub(crate) const CANCEL_REQUEST_METHOD_NAME: &str = "$/cancel_request";
9688
#[schemars(inline)]
9789
#[non_exhaustive]
9890
pub enum ProtocolLevelNotification {
99-
/// **UNSTABLE**
100-
///
101-
/// This capability is not part of the spec yet, and may be removed or
102-
/// changed at any point.
103-
///
10491
/// Cancels an ongoing request.
10592
///
10693
/// This is a notification sent by the side that sent a request to cancel that request.
10794
///
10895
/// Upon receiving this notification, the receiver:
10996
///
110-
/// 1. MUST cancel the corresponding request activity and all nested activities
97+
/// 1. MAY cancel the corresponding request activity and all nested activities
11198
/// 2. MAY send any pending notifications.
11299
/// 3. MUST send one of these responses for the original request:
113100
/// - Valid response with appropriate data (partial results or cancellation marker)
114101
/// - Error response with code `-32800` (Cancelled)
115102
///
116103
/// See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/cancellation)
117-
#[cfg(feature = "unstable_cancel_request")]
118104
CancelRequestNotification(CancelRequestNotification),
119105
}
120106

@@ -123,7 +109,6 @@ impl ProtocolLevelNotification {
123109
#[must_use]
124110
pub fn method(&self) -> &str {
125111
match self {
126-
#[cfg(feature = "unstable_cancel_request")]
127112
Self::CancelRequestNotification(..) => PROTOCOL_LEVEL_METHOD_NAMES.cancel_request,
128113
}
129114
}

agent-client-protocol-schema/src/v2/conversion.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,6 @@ impl IntoV2 for crate::v1::PlanEntryStatus {
897897
}
898898
}
899899

900-
#[cfg(feature = "unstable_cancel_request")]
901900
impl IntoV1 for super::CancelRequestNotification {
902901
type Output = crate::v1::CancelRequestNotification;
903902

@@ -910,7 +909,6 @@ impl IntoV1 for super::CancelRequestNotification {
910909
}
911910
}
912911

913-
#[cfg(feature = "unstable_cancel_request")]
914912
impl IntoV2 for crate::v1::CancelRequestNotification {
915913
type Output = super::CancelRequestNotification;
916914

@@ -923,7 +921,6 @@ impl IntoV2 for crate::v1::CancelRequestNotification {
923921
}
924922
}
925923

926-
#[cfg(feature = "unstable_cancel_request")]
927924
impl IntoV1 for super::ProtocolLevelNotification {
928925
type Output = crate::v1::ProtocolLevelNotification;
929926

@@ -936,7 +933,6 @@ impl IntoV1 for super::ProtocolLevelNotification {
936933
}
937934
}
938935

939-
#[cfg(feature = "unstable_cancel_request")]
940936
impl IntoV2 for crate::v1::ProtocolLevelNotification {
941937
type Output = super::ProtocolLevelNotification;
942938

agent-client-protocol-schema/src/v2/error.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,10 @@ impl Error {
9999
ErrorCode::InternalError.into()
100100
}
101101

102-
/// **UNSTABLE**
103-
///
104-
/// This capability is not part of the spec yet, and may be removed or changed at any point.
105-
///
106102
/// Request was cancelled.
107103
///
108104
/// Execution of the method was aborted either due to a cancellation request from the caller
109105
/// or because of resource constraints or shutdown.
110-
#[cfg(feature = "unstable_cancel_request")]
111106
#[must_use]
112107
pub fn request_cancelled() -> Self {
113108
ErrorCode::RequestCancelled.into()
@@ -183,11 +178,6 @@ pub enum ErrorCode {
183178
#[schemars(transform = error_code_transform)]
184179
#[strum(to_string = "Internal error")]
185180
InternalError, // -32603
186-
#[cfg(feature = "unstable_cancel_request")]
187-
/// **UNSTABLE**
188-
///
189-
/// This capability is not part of the spec yet, and may be removed or changed at any point.
190-
///
191181
/// Execution of the method was aborted either due to a cancellation request from the caller or
192182
/// because of resource constraints or shutdown.
193183
#[schemars(transform = error_code_transform)]
@@ -227,7 +217,6 @@ impl From<i32> for ErrorCode {
227217
-32601 => ErrorCode::MethodNotFound,
228218
-32602 => ErrorCode::InvalidParams,
229219
-32603 => ErrorCode::InternalError,
230-
#[cfg(feature = "unstable_cancel_request")]
231220
-32800 => ErrorCode::RequestCancelled,
232221
-32000 => ErrorCode::AuthRequired,
233222
-32002 => ErrorCode::ResourceNotFound,
@@ -246,7 +235,6 @@ impl From<ErrorCode> for i32 {
246235
ErrorCode::MethodNotFound => -32601,
247236
ErrorCode::InvalidParams => -32602,
248237
ErrorCode::InternalError => -32603,
249-
#[cfg(feature = "unstable_cancel_request")]
250238
ErrorCode::RequestCancelled => -32800,
251239
ErrorCode::AuthRequired => -32000,
252240
ErrorCode::ResourceNotFound => -32002,
@@ -275,7 +263,6 @@ fn error_code_transform(schema: &mut Schema) {
275263
"MethodNotFound" => ErrorCode::MethodNotFound,
276264
"InvalidParams" => ErrorCode::InvalidParams,
277265
"InternalError" => ErrorCode::InternalError,
278-
#[cfg(feature = "unstable_cancel_request")]
279266
"RequestCancelled" => ErrorCode::RequestCancelled,
280267
"AuthRequired" => ErrorCode::AuthRequired,
281268
"ResourceNotFound" => ErrorCode::ResourceNotFound,

agent-client-protocol-schema/src/v2/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ mod mcp;
2323
#[cfg(feature = "unstable_nes")]
2424
mod nes;
2525
mod plan;
26-
#[cfg(feature = "unstable_cancel_request")]
2726
mod protocol_level;
2827
pub(crate) mod schema_util;
2928
mod tool_call;
@@ -42,7 +41,6 @@ pub use mcp::*;
4241
#[cfg(feature = "unstable_nes")]
4342
pub use nes::*;
4443
pub use plan::*;
45-
#[cfg(feature = "unstable_cancel_request")]
4644
pub use protocol_level::*;
4745
pub use serde_json::value::RawValue;
4846
pub use tool_call::*;

agent-client-protocol-schema/src/v2/protocol_level.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@ use serde_with::{DefaultOnError, serde_as, skip_serializing_none};
55
use super::{Meta, RequestId};
66
use crate::IntoOption;
77

8-
/// **UNSTABLE**
9-
///
10-
/// This capability is not part of the spec yet, and may be removed or changed at any point.
11-
///
128
/// Notification to cancel an ongoing request.
139
///
1410
/// See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/cancellation)
15-
#[cfg(feature = "unstable_cancel_request")]
1611
#[serde_as]
1712
#[skip_serializing_none]
1813
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
@@ -34,7 +29,6 @@ pub struct CancelRequestNotification {
3429
pub meta: Option<Meta>,
3530
}
3631

37-
#[cfg(feature = "unstable_cancel_request")]
3832
impl CancelRequestNotification {
3933
/// Builds [`CancelRequestNotification`] with the required notification fields set; optional fields start unset or empty.
4034
#[must_use]
@@ -66,13 +60,11 @@ impl CancelRequestNotification {
6660
#[non_exhaustive]
6761
pub struct GeneralMethodNames {
6862
/// Method name for protocol-level request cancellation notifications.
69-
#[cfg(feature = "unstable_cancel_request")]
7063
pub cancel_request: &'static str,
7164
}
7265

7366
/// Constant containing all agent method names.
7467
pub const PROTOCOL_LEVEL_METHOD_NAMES: GeneralMethodNames = GeneralMethodNames {
75-
#[cfg(feature = "unstable_cancel_request")]
7668
cancel_request: CANCEL_REQUEST_METHOD_NAME,
7769
};
7870

@@ -95,25 +87,19 @@ pub(crate) const CANCEL_REQUEST_METHOD_NAME: &str = "$/cancel_request";
9587
#[schemars(inline)]
9688
#[non_exhaustive]
9789
pub enum ProtocolLevelNotification {
98-
/// **UNSTABLE**
99-
///
100-
/// This capability is not part of the spec yet, and may be removed or
101-
/// changed at any point.
102-
///
10390
/// Cancels an ongoing request.
10491
///
10592
/// This is a notification sent by the side that sent a request to cancel that request.
10693
///
10794
/// Upon receiving this notification, the receiver:
10895
///
109-
/// 1. MUST cancel the corresponding request activity and all nested activities
96+
/// 1. MAY cancel the corresponding request activity and all nested activities
11097
/// 2. MAY send any pending notifications.
11198
/// 3. MUST send one of these responses for the original request:
11299
/// - Valid response with appropriate data (partial results or cancellation marker)
113100
/// - Error response with code `-32800` (Cancelled)
114101
///
115102
/// See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/cancellation)
116-
#[cfg(feature = "unstable_cancel_request")]
117103
CancelRequestNotification(CancelRequestNotification),
118104
}
119105

@@ -122,7 +108,6 @@ impl ProtocolLevelNotification {
122108
#[must_use]
123109
pub fn method(&self) -> &str {
124110
match self {
125-
#[cfg(feature = "unstable_cancel_request")]
126111
Self::CancelRequestNotification(..) => PROTOCOL_LEVEL_METHOD_NAMES.cancel_request,
127112
}
128113
}

docs/docs.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"protocol/v1/content",
7878
"protocol/v1/tool-calls",
7979
"protocol/v1/file-system",
80+
"protocol/v1/cancellation",
8081
"protocol/v1/terminals",
8182
"protocol/v1/agent-plan",
8283
"protocol/v1/session-modes",
@@ -126,6 +127,7 @@
126127
"protocol/v2/prompt-lifecycle",
127128
"protocol/v2/content",
128129
"protocol/v2/tool-calls",
130+
"protocol/v2/cancellation",
129131
"protocol/v2/agent-plan",
130132
"protocol/v2/session-config-options",
131133
"protocol/v2/slash-commands",
@@ -209,7 +211,7 @@
209211
},
210212
{
211213
"group": "Preview",
212-
"pages": ["rfds/request-cancellation"]
214+
"pages": []
213215
},
214216
{
215217
"group": "Completed",
@@ -228,7 +230,8 @@
228230
"rfds/session-usage",
229231
"rfds/session-delete",
230232
"rfds/model-config-category",
231-
"rfds/rust-sdk-v1"
233+
"rfds/rust-sdk-v1",
234+
"rfds/request-cancellation"
232235
]
233236
}
234237
]

0 commit comments

Comments
 (0)