@@ -540,6 +540,7 @@ pub struct ComputeRuntime {
540540 sync_lock : Arc < Mutex < ( ) > > ,
541541 lifecycle_gates : Arc < LifecycleGateRegistry > ,
542542 gateway_listener_requirements : Vec < GatewayListenerRequirement > ,
543+ gateway_managed_lifecycle : bool ,
543544 replica_id : String ,
544545}
545546
@@ -569,6 +570,7 @@ impl ComputeRuntime {
569570 sandbox_watch_bus : SandboxWatchBus ,
570571 tracing_log_bus : TracingLogBus ,
571572 supervisor_sessions : Arc < SupervisorSessionRegistry > ,
573+ gateway_managed_lifecycle : bool ,
572574 ) -> Result < Self , ComputeError > {
573575 let capabilities = driver
574576 . get_capabilities ( Request :: new ( GetCapabilitiesRequest { } ) )
@@ -655,6 +657,7 @@ impl ComputeRuntime {
655657 sync_lock : Arc :: new ( Mutex :: new ( ( ) ) ) ,
656658 lifecycle_gates : Arc :: new ( LifecycleGateRegistry :: default ( ) ) ,
657659 gateway_listener_requirements,
660+ gateway_managed_lifecycle,
658661 replica_id : lease:: replica_id ( ) ,
659662 } )
660663 }
@@ -691,6 +694,7 @@ impl ComputeRuntime {
691694 sandbox_watch_bus : SandboxWatchBus ,
692695 tracing_log_bus : TracingLogBus ,
693696 supervisor_sessions : Arc < SupervisorSessionRegistry > ,
697+ gateway_managed_lifecycle : bool ,
694698 ) -> Result < Self , ComputeError > {
695699 let driver: SharedComputeDriver = Arc :: new ( RemoteComputeDriver :: new ( endpoint. channel ) ) ;
696700 Self :: from_driver (
@@ -702,6 +706,7 @@ impl ComputeRuntime {
702706 sandbox_watch_bus,
703707 tracing_log_bus,
704708 supervisor_sessions,
709+ gateway_managed_lifecycle,
705710 )
706711 . await
707712 }
@@ -1934,14 +1939,10 @@ impl ComputeRuntime {
19341939 /// persisted lifecycle intent.
19351940 ///
19361941 /// An explicit sandbox stop persists `Stopped`; gateway shutdown does not.
1937- /// Docker, Podman, and VM compute is stopped through the same public driver
1938- /// RPC and restarted from retained running intent. Kubernetes remains
1939- /// cluster-owned.
1942+ /// Registrations whose compute lifecycle is gateway-owned are stopped
1943+ /// through the same public driver RPC and restarted from retained intent.
19401944 async fn stop_persisted_sandboxes_on_shutdown ( & self ) -> Result < ( ) , String > {
1941- if !matches ! (
1942- self . driver_kind( ) ,
1943- Some ( ComputeDriverKind :: Docker | ComputeDriverKind :: Podman | ComputeDriverKind :: Vm )
1944- ) {
1945+ if !self . gateway_managed_lifecycle {
19451946 return Ok ( ( ) ) ;
19461947 }
19471948
@@ -2024,17 +2025,14 @@ impl ComputeRuntime {
20242025 /// Reconcile running intent for local compute after a gateway restart.
20252026 ///
20262027 /// `StartSandbox` is idempotent, so call it for every persisted phase that
2027- /// requires running compute on Docker, Podman, and VM . Stable stopped,
2028- /// deleting, and error states are deliberately left alone.
2028+ /// requires running compute for gateway-owned registrations . Stable
2029+ /// stopped, deleting, and error states are deliberately left alone.
20292030 ///
20302031 /// Should be called once at gateway startup, before watchers spawn,
20312032 /// so the watch loop sees the post-start state on its first poll.
20322033 pub async fn start_persisted_sandboxes ( & self ) -> Result < ( ) , String > {
20332034 self . recover_persisted_lifecycle_transitions ( ) . await ?;
2034- if !matches ! (
2035- self . driver_kind( ) ,
2036- Some ( ComputeDriverKind :: Docker | ComputeDriverKind :: Podman | ComputeDriverKind :: Vm )
2037- ) {
2035+ if !self . gateway_managed_lifecycle {
20382036 return Ok ( ( ) ) ;
20392037 }
20402038
@@ -3970,6 +3968,7 @@ pub async fn new_test_runtime_with_driver(
39703968 sync_lock : Arc :: new ( Mutex :: new ( ( ) ) ) ,
39713969 lifecycle_gates : Arc :: new ( LifecycleGateRegistry :: default ( ) ) ,
39723970 gateway_listener_requirements : Vec :: new ( ) ,
3971+ gateway_managed_lifecycle : false ,
39733972 replica_id : "test-replica" . to_string ( ) ,
39743973 }
39753974}
@@ -4651,10 +4650,20 @@ mod tests {
46514650 sync_lock : Arc :: new ( Mutex :: new ( ( ) ) ) ,
46524651 lifecycle_gates : Arc :: new ( LifecycleGateRegistry :: default ( ) ) ,
46534652 gateway_listener_requirements : Vec :: new ( ) ,
4653+ gateway_managed_lifecycle : false ,
46544654 replica_id : "test-replica" . to_string ( ) ,
46554655 }
46564656 }
46574657
4658+ async fn test_runtime_with_gateway_managed_lifecycle (
4659+ driver : SharedComputeDriver ,
4660+ driver_name : & str ,
4661+ ) -> ComputeRuntime {
4662+ let mut runtime = test_runtime_for_driver ( driver, driver_name) . await ;
4663+ runtime. gateway_managed_lifecycle = true ;
4664+ runtime
4665+ }
4666+
46584667 fn register_test_supervisor_session ( runtime : & ComputeRuntime , sandbox_id : & str ) {
46594668 let ( tx, _rx) = mpsc:: channel ( 1 ) ;
46604669 let ( shutdown_tx, _shutdown_rx) = oneshot:: channel ( ) ;
@@ -8035,7 +8044,8 @@ mod tests {
80358044 #[ tokio:: test]
80368045 async fn shutdown_stops_running_intent_without_changing_persisted_phase ( ) {
80378046 let driver = ControlledDriver :: new ( ) ;
8038- let runtime = test_runtime_for_driver ( driver. clone ( ) , "docker" ) . await ;
8047+ let runtime =
8048+ test_runtime_with_gateway_managed_lifecycle ( driver. clone ( ) , "arbitrary" ) . await ;
80398049
80408050 for ( id, name, phase) in [
80418051 ( "sb-unspecified" , "unspecified" , SandboxPhase :: Unspecified ) ,
@@ -8094,7 +8104,8 @@ mod tests {
80948104 async fn shutdown_stop_sweep_continues_after_driver_errors ( ) {
80958105 let driver = ControlledDriver :: new ( ) ;
80968106 driver. set_stop_outcome ( ControlledLifecycleOutcome :: Error ( "runtime angry" ) ) ;
8097- let runtime = test_runtime_for_driver ( driver. clone ( ) , "podman" ) . await ;
8107+ let runtime =
8108+ test_runtime_with_gateway_managed_lifecycle ( driver. clone ( ) , "arbitrary" ) . await ;
80988109 for ( id, name) in [ ( "sb-1" , "one" ) , ( "sb-2" , "two" ) ] {
80998110 runtime
81008111 . store
@@ -8113,10 +8124,11 @@ mod tests {
81138124 }
81148125
81158126 #[ tokio:: test]
8116- async fn shutdown_stop_sweep_runs_for_each_local_driver ( ) {
8117- for driver_name in [ "docker " , "podman" , "vm "] {
8127+ async fn shutdown_stop_sweep_runs_for_any_registered_driver_policy ( ) {
8128+ for driver_name in [ "arbitrary " , "docker " ] {
81188129 let driver = ControlledDriver :: new ( ) ;
8119- let runtime = test_runtime_for_driver ( driver. clone ( ) , driver_name) . await ;
8130+ let runtime =
8131+ test_runtime_with_gateway_managed_lifecycle ( driver. clone ( ) , driver_name) . await ;
81208132 runtime
81218133 . store
81228134 . put_message ( & sandbox_record ( "sb-1" , "sandbox" , SandboxPhase :: Ready ) )
@@ -8137,8 +8149,8 @@ mod tests {
81378149 }
81388150
81398151 #[ tokio:: test]
8140- async fn shutdown_stop_sweep_skips_kubernetes_and_extension_drivers ( ) {
8141- for driver_name in [ "kubernetes" , "extension" ] {
8152+ async fn shutdown_stop_sweep_skips_drivers_without_registered_policy ( ) {
8153+ for driver_name in [ "docker" , " kubernetes", "extension" ] {
81428154 let driver = ControlledDriver :: new ( ) ;
81438155 let runtime = test_runtime_for_driver ( driver. clone ( ) , driver_name) . await ;
81448156 runtime
@@ -8163,7 +8175,8 @@ mod tests {
81638175 #[ tokio:: test]
81648176 async fn start_persisted_sandboxes_starts_running_phases ( ) {
81658177 let driver = ControlledDriver :: new ( ) ;
8166- let runtime = test_runtime_for_driver ( driver. clone ( ) , "docker" ) . await ;
8178+ let runtime =
8179+ test_runtime_with_gateway_managed_lifecycle ( driver. clone ( ) , "arbitrary" ) . await ;
81678180
81688181 for ( id, name, phase) in [
81698182 ( "sb-unspecified" , "unspecified" , SandboxPhase :: Unspecified ) ,
@@ -8202,7 +8215,7 @@ mod tests {
82028215 async fn start_persisted_sandboxes_marks_missing_backend_as_error ( ) {
82038216 let driver = ControlledDriver :: new ( ) ;
82048217 driver. set_start_outcome ( ControlledLifecycleOutcome :: NotFound ) ;
8205- let runtime = test_runtime_for_driver ( driver, "podman " ) . await ;
8218+ let runtime = test_runtime_with_gateway_managed_lifecycle ( driver, "arbitrary " ) . await ;
82068219
82078220 let sandbox = sandbox_record ( "sb-1" , "missing" , SandboxPhase :: Ready ) ;
82088221 runtime. store . put_message ( & sandbox) . await . unwrap ( ) ;
@@ -8232,7 +8245,7 @@ mod tests {
82328245 async fn start_persisted_sandboxes_marks_failed_start_as_error ( ) {
82338246 let driver = ControlledDriver :: new ( ) ;
82348247 driver. set_start_outcome ( ControlledLifecycleOutcome :: Error ( "runtime angry" ) ) ;
8235- let runtime = test_runtime_for_driver ( driver, "vm " ) . await ;
8248+ let runtime = test_runtime_with_gateway_managed_lifecycle ( driver, "arbitrary " ) . await ;
82368249
82378250 let sandbox = sandbox_record ( "sb-1" , "broken" , SandboxPhase :: Provisioning ) ;
82388251 runtime. store . put_message ( & sandbox) . await . unwrap ( ) ;
@@ -8259,10 +8272,11 @@ mod tests {
82598272 }
82608273
82618274 #[ tokio:: test]
8262- async fn start_persisted_sandboxes_runs_for_each_local_driver ( ) {
8263- for driver_name in [ "docker " , "podman" , "vm "] {
8275+ async fn start_persisted_sandboxes_runs_for_any_registered_driver_policy ( ) {
8276+ for driver_name in [ "arbitrary " , "docker " ] {
82648277 let driver = ControlledDriver :: new ( ) ;
8265- let runtime = test_runtime_for_driver ( driver. clone ( ) , driver_name) . await ;
8278+ let runtime =
8279+ test_runtime_with_gateway_managed_lifecycle ( driver. clone ( ) , driver_name) . await ;
82668280 let sandbox = sandbox_record ( "sb-1" , "local" , SandboxPhase :: Ready ) ;
82678281 runtime. store . put_message ( & sandbox) . await . unwrap ( ) ;
82688282
@@ -8277,8 +8291,8 @@ mod tests {
82778291 }
82788292
82798293 #[ tokio:: test]
8280- async fn start_persisted_sandboxes_skips_kubernetes_and_extension_drivers ( ) {
8281- for driver_name in [ "kubernetes" , "extension" ] {
8294+ async fn start_persisted_sandboxes_skips_drivers_without_registered_policy ( ) {
8295+ for driver_name in [ "docker" , " kubernetes", "extension" ] {
82828296 let driver = ControlledDriver :: new ( ) ;
82838297 let runtime = test_runtime_for_driver ( driver. clone ( ) , driver_name) . await ;
82848298 let sandbox = sandbox_record ( "sb-1" , "remote" , SandboxPhase :: Ready ) ;
@@ -8350,6 +8364,7 @@ mod tests {
83508364 SandboxWatchBus :: new ( ) ,
83518365 TracingLogBus :: new ( ) ,
83528366 Arc :: new ( SupervisorSessionRegistry :: new ( ) ) ,
8367+ false ,
83538368 )
83548369 . await
83558370 . unwrap ( ) ;
@@ -8475,6 +8490,7 @@ mod tests {
84758490 SandboxWatchBus :: new ( ) ,
84768491 TracingLogBus :: new ( ) ,
84778492 Arc :: new ( SupervisorSessionRegistry :: new ( ) ) ,
8493+ false ,
84788494 )
84798495 . await
84808496 . unwrap ( ) ;
@@ -8522,6 +8538,7 @@ mod tests {
85228538 SandboxWatchBus :: new ( ) ,
85238539 TracingLogBus :: new ( ) ,
85248540 Arc :: new ( SupervisorSessionRegistry :: new ( ) ) ,
8541+ false ,
85258542 )
85268543 . await
85278544 . unwrap ( ) ;
@@ -8641,6 +8658,7 @@ mod tests {
86418658 SandboxWatchBus :: new ( ) ,
86428659 TracingLogBus :: new ( ) ,
86438660 Arc :: new ( SupervisorSessionRegistry :: new ( ) ) ,
8661+ false ,
86448662 )
86458663 . await
86468664 . unwrap ( ) ;
0 commit comments