Skip to main content

muse_code_sdk/msp/method/lifecycle/
session_leave.rs

1// @generated from the MSP stable schema and protocol sources; do not edit by hand.
2
3use crate::msp::command::CommandAckStatus;
4use serde::Deserialize;
5use serde::Serialize;
6
7/// `session/leave` params.
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct SessionLeaveParams {
11    /// Client-minted UUIDv7 command identity.
12    pub command_id: String,
13    /// The exact loaded session whose ownership is to be released.
14    pub session_id: String,
15    /// Explicitly cancel unfinished work before leaving. Omitted is `false`.
16    #[serde(default, skip_serializing_if = "Option::is_none")]
17    pub stop: Option<bool>,
18}
19
20/// The admission-only `session/leave` result.
21#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
22#[serde(rename_all = "camelCase")]
23#[non_exhaustive]
24pub struct SessionLeaveResult {
25    /// The leave command's id.
26    pub command_id: String,
27    /// The admission status, `accepted` once the leave is admitted. The final
28    /// result arrives later as `session/leaveCompleted`. Sending the same leave
29    /// command again returns `accepted` and re-pushes the recorded result if
30    /// there is one, from the host that ran the leave (for as long as it runs,
31    /// even after the release) or from a host that has the session loaded
32    /// (after a host crash, `abandoned` among them). Any other host treats it
33    /// as a fresh leave: a durable host that has not loaded the session refuses
34    /// it with `sessionNotLoaded` until it is resumed there.
35    pub status: CommandAckStatus,
36}
37
38/// Current producer outcomes for `session/leaveCompleted`; receiver-open.
39#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
40#[serde(transparent)]
41#[non_exhaustive]
42pub struct SessionLeaveOutcome(pub String);
43
44impl SessionLeaveOutcome {
45    /// `released`: the host released the session; `viewCursor` is set.
46    pub const RELEASED: &'static str = "released";
47    /// `failed`: the leave did not end in a release this host can report;
48    /// `reason` says why.
49    pub const FAILED: &'static str = "failed";
50}
51
52/// Current producer failure reasons for `session/leaveCompleted`;
53/// receiver-open for additive future reasons.
54#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
55#[serde(transparent)]
56#[non_exhaustive]
57pub struct SessionLeaveFailureReason(pub String);
58
59impl SessionLeaveFailureReason {
60    /// `timeout`: the session did not finish shutting down within the leave's
61    /// window. The host keeps the session.
62    pub const TIMEOUT: &'static str = "timeout";
63    /// `responseUndelivered`: the leave's acceptance could not be delivered to
64    /// the client. The host keeps the session.
65    pub const RESPONSE_UNDELIVERED: &'static str = "responseUndelivered";
66    /// `persistenceFailed`: saving the session or releasing its writer lease
67    /// failed. The host keeps the session.
68    pub const PERSISTENCE_FAILED: &'static str = "persistenceFailed";
69    /// `runtimeFailed`: the session's runtime failed while shutting down. The
70    /// host keeps the session.
71    pub const RUNTIME_FAILED: &'static str = "runtimeFailed";
72    /// `abandoned`: no host owns this leave's result. A host that later took
73    /// the session's writer recorded it because no result was recorded and
74    /// either the leave had reached its release point or the host that ran it
75    /// was proven dead; it never means the release failed. Recording it pushes
76    /// nothing; a client sees it only as the `session/leaveCompleted`
77    /// re-pushed after it sends the same leave command again.
78    pub const ABANDONED: &'static str = "abandoned";
79}
80
81/// Params of the protected, non-view leave terminal notification.
82#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
83#[serde(rename_all = "camelCase")]
84#[non_exhaustive]
85pub struct SessionLeaveCompletedParams {
86    /// The session the leave was for.
87    pub session_id: String,
88    /// The leave command's id, matching the `session/leave` request.
89    pub command_id: String,
90    /// How the leave ended: `released` or `failed`. The set is open, so newer
91    /// hosts may add outcomes.
92    pub outcome: SessionLeaveOutcome,
93    /// Why the leave failed. Present when `outcome` is `failed`.
94    #[serde(skip_serializing_if = "Option::is_none")]
95    pub reason: Option<SessionLeaveFailureReason>,
96    /// The session's view cursor at release: everything up to it was folded
97    /// before the host let go. Present when `outcome` is `released`.
98    #[serde(skip_serializing_if = "Option::is_none")]
99    pub view_cursor: Option<String>,
100}