Skip to content

Commit 9cacfad

Browse files
drewelezar
authored andcommitted
refactor(compute): negotiate gateway-managed lifecycle
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 72fc58f commit 9cacfad

8 files changed

Lines changed: 99 additions & 42 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ 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.
202+
not follow this local gateway lifecycle. An external driver follows it only
203+
when `GetCapabilities` advertises `GATEWAY_MANAGED_LIFECYCLE`.
203204

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

‎architecture/compute-runtimes.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ implementing `ComputeDriver` out of tree.
2727
At initialization the gateway snapshots additive feature values from
2828
`GetCapabilities`; unknown values are ignored. Post-initialization lifecycle
2929
and policy behavior does not depend on the configured or advertised driver
30-
name. Startup intent reconciliation and native process-identity defaults are
31-
enabled only by their corresponding features. Driver-requested listeners are
32-
structurally validated and remain restricted to sandbox callback RPCs.
30+
name. Gateway-managed shutdown/start lifecycle and native process-identity
31+
defaults are enabled only by their corresponding features. Driver-requested
32+
listeners are structurally validated and remain restricted to sandbox callback
33+
RPCs.
3334

3435
Drivers own runtime-specific platform event interpretation. When an event should
3536
drive client provisioning UI, the driver attaches the shared

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,15 +589,15 @@ mod tests {
589589
"1.0.0",
590590
"sandbox:latest",
591591
[
592-
ComputeDriverFeature::GatewayStartReconciliation,
592+
ComputeDriverFeature::GatewayManagedLifecycle,
593593
ComputeDriverFeature::PreserveUnspecifiedProcessIdentity,
594594
],
595595
);
596596

597597
assert_eq!(
598598
capabilities.features,
599599
vec![
600-
i32::from(ComputeDriverFeature::GatewayStartReconciliation),
600+
i32::from(ComputeDriverFeature::GatewayManagedLifecycle),
601601
i32::from(ComputeDriverFeature::PreserveUnspecifiedProcessIdentity),
602602
]
603603
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl DockerComputeDriver {
495495
&self.config.daemon_version,
496496
&self.config.default_image,
497497
[
498-
openshell_core::proto::compute::v1::ComputeDriverFeature::GatewayStartReconciliation,
498+
openshell_core::proto::compute::v1::ComputeDriverFeature::GatewayManagedLifecycle,
499499
openshell_core::proto::compute::v1::ComputeDriverFeature::PreserveUnspecifiedProcessIdentity,
500500
],
501501
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ impl PodmanComputeDriver {
472472
openshell_core::VERSION,
473473
&self.config.default_image,
474474
[
475-
openshell_core::proto::compute::v1::ComputeDriverFeature::GatewayStartReconciliation,
475+
openshell_core::proto::compute::v1::ComputeDriverFeature::GatewayManagedLifecycle,
476476
openshell_core::proto::compute::v1::ComputeDriverFeature::PreserveUnspecifiedProcessIdentity,
477477
],
478478
))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +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-
features: vec![ComputeDriverFeature::GatewayStartReconciliation.into()],
523+
features: vec![ComputeDriverFeature::GatewayManagedLifecycle.into()],
524524
}
525525
}
526526

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

Lines changed: 85 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,11 @@ impl ComputeRuntime {
838838
self.driver_info.features.contains(&i32::from(feature))
839839
}
840840

841+
#[must_use]
842+
pub(crate) fn uses_gateway_managed_lifecycle(&self) -> bool {
843+
self.supports_feature(ComputeDriverFeature::GatewayManagedLifecycle)
844+
}
845+
841846
#[must_use]
842847
pub(crate) fn preserves_unspecified_process_identity(&self) -> bool {
843848
self.supports_feature(ComputeDriverFeature::PreserveUnspecifiedProcessIdentity)
@@ -2056,14 +2061,10 @@ impl ComputeRuntime {
20562061
/// persisted lifecycle intent.
20572062
///
20582063
/// An explicit sandbox stop persists `Stopped`; gateway shutdown does not.
2059-
/// Docker, Podman, and VM compute is stopped through the same public driver
2060-
/// RPC and restarted from the retained running-intent phase on gateway
2061-
/// startup. Kubernetes compute remains cluster-owned and is excluded.
2064+
/// Drivers opt into stop/start ownership through their public capability
2065+
/// snapshot. Kubernetes and legacy extension drivers omit that capability.
20622066
async fn stop_persisted_sandboxes_on_shutdown(&self) -> Result<(), String> {
2063-
if !matches!(
2064-
self.driver_kind(),
2065-
Some(ComputeDriverKind::Docker | ComputeDriverKind::Podman | ComputeDriverKind::Vm)
2066-
) {
2067+
if !self.uses_gateway_managed_lifecycle() {
20672068
return Ok(());
20682069
}
20692070

@@ -2151,7 +2152,7 @@ impl ComputeRuntime {
21512152

21522153
/// Reconcile running intent for local compute after a gateway restart.
21532154
///
2154-
/// Drivers opt into this sweep through their startup capability snapshot.
2155+
/// Drivers opt into this sweep through their lifecycle capability snapshot.
21552156
/// `StartSandbox` is idempotent, so call it for every persisted phase that
21562157
/// requires running compute. Stable stopped, deleting, and error states are
21572158
/// deliberately left alone.
@@ -2160,7 +2161,7 @@ impl ComputeRuntime {
21602161
/// so the watch loop sees the post-start state on its first poll.
21612162
pub async fn start_persisted_sandboxes(&self) -> Result<(), String> {
21622163
self.recover_persisted_lifecycle_transitions().await?;
2163-
if !self.supports_feature(ComputeDriverFeature::GatewayStartReconciliation) {
2164+
if !self.uses_gateway_managed_lifecycle() {
21642165
return Ok(());
21652166
}
21662167

@@ -4096,11 +4097,11 @@ pub async fn new_test_runtime_with_driver(
40964097
) -> ComputeRuntime {
40974098
let features = match driver_name.parse::<ComputeDriverKind>().ok() {
40984099
Some(ComputeDriverKind::Docker | ComputeDriverKind::Podman) => vec![
4099-
i32::from(ComputeDriverFeature::GatewayStartReconciliation),
4100+
i32::from(ComputeDriverFeature::GatewayManagedLifecycle),
41004101
i32::from(ComputeDriverFeature::PreserveUnspecifiedProcessIdentity),
41014102
],
41024103
Some(ComputeDriverKind::Vm) => {
4103-
vec![i32::from(ComputeDriverFeature::GatewayStartReconciliation)]
4104+
vec![i32::from(ComputeDriverFeature::GatewayManagedLifecycle)]
41044105
}
41054106
_ => Vec::new(),
41064107
};
@@ -8198,7 +8199,12 @@ mod tests {
81988199
#[tokio::test]
81998200
async fn shutdown_stops_running_intent_without_changing_persisted_phase() {
82008201
let driver = ControlledDriver::new();
8201-
let runtime = test_runtime_for_driver(driver.clone(), "docker").await;
8202+
let runtime = test_runtime_for_driver_with_features(
8203+
driver.clone(),
8204+
"extension",
8205+
vec![ComputeDriverFeature::GatewayManagedLifecycle],
8206+
)
8207+
.await;
82028208

82038209
for (id, name, phase) in [
82048210
("sb-unspecified", "unspecified", SandboxPhase::Unspecified),
@@ -8257,7 +8263,12 @@ mod tests {
82578263
async fn shutdown_stop_sweep_continues_after_driver_errors() {
82588264
let driver = ControlledDriver::new();
82598265
driver.set_stop_outcome(ControlledLifecycleOutcome::Error("runtime angry"));
8260-
let runtime = test_runtime_for_driver(driver.clone(), "podman").await;
8266+
let runtime = test_runtime_for_driver_with_features(
8267+
driver.clone(),
8268+
"extension",
8269+
vec![ComputeDriverFeature::GatewayManagedLifecycle],
8270+
)
8271+
.await;
82618272
for (id, name) in [("sb-1", "one"), ("sb-2", "two")] {
82628273
runtime
82638274
.store
@@ -8279,7 +8290,12 @@ mod tests {
82798290
async fn shutdown_stop_sweep_bounds_driver_concurrency() {
82808291
let driver = ControlledDriver::new();
82818292
driver.block_stop();
8282-
let runtime = test_runtime_for_driver(driver.clone(), "docker").await;
8293+
let runtime = test_runtime_for_driver_with_features(
8294+
driver.clone(),
8295+
"extension",
8296+
vec![ComputeDriverFeature::GatewayManagedLifecycle],
8297+
)
8298+
.await;
82838299
for index in 0..=SHUTDOWN_STOP_CONCURRENCY {
82848300
runtime
82858301
.store
@@ -8318,7 +8334,12 @@ mod tests {
83188334
#[tokio::test]
83198335
async fn shutdown_stop_sweep_rechecks_intent_after_acquiring_gate() {
83208336
let driver = ControlledDriver::new();
8321-
let runtime = test_runtime_for_driver(driver.clone(), "docker").await;
8337+
let runtime = test_runtime_for_driver_with_features(
8338+
driver.clone(),
8339+
"extension",
8340+
vec![ComputeDriverFeature::GatewayManagedLifecycle],
8341+
)
8342+
.await;
83228343
runtime
83238344
.store
83248345
.put_message(&sandbox_record("sb-1", "sandbox", SandboxPhase::Ready))
@@ -8353,16 +8374,15 @@ mod tests {
83538374
}
83548375

83558376
#[tokio::test]
8356-
async fn shutdown_stop_sweep_runs_for_each_local_driver_only() {
8357-
for (driver_name, expected_calls) in [
8358-
("docker", 1),
8359-
("podman", 1),
8360-
("vm", 1),
8361-
("kubernetes", 0),
8362-
("extension", 0),
8363-
] {
8377+
async fn shutdown_stop_sweep_runs_for_any_capable_driver() {
8378+
for driver_name in ["docker", "podman", "vm", "extension"] {
83648379
let driver = ControlledDriver::new();
8365-
let runtime = test_runtime_for_driver(driver.clone(), driver_name).await;
8380+
let runtime = test_runtime_for_driver_with_features(
8381+
driver.clone(),
8382+
driver_name,
8383+
vec![ComputeDriverFeature::GatewayManagedLifecycle],
8384+
)
8385+
.await;
83668386
runtime
83678387
.store
83688388
.put_message(&sandbox_record("sb-1", "sandbox", SandboxPhase::Ready))
@@ -8376,19 +8396,43 @@ mod tests {
83768396

83778397
assert_eq!(
83788398
driver.stop_calls(),
8379-
expected_calls,
8399+
1,
83808400
"unexpected shutdown behavior for {driver_name}"
83818401
);
83828402
}
83838403
}
83848404

8405+
#[tokio::test]
8406+
async fn shutdown_stop_sweep_skips_drivers_without_feature() {
8407+
for driver_name in ["kubernetes", "docker", "extension"] {
8408+
let driver = ControlledDriver::new();
8409+
let runtime = test_runtime_for_driver(driver.clone(), driver_name).await;
8410+
runtime
8411+
.store
8412+
.put_message(&sandbox_record("sb-1", "sandbox", SandboxPhase::Ready))
8413+
.await
8414+
.unwrap();
8415+
8416+
runtime
8417+
.stop_persisted_sandboxes_on_shutdown()
8418+
.await
8419+
.unwrap();
8420+
8421+
assert_eq!(
8422+
driver.stop_calls(),
8423+
0,
8424+
"{driver_name} should retain operator-owned lifecycle"
8425+
);
8426+
}
8427+
}
8428+
83858429
#[tokio::test]
83868430
async fn start_persisted_sandboxes_starts_running_phases() {
83878431
let driver = ControlledDriver::new();
83888432
let runtime = test_runtime_for_driver_with_features(
83898433
driver.clone(),
83908434
"extension",
8391-
vec![ComputeDriverFeature::GatewayStartReconciliation],
8435+
vec![ComputeDriverFeature::GatewayManagedLifecycle],
83928436
)
83938437
.await;
83948438

@@ -8495,7 +8539,7 @@ mod tests {
84958539
let runtime = test_runtime_for_driver_with_features(
84968540
driver,
84978541
"extension",
8498-
vec![ComputeDriverFeature::GatewayStartReconciliation],
8542+
vec![ComputeDriverFeature::GatewayManagedLifecycle],
84998543
)
85008544
.await;
85018545

@@ -8530,7 +8574,7 @@ mod tests {
85308574
let runtime = test_runtime_for_driver_with_features(
85318575
driver,
85328576
"extension",
8533-
vec![ComputeDriverFeature::GatewayStartReconciliation],
8577+
vec![ComputeDriverFeature::GatewayManagedLifecycle],
85348578
)
85358579
.await;
85368580

@@ -8565,7 +8609,7 @@ mod tests {
85658609
let runtime = test_runtime_for_driver_with_features(
85668610
driver.clone(),
85678611
driver_name,
8568-
vec![ComputeDriverFeature::GatewayStartReconciliation],
8612+
vec![ComputeDriverFeature::GatewayManagedLifecycle],
85698613
)
85708614
.await;
85718615
let sandbox = sandbox_record("sb-1", "local", SandboxPhase::Ready);
@@ -8811,7 +8855,7 @@ mod tests {
88118855
.with_driver_name("fake-remote-driver")
88128856
.with_default_image("openshell/sandbox:remote")
88138857
.with_features([
8814-
ComputeDriverFeature::GatewayStartReconciliation,
8858+
ComputeDriverFeature::GatewayManagedLifecycle,
88158859
ComputeDriverFeature::PreserveUnspecifiedProcessIdentity,
88168860
])
88178861
.with_gateway_listener_requirement(
@@ -8887,6 +8931,17 @@ mod tests {
88878931
assert!(driver_config.fields.contains_key("pool"));
88888932
assert!(!driver_config.fields.contains_key("network_mode"));
88898933

8934+
driver.clear_calls();
8935+
runtime
8936+
.stop_persisted_sandboxes_on_shutdown()
8937+
.await
8938+
.unwrap();
8939+
assert!(matches!(
8940+
driver.calls().as_slice(),
8941+
[FakeComputeDriverCall::StopSandbox { sandbox_id, sandbox_name }]
8942+
if sandbox_id == "sb-uds" && sandbox_name == "uds-sandbox"
8943+
));
8944+
88908945
driver.clear_calls();
88918946
runtime.start_persisted_sandboxes().await.unwrap();
88928947
assert!(matches!(

‎proto/compute_driver.proto‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ message GetCapabilitiesResponse {
8282

8383
enum ComputeDriverFeature {
8484
COMPUTE_DRIVER_FEATURE_UNSPECIFIED = 0;
85-
// Reconcile persisted running intent by calling StartSandbox when the
86-
// gateway starts.
87-
COMPUTE_DRIVER_FEATURE_GATEWAY_START_RECONCILIATION = 1;
85+
// Let the gateway stop persisted running intent during graceful shutdown
86+
// and restart that intent when the gateway starts.
87+
COMPUTE_DRIVER_FEATURE_GATEWAY_MANAGED_LIFECYCLE = 1;
8888
// Preserve omitted process user/group fields so the runtime can apply its
8989
// native image or OCI identity defaults.
9090
COMPUTE_DRIVER_FEATURE_PRESERVE_UNSPECIFIED_PROCESS_IDENTITY = 2;

0 commit comments

Comments
 (0)