Skip to content

Commit 299fcd6

Browse files
drewelezar
authored andcommitted
feat(compute): let drivers declare gateway lifecycle
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 7bca069 commit 299fcd6

10 files changed

Lines changed: 79 additions & 37 deletions

File tree

‎.agents/skills/debug-openshell-cluster/SKILL.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ running intent should stop before the gateway exits and restart after it
199199
returns. Check for `Stopped sandbox during gateway shutdown` and `Started
200200
sandbox during gateway startup` in gateway logs. A sandbox explicitly stopped
201201
through the CLI remains stopped. Kubernetes sandboxes are cluster-owned and do
202-
not follow this local gateway lifecycle. An external driver configured under a
203-
different name is not included in the local gateway lifecycle sweep.
202+
not follow this local gateway lifecycle. Internal and external drivers follow
203+
the same rule: `GetCapabilities.gateway_manages_lifecycle` must be true for the
204+
gateway to run shutdown and startup sweeps.
204205

205206
### Step 5: Check Podman-Backed Gateways
206207

‎architecture/compute-runtimes.md‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ references to gateway-internal types. The gateway owns the public
2424
implementing `ComputeDriver` out of tree.
2525

2626
`compute_driver.proto` is the supported gateway/driver extension boundary.
27-
At initialization the gateway snapshots the driver's identity, version, and
28-
default image from `GetCapabilities`. Process-identity omissions are preserved
29-
across this boundary so every driver can apply its native image or runtime
30-
defaults. Driver-requested listeners are structurally validated and remain
31-
restricted to sandbox callback RPCs.
27+
At initialization the gateway snapshots the driver's identity, version,
28+
default image, and gateway-lifecycle preference from `GetCapabilities`.
29+
Process-identity omissions are preserved across this boundary so every driver
30+
can apply its native image or runtime defaults. Driver-requested listeners are
31+
structurally validated and remain restricted to sandbox callback RPCs.
3232

3333
Drivers own runtime-specific platform event interpretation. When an event should
3434
drive client provisioning UI, the driver attaches the shared
@@ -126,6 +126,11 @@ shared idempotent `StartSandbox` RPC before watch processing begins. Explicitly
126126
cluster-owned and continue running without gateway shutdown or startup
127127
lifecycle calls.
128128

129+
The driver reports this behavior through
130+
`GetCapabilities.gateway_managed_lifecycle`. The same declaration works for
131+
in-process and external drivers. Older drivers omit the field and retain the
132+
conservative operator-managed behavior.
133+
129134
## Deletion Lifecycle
130135

131136
Lifecycle requests use per-sandbox gates to serialize stop, start, and

‎crates/openshell-core/src/driver_utils.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,13 @@ pub fn build_capabilities_response(
380380
driver_name: &str,
381381
driver_version: impl Into<String>,
382382
default_image: impl Into<String>,
383+
gateway_managed_lifecycle: bool,
383384
) -> GetCapabilitiesResponse {
384385
GetCapabilitiesResponse {
385386
driver_name: driver_name.to_string(),
386387
driver_version: driver_version.into(),
387388
default_image: default_image.into(),
389+
gateway_managed_lifecycle,
388390
}
389391
}
390392

‎crates/openshell-driver-docker/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ impl DockerComputeDriver {
494494
"docker",
495495
&self.config.daemon_version,
496496
&self.config.default_image,
497+
true,
497498
)
498499
}
499500

‎crates/openshell-driver-kubernetes/src/driver.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ impl KubernetesComputeDriver {
548548
"kubernetes",
549549
openshell_core::VERSION,
550550
&self.config.default_image,
551+
false,
551552
))
552553
}
553554

‎crates/openshell-driver-podman/src/driver.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ impl PodmanComputeDriver {
471471
"podman",
472472
openshell_core::VERSION,
473473
&self.config.default_image,
474+
true,
474475
))
475476
}
476477

‎crates/openshell-driver-vm/src/driver.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ impl VmDriver {
520520
driver_name: DRIVER_NAME.to_string(),
521521
driver_version: openshell_core::VERSION.to_string(),
522522
default_image: self.config.default_image.clone(),
523+
gateway_managed_lifecycle: true,
523524
}
524525
}
525526

‎crates/openshell-server/src/compute/mod.rs‎

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ pub struct ComputeDriverInfoSnapshot {
277277
pub driver_name: String,
278278
/// Driver-reported implementation version from the startup capability snapshot.
279279
pub driver_version: String,
280+
/// Whether the driver asks the gateway to reconcile compute across restarts.
281+
pub gateway_managed_lifecycle: bool,
280282
}
281283

282284
/// Interval between store-vs-backend reconciliation sweeps.
@@ -612,6 +614,7 @@ impl ComputeRuntime {
612614
name: driver_name.clone(),
613615
driver_name: capabilities.driver_name,
614616
driver_version: capabilities.driver_version,
617+
gateway_managed_lifecycle: capabilities.gateway_managed_lifecycle,
615618
};
616619
let default_image = capabilities.default_image;
617620
let gateway_listener_requirements = match driver
@@ -2042,14 +2045,9 @@ impl ComputeRuntime {
20422045
/// persisted lifecycle intent.
20432046
///
20442047
/// An explicit sandbox stop persists `Stopped`; gateway shutdown does not.
2045-
/// Docker, Podman, and VM compute is stopped through the same public driver
2046-
/// RPC and restarted from retained running intent. Kubernetes remains
2047-
/// cluster-owned.
2048+
/// Drivers request this sweep through their startup capability snapshot.
20482049
async fn stop_persisted_sandboxes_on_shutdown(&self) -> Result<(), String> {
2049-
if !matches!(
2050-
self.driver_kind(),
2051-
Some(ComputeDriverKind::Docker | ComputeDriverKind::Podman | ComputeDriverKind::Vm)
2052-
) {
2050+
if !self.driver_info.gateway_managed_lifecycle {
20532051
return Ok(());
20542052
}
20552053

@@ -2138,17 +2136,15 @@ impl ComputeRuntime {
21382136
/// Reconcile running intent for local compute after a gateway restart.
21392137
///
21402138
/// `StartSandbox` is idempotent, so call it for every persisted phase that
2141-
/// requires running compute on Docker, Podman, and VM. Stable stopped,
2142-
/// deleting, and error states are deliberately left alone.
2139+
/// requires running compute for drivers that request gateway-managed
2140+
/// lifecycle. Stable stopped, deleting, and error states are deliberately
2141+
/// left alone.
21432142
///
21442143
/// Should be called once at gateway startup, before watchers spawn,
21452144
/// so the watch loop sees the post-start state on its first poll.
21462145
pub async fn start_persisted_sandboxes(&self) -> Result<(), String> {
21472146
self.recover_persisted_lifecycle_transitions().await?;
2148-
if !matches!(
2149-
self.driver_kind(),
2150-
Some(ComputeDriverKind::Docker | ComputeDriverKind::Podman | ComputeDriverKind::Vm)
2151-
) {
2147+
if !self.driver_info.gateway_managed_lifecycle {
21522148
return Ok(());
21532149
}
21542150

@@ -3947,6 +3943,7 @@ impl ComputeDriver for NoopTestDriver {
39473943
driver_name: "noop-test-driver".to_string(),
39483944
driver_version: "test".to_string(),
39493945
default_image: "openshell/sandbox:test".to_string(),
3946+
gateway_managed_lifecycle: false,
39503947
},
39513948
))
39523949
}
@@ -4087,6 +4084,7 @@ pub async fn new_test_runtime_with_driver(
40874084
name: driver_name.to_string(),
40884085
driver_name: driver_name.to_string(),
40894086
driver_version: "test".to_string(),
4087+
gateway_managed_lifecycle: false,
40904088
},
40914089
driver_process: None,
40924090
default_image: "openshell/sandbox:test".to_string(),
@@ -4249,6 +4247,7 @@ mod tests {
42494247
driver_name: "test-driver".to_string(),
42504248
driver_version: "test".to_string(),
42514249
default_image: "openshell/sandbox:test".to_string(),
4250+
gateway_managed_lifecycle: false,
42524251
}))
42534252
}
42544253

@@ -4566,6 +4565,7 @@ mod tests {
45664565
driver_name: "controlled-test-driver".to_string(),
45674566
driver_version: "test".to_string(),
45684567
default_image: "openshell/sandbox:test".to_string(),
4568+
gateway_managed_lifecycle: false,
45694569
}))
45704570
}
45714571

@@ -4768,6 +4768,7 @@ mod tests {
47684768
name: driver_name.to_string(),
47694769
driver_name: driver_name.to_string(),
47704770
driver_version: "test".to_string(),
4771+
gateway_managed_lifecycle: false,
47714772
},
47724773
driver_process: None,
47734774
default_image: "openshell/sandbox:test".to_string(),
@@ -4783,6 +4784,15 @@ mod tests {
47834784
}
47844785
}
47854786

4787+
async fn test_runtime_with_gateway_managed_lifecycle(
4788+
driver: SharedComputeDriver,
4789+
driver_name: &str,
4790+
) -> ComputeRuntime {
4791+
let mut runtime = test_runtime_for_driver(driver, driver_name).await;
4792+
runtime.driver_info.gateway_managed_lifecycle = true;
4793+
runtime
4794+
}
4795+
47864796
fn register_test_supervisor_session(runtime: &ComputeRuntime, sandbox_id: &str) {
47874797
let (tx, _rx) = mpsc::channel(1);
47884798
let (shutdown_tx, _shutdown_rx) = oneshot::channel();
@@ -8163,7 +8173,8 @@ mod tests {
81638173
#[tokio::test]
81648174
async fn shutdown_stops_running_intent_without_changing_persisted_phase() {
81658175
let driver = ControlledDriver::new();
8166-
let runtime = test_runtime_for_driver(driver.clone(), "docker").await;
8176+
let runtime =
8177+
test_runtime_with_gateway_managed_lifecycle(driver.clone(), "arbitrary").await;
81678178

81688179
for (id, name, phase) in [
81698180
("sb-unspecified", "unspecified", SandboxPhase::Unspecified),
@@ -8222,7 +8233,8 @@ mod tests {
82228233
async fn shutdown_stop_sweep_continues_after_driver_errors() {
82238234
let driver = ControlledDriver::new();
82248235
driver.set_stop_outcome(ControlledLifecycleOutcome::Error("runtime angry"));
8225-
let runtime = test_runtime_for_driver(driver.clone(), "podman").await;
8236+
let runtime =
8237+
test_runtime_with_gateway_managed_lifecycle(driver.clone(), "arbitrary").await;
82268238
for (id, name) in [("sb-1", "one"), ("sb-2", "two")] {
82278239
runtime
82288240
.store
@@ -8244,7 +8256,8 @@ mod tests {
82448256
async fn shutdown_stop_sweep_bounds_driver_concurrency() {
82458257
let driver = ControlledDriver::new();
82468258
driver.block_stop();
8247-
let runtime = test_runtime_for_driver(driver.clone(), "docker").await;
8259+
let runtime =
8260+
test_runtime_with_gateway_managed_lifecycle(driver.clone(), "arbitrary").await;
82488261
for index in 0..=SHUTDOWN_STOP_CONCURRENCY {
82498262
runtime
82508263
.store
@@ -8283,7 +8296,8 @@ mod tests {
82838296
#[tokio::test]
82848297
async fn shutdown_stop_sweep_rechecks_intent_after_acquiring_gate() {
82858298
let driver = ControlledDriver::new();
8286-
let runtime = test_runtime_for_driver(driver.clone(), "docker").await;
8299+
let runtime =
8300+
test_runtime_with_gateway_managed_lifecycle(driver.clone(), "arbitrary").await;
82878301
runtime
82888302
.store
82898303
.put_message(&sandbox_record("sb-1", "sandbox", SandboxPhase::Ready))
@@ -8318,10 +8332,11 @@ mod tests {
83188332
}
83198333

83208334
#[tokio::test]
8321-
async fn shutdown_stop_sweep_runs_for_each_local_driver() {
8322-
for driver_name in ["docker", "podman", "vm"] {
8335+
async fn shutdown_stop_sweep_runs_for_any_capable_driver() {
8336+
for driver_name in ["arbitrary", "docker"] {
83238337
let driver = ControlledDriver::new();
8324-
let runtime = test_runtime_for_driver(driver.clone(), driver_name).await;
8338+
let runtime =
8339+
test_runtime_with_gateway_managed_lifecycle(driver.clone(), driver_name).await;
83258340
runtime
83268341
.store
83278342
.put_message(&sandbox_record("sb-1", "sandbox", SandboxPhase::Ready))
@@ -8342,8 +8357,8 @@ mod tests {
83428357
}
83438358

83448359
#[tokio::test]
8345-
async fn shutdown_stop_sweep_skips_kubernetes_and_extension_drivers() {
8346-
for driver_name in ["kubernetes", "extension"] {
8360+
async fn shutdown_stop_sweep_skips_drivers_without_capability() {
8361+
for driver_name in ["docker", "kubernetes", "extension"] {
83478362
let driver = ControlledDriver::new();
83488363
let runtime = test_runtime_for_driver(driver.clone(), driver_name).await;
83498364
runtime
@@ -8368,7 +8383,8 @@ mod tests {
83688383
#[tokio::test]
83698384
async fn start_persisted_sandboxes_starts_running_phases() {
83708385
let driver = ControlledDriver::new();
8371-
let runtime = test_runtime_for_driver(driver.clone(), "docker").await;
8386+
let runtime =
8387+
test_runtime_with_gateway_managed_lifecycle(driver.clone(), "arbitrary").await;
83728388

83738389
for (id, name, phase) in [
83748390
("sb-unspecified", "unspecified", SandboxPhase::Unspecified),
@@ -8470,7 +8486,7 @@ mod tests {
84708486
async fn start_persisted_sandboxes_marks_missing_backend_as_error() {
84718487
let driver = ControlledDriver::new();
84728488
driver.set_start_outcome(ControlledLifecycleOutcome::NotFound);
8473-
let runtime = test_runtime_for_driver(driver, "podman").await;
8489+
let runtime = test_runtime_with_gateway_managed_lifecycle(driver, "arbitrary").await;
84748490

84758491
let sandbox = sandbox_record("sb-1", "missing", SandboxPhase::Ready);
84768492
runtime.store.put_message(&sandbox).await.unwrap();
@@ -8500,7 +8516,7 @@ mod tests {
85008516
async fn start_persisted_sandboxes_marks_failed_start_as_error() {
85018517
let driver = ControlledDriver::new();
85028518
driver.set_start_outcome(ControlledLifecycleOutcome::Error("runtime angry"));
8503-
let runtime = test_runtime_for_driver(driver, "vm").await;
8519+
let runtime = test_runtime_with_gateway_managed_lifecycle(driver, "arbitrary").await;
85048520

85058521
let sandbox = sandbox_record("sb-1", "broken", SandboxPhase::Provisioning);
85068522
runtime.store.put_message(&sandbox).await.unwrap();
@@ -8527,10 +8543,11 @@ mod tests {
85278543
}
85288544

85298545
#[tokio::test]
8530-
async fn start_persisted_sandboxes_runs_for_each_local_driver() {
8531-
for driver_name in ["docker", "podman", "vm"] {
8546+
async fn start_persisted_sandboxes_runs_for_any_capable_driver() {
8547+
for driver_name in ["arbitrary", "docker"] {
85328548
let driver = ControlledDriver::new();
8533-
let runtime = test_runtime_for_driver(driver.clone(), driver_name).await;
8549+
let runtime =
8550+
test_runtime_with_gateway_managed_lifecycle(driver.clone(), driver_name).await;
85348551
let sandbox = sandbox_record("sb-1", "local", SandboxPhase::Ready);
85358552
runtime.store.put_message(&sandbox).await.unwrap();
85368553

@@ -8545,8 +8562,8 @@ mod tests {
85458562
}
85468563

85478564
#[tokio::test]
8548-
async fn start_persisted_sandboxes_skips_kubernetes_and_extension_drivers() {
8549-
for driver_name in ["kubernetes", "extension"] {
8565+
async fn start_persisted_sandboxes_skips_drivers_without_capability() {
8566+
for driver_name in ["docker", "kubernetes", "extension"] {
85508567
let driver = ControlledDriver::new();
85518568
let runtime = test_runtime_for_driver(driver.clone(), driver_name).await;
85528569
let sandbox = sandbox_record("sb-1", "remote", SandboxPhase::Ready);
@@ -8773,6 +8790,7 @@ mod tests {
87738790
let driver = FakeComputeDriver::new()
87748791
.with_driver_name("fake-remote-driver")
87758792
.with_default_image("openshell/sandbox:remote")
8793+
.with_gateway_managed_lifecycle()
87768794
.with_gateway_listener_requirement(
87778795
"172.19.0.1:17670",
87788796
"external driver managed bridge",

‎crates/openshell-server/src/test_support.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct FakeComputeDriverState {
7474
driver_name: String,
7575
driver_version: String,
7676
default_image: String,
77+
gateway_managed_lifecycle: bool,
7778
gateway_listener_requirements: Vec<GatewayListenerRequirement>,
7879
gateway_listener_requirements_supported: bool,
7980
sandboxes: HashMap<String, DriverSandbox>,
@@ -95,6 +96,7 @@ impl FakeComputeDriver {
9596
driver_name: "fake-compute-driver".to_string(),
9697
driver_version: "test".to_string(),
9798
default_image: "openshell/sandbox:test".to_string(),
99+
gateway_managed_lifecycle: false,
98100
gateway_listener_requirements: Vec::new(),
99101
gateway_listener_requirements_supported: true,
100102
sandboxes: HashMap::new(),
@@ -122,6 +124,12 @@ impl FakeComputeDriver {
122124
self
123125
}
124126

127+
#[must_use]
128+
pub fn with_gateway_managed_lifecycle(self) -> Self {
129+
self.with_state(|state| state.gateway_managed_lifecycle = true);
130+
self
131+
}
132+
125133
#[must_use]
126134
pub fn with_gateway_listener_requirement(
127135
self,
@@ -241,6 +249,7 @@ impl ComputeDriver for FakeComputeDriver {
241249
driver_name: state.driver_name.clone(),
242250
driver_version: state.driver_version.clone(),
243251
default_image: state.default_image.clone(),
252+
gateway_managed_lifecycle: state.gateway_managed_lifecycle,
244253
}
245254
});
246255
Ok(Response::new(response))

‎proto/compute_driver.proto‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ message GetCapabilitiesResponse {
7575
string driver_version = 2;
7676
// Default sandbox image recommended by the driver.
7777
string default_image = 3;
78+
// Whether the gateway should stop running sandbox compute during graceful
79+
// shutdown and restart the retained running intent on startup.
80+
bool gateway_managed_lifecycle = 6;
7881
}
7982

8083
message GetGatewayListenerRequirementsRequest {}

0 commit comments

Comments
 (0)