Skip to content

Commit ec4e904

Browse files
authored
docs(v2): clarify prompt cancellation when closing sessions (#2385)
1 parent 1df3a77 commit ec4e904

9 files changed

Lines changed: 47 additions & 2 deletions

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,17 @@ impl ResumeSessionResponse {
16391639
/// The agent **must** cancel any ongoing work related to the session (treat it
16401640
/// as if `session/cancel` was called) and then free up any resources associated
16411641
/// with the session.
1642+
///
1643+
/// When closing cancels active foreground work, the Agent MUST send the final
1644+
/// updates for that work and the idle `state_update` with `stopReason: "cancelled"`
1645+
/// before responding successfully to `session/close`. Closing an idle session
1646+
/// does not itself require another idle update.
1647+
///
1648+
/// Closing may also cancel pending `session/prompt` requests, including queued
1649+
/// prompts. If closing prevents a prompt's user message from being inserted, the
1650+
/// Agent MUST answer that request with `-32800` (Request Cancelled). If the message
1651+
/// has already been inserted, the Agent MUST respond successfully with its
1652+
/// `messageId`. Prompt responses need not precede the close response.
16421653
#[serde_as]
16431654
#[skip_serializing_none]
16441655
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]

‎docs/protocol/v2/draft/prompt-lifecycle.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ Insertion is not a promise of durable storage or model consumption. Every insert
261261

262262
A successful prompt response is not an `idle` signal. Session work and notifications continue independently of the completed prompt request. If the response is lost, the submission's outcome remains uncertain: replay may omit live-only or discarded messages, and a retry can create another submission.
263263

264+
The same insertion boundary applies when [closing the session](/protocol/v2/draft/session-setup#closing-active-sessions) cancels a pending prompt: if closing prevents insertion, the request receives `-32800` (Request Cancelled); if the message has already been inserted, it receives a successful `messageId` response. Prompt responses need not precede the close response.
265+
264266
### 3. Agent Reports Output
265267

266268
When foreground work starts or resumes, the Agent **MUST** send a `state_update` notification with `state: "running"`:

‎docs/protocol/v2/draft/schema.mdx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,17 @@ The agent **must** cancel any ongoing work related to the session (treat it
933933
as if `session/cancel` was called) and then free up any resources associated
934934
with the session.
935935

936+
When closing cancels active foreground work, the Agent MUST send the final
937+
updates for that work and the idle `state_update` with `stopReason: "cancelled"`
938+
before responding successfully to `session/close`. Closing an idle session
939+
does not itself require another idle update.
940+
941+
Closing may also cancel pending `session/prompt` requests, including queued
942+
prompts. If closing prevents a prompt's user message from being inserted, the
943+
Agent MUST answer that request with `-32800` (Request Cancelled). If the message
944+
has already been inserted, the Agent MUST respond successfully with its
945+
`messageId`. Prompt responses need not precede the close response.
946+
936947
**Type:** Object
937948

938949
**Properties:**

‎docs/protocol/v2/draft/session-setup.mdx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ The Agent **MUST** cancel any ongoing work for that session as if
308308
[`session/cancel`](/protocol/v2/draft/prompt-lifecycle#cancellation) had been called, then free the
309309
resources associated with the session.
310310

311+
When closing cancels active foreground work, the Agent **MUST** send the final updates for that work and the idle `state_update` with `stopReason: "cancelled"` before responding successfully to `session/close`. Closing an idle session does not itself require another idle update.
312+
313+
Closing may also cancel pending `session/prompt` requests, including queued prompts. If closing prevents a prompt's user message from being inserted, the Agent **MUST** answer that request with `-32800` (Request Cancelled). If the message has already been inserted, the Agent **MUST** respond successfully with its `messageId`, as described in [Prompt Accepted](/protocol/v2/draft/prompt-lifecycle#2-prompt-accepted). Prompt responses need not precede the close response.
314+
311315
On success, the Agent responds with an empty result object:
312316

313317
```json

‎docs/protocol/v2/prompt-lifecycle.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ Insertion is not a promise of durable storage or model consumption. Every insert
211211

212212
A successful prompt response is not an `idle` signal. Session work and notifications continue independently of the completed prompt request. If the response is lost, the submission's outcome remains uncertain: replay may omit live-only or discarded messages, and a retry can create another submission.
213213

214+
The same insertion boundary applies when [closing the session](/protocol/v2/session-setup#closing-active-sessions) cancels a pending prompt: if closing prevents insertion, the request receives `-32800` (Request Cancelled); if the message has already been inserted, it receives a successful `messageId` response. Prompt responses need not precede the close response.
215+
214216
### 3. Agent Reports Output
215217

216218
When foreground work starts or resumes, the Agent **MUST** send a `state_update` notification with `state: "running"`:

‎docs/protocol/v2/schema.mdx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,17 @@ The agent **must** cancel any ongoing work related to the session (treat it
279279
as if `session/cancel` was called) and then free up any resources associated
280280
with the session.
281281

282+
When closing cancels active foreground work, the Agent MUST send the final
283+
updates for that work and the idle `state_update` with `stopReason: "cancelled"`
284+
before responding successfully to `session/close`. Closing an idle session
285+
does not itself require another idle update.
286+
287+
Closing may also cancel pending `session/prompt` requests, including queued
288+
prompts. If closing prevents a prompt's user message from being inserted, the
289+
Agent MUST answer that request with `-32800` (Request Cancelled). If the message
290+
has already been inserted, the Agent MUST respond successfully with its
291+
`messageId`. Prompt responses need not precede the close response.
292+
282293
**Type:** Object
283294

284295
**Properties:**

‎docs/protocol/v2/session-setup.mdx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ To close an active session, Clients **MUST** call the `session/close` method wit
301301

302302
The Agent **MUST** cancel any ongoing work for that session as if [`session/cancel`](/protocol/v2/prompt-lifecycle#cancellation) had been called, then free the resources associated with the session.
303303

304+
When closing cancels active foreground work, the Agent **MUST** send the final updates for that work and the idle `state_update` with `stopReason: "cancelled"` before responding successfully to `session/close`. Closing an idle session does not itself require another idle update.
305+
306+
Closing may also cancel pending `session/prompt` requests, including queued prompts. If closing prevents a prompt's user message from being inserted, the Agent **MUST** answer that request with `-32800` (Request Cancelled). If the message has already been inserted, the Agent **MUST** respond successfully with its `messageId`, as described in [Prompt Accepted](/protocol/v2/prompt-lifecycle#2-prompt-accepted). Prompt responses need not precede the close response.
307+
304308
On success, the Agent responds with an empty result object:
305309

306310
```json

‎schema/v2/schema.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6780,7 +6780,7 @@
67806780
}
67816781
},
67826782
"CloseSessionRequest": {
6783-
"description": "Request parameters for closing an active session.\n\nThe agent **must** cancel any ongoing work related to the session (treat it\nas if `session/cancel` was called) and then free up any resources associated\nwith the session.",
6783+
"description": "Request parameters for closing an active session.\n\nThe agent **must** cancel any ongoing work related to the session (treat it\nas if `session/cancel` was called) and then free up any resources associated\nwith the session.\n\nWhen closing cancels active foreground work, the Agent MUST send the final\nupdates for that work and the idle `state_update` with `stopReason: \"cancelled\"`\nbefore responding successfully to `session/close`. Closing an idle session\ndoes not itself require another idle update.\n\nClosing may also cancel pending `session/prompt` requests, including queued\nprompts. If closing prevents a prompt's user message from being inserted, the\nAgent MUST answer that request with `-32800` (Request Cancelled). If the message\nhas already been inserted, the Agent MUST respond successfully with its\n`messageId`. Prompt responses need not precede the close response.",
67846784
"type": "object",
67856785
"properties": {
67866786
"sessionId": {

‎schema/v2/schema.unstable.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9119,7 +9119,7 @@
91199119
}
91209120
},
91219121
"CloseSessionRequest": {
9122-
"description": "Request parameters for closing an active session.\n\nThe agent **must** cancel any ongoing work related to the session (treat it\nas if `session/cancel` was called) and then free up any resources associated\nwith the session.",
9122+
"description": "Request parameters for closing an active session.\n\nThe agent **must** cancel any ongoing work related to the session (treat it\nas if `session/cancel` was called) and then free up any resources associated\nwith the session.\n\nWhen closing cancels active foreground work, the Agent MUST send the final\nupdates for that work and the idle `state_update` with `stopReason: \"cancelled\"`\nbefore responding successfully to `session/close`. Closing an idle session\ndoes not itself require another idle update.\n\nClosing may also cancel pending `session/prompt` requests, including queued\nprompts. If closing prevents a prompt's user message from being inserted, the\nAgent MUST answer that request with `-32800` (Request Cancelled). If the message\nhas already been inserted, the Agent MUST respond successfully with its\n`messageId`. Prompt responses need not precede the close response.",
91239123
"type": "object",
91249124
"properties": {
91259125
"sessionId": {

0 commit comments

Comments
 (0)