1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! Record-deletion route handlers for managed sessions (#2012).
//!
//! Why: split out of `managed_routes/mod.rs`, which had grown to exactly the
//! 500-SLOC production cap and could not accept another module declaration.
//! These two handlers are one cohesive concept — removing a session from the
//! operator's list — and are the only handlers in that file that never touch
//! the runtime or the workspace, so they detach cleanly.
//! What: [`delete_managed_session`] soft-deletes the RECORD;
//! [`stop_managed_session`] is the legacy `DELETE` alias that delegates to
//! runtime-stop. Both are re-exported from the parent so route wiring and
//! external callers keep their existing paths.
//! Test: `delete_route_marks_deleted`, `delete_route_refuses_running_without_force`,
//! `delete_route_force_bypasses_guard` in `managed_routes::tests`.
use Arc;
use ;
use ;
use crateRouteOutcome;
use crateDaemonState;
/// POST /api/v1/sessions/managed/{id}/delete — soft-delete the RECORD, mark `--deleted--` (#2012).
///
/// Why: distinct from `decommission` (stop runtime + maybe remove workspace +
/// `Decommissioned` tombstone) — this marks the record `Deleted` (rendered
/// `--deleted--`) so the operator's master list REFLECTS the deletion instead
/// of the row vanishing, honouring the "fully-tracked lifecycle" standard.
/// Fail-closed: a RUNNING session (`Active`/`Provisioning`) is refused unless
/// `?force=true`.
/// What: parses the id and the `force` query flag, delegates to
/// [`crate::session_manager::SessionManager::delete_record`], and maps its
/// result — `Ok` → 200 with the pre-deletion [`DeleteResponse`] snapshot;
/// `SessionNotFound` → 404; `InvalidState` (the running-guard refusal) → 409
/// with the manager's actionable message; any other error → 500. NEVER
/// touches the workspace directory on disk (see `delete_record`'s doc).
/// Test: `delete_route_marks_deleted`, `delete_route_refuses_running_without_force`,
/// `delete_route_force_bypasses_guard` in managed_routes tests.
pub async
/// The transport-neutral body of `POST .../{id}/delete` (#6288), served over
/// the socket as `mpm.managed.delete`.
///
/// Test: `managed_delete_parity` (the missing-id refusal),
/// `managed_delete_refuses_a_running_session_without_force` and
/// `managed_delete_force_bypasses_the_running_guard_on_both_transports` (the
/// `force` flag, decoded from a real JSON-RPC frame) — all in
/// `daemon::rpc::managed_tests`.
pub async
/// DELETE /api/v1/sessions/managed/{id} — stop and deregister (legacy alias).
///
/// Why: the original MVP wired DELETE to a "stop" that marked the record Dead.
/// The new semantic is `POST /{id}/runtime-stop` (keep workspace) and
/// `POST /{id}/decommission` (full teardown). This handler now delegates to
/// `runtime-stop` (marks Stopped, keeps workspace) so existing scripts that use
/// DELETE do not experience data loss.
/// What: delegates to SessionManager::stop.
/// Test: covered by `stop_managed_session_runtime` tests.
pub async