From 9ed34da5633337f7d3113263d69b8a8726575312 Mon Sep 17 00:00:00 2001 From: Eduardo Fonseca Date: Wed, 2 Dec 2026 17:57:39 -0500 Subject: [PATCH 1/2] fix(helios): open offload before persistent worker Move offload store opening ahead of executor construction and close the store and executor in LIFO order on every early failure path, preserving ownership of drained resources. This lets GPU KV-compressed cores reach server startup without the persistent-worker startup deadlock. Other runtime GKV1 contention remains outside this change. Validation: cargo test -p flare-helios --features runtime-core on Hades Linux aarch64: 1243 passed, 0 failed, 37 ignored. Existing GB300 before/after hardware evidence is supplied in the PR description; no fresh GPU startup reproduction was run for this submission. Signed-off-by: Eduardo Fonseca Design-Signed-Off-By: Iris; design-review=2e5b Signed-off-by: Iris (Eduardo's coding agent) --- helios/src/server/runtime.rs | 83 ++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 31 deletions(-) diff --git a/helios/src/server/runtime.rs b/helios/src/server/runtime.rs index 2f9b6bfd6..c01403baf 100644 --- a/helios/src/server/runtime.rs +++ b/helios/src/server/runtime.rs @@ -654,12 +654,50 @@ impl ModelRuntime { error: Some(error), }; } + // Open the host prefix store before RankExecutor::new launches + // any persistent GPU worker: GKV1's cuModuleLoadData blocks + // waiting for active kernels on the context to quiesce, which + // deadlocks against a running persistent worker. Shutdown + // already runs in the symmetric LIFO order (executor.close() + // before worker.close_store()). + let store = match manifest + .offload + .as_ref() + .and_then(|binding| { + let copy_gate = binding.copy_gate(); + binding + .take() + .map(|(prepared, gpu_cubins)| (prepared, gpu_cubins, copy_gate)) + }) + .map(|(prepared, gpu_cubins, copy_gate)| { + if let Some(rank) = prepared.geometry.first() { + worker_metrics.codec_placement(rank.placement); + } + if let Some(warning) = prepared.intake_warning() { + if log_to_stderr { eprintln!("warning: {warning}"); } + } + crate::offload::open(prepared, gpu_cubins, copy_gate) + }) + .transpose() + { + Ok(store) => store, + Err(error) => { + let _ = ready_tx.send(Err(error.clone())); + return Shutdown { + drained: true, + error: Some(error), + }; + } + }; // SAFETY: start's caller retains all prepared resources through // confirmed drain. This thread exclusively owns the executor; // construction binds both streams to the manifest's context. let mut executor = match unsafe { RankExecutor::new(manifest, peers) } { Ok(executor) => executor, Err(error) => { + if let Some(mut store) = store { + let _ = store.close(); + } let _ = ready_tx.send(Err(error.clone())); return Shutdown { drained: true, @@ -676,6 +714,13 @@ impl ModelRuntime { Err(error) => { let _ = ready_tx.send(Err(error.clone())); let mut shutdown = executor.close(); + if shutdown.drained { + if let Some(mut store) = store { + let _ = store.close(); + } + } else if let Some(store) = store { + std::mem::forget(store); + } shutdown.error = Some(error); return shutdown; } @@ -739,40 +784,16 @@ impl ModelRuntime { { let _ = ready_tx.send(Err(error.clone())); let mut shutdown = executor.close(); + if shutdown.drained { + if let Some(mut store) = store { + let _ = store.close(); + } + } else if let Some(store) = store { + std::mem::forget(store); + } shutdown.error = Some(error); return shutdown; } - // The host prefix store opens its transfer threads on every - // rank's context, which the loader prepared for this process. - let store = match executor - .manifest() - .offload - .as_ref() - .and_then(|binding| { - let copy_gate = binding.copy_gate(); - binding - .take() - .map(|(prepared, gpu_cubins)| (prepared, gpu_cubins, copy_gate)) - }) - .map(|(prepared, gpu_cubins, copy_gate)| { - if let Some(rank) = prepared.geometry.first() { - worker_metrics.codec_placement(rank.placement); - } - if let Some(warning) = prepared.intake_warning() { - if log_to_stderr { eprintln!("warning: {warning}"); } - } - crate::offload::open(prepared, gpu_cubins, copy_gate) - }) - .transpose() - { - Ok(store) => store, - Err(error) => { - let _ = ready_tx.send(Err(error.clone())); - let mut shutdown = executor.close(); - shutdown.error = Some(error); - return shutdown; - } - }; let mut worker = Worker::new( &worker_config, &frontend, From 501bb0e9f0c0a26bce0a1d2bd2de4ccdce9ddba4 Mon Sep 17 00:00:00 2001 From: Eduardo Fonseca Date: Thu, 3 Dec 2026 10:15:07 -0500 Subject: [PATCH 2/2] fix(helios): preserve store ownership on startup failures Reuse the worker's drain-aware store close logic for executor and scheduler startup failure paths. Retain the host store when executor drain or store close fails or unwinds, and preserve the first startup error. Validation on Hades Linux aarch64: FLARE_TEST_TEMPLATE_DIR=/tmp/flare-test-templates-pr698 cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server 1897 passed, 0 failed, 84 ignored. The gated muse_spark fixture was unavailable; its only consumer is ignored. No fresh GB300 GKV1 startup reproduction was run. Signed-off-by: Eduardo Fonseca Design-Signed-Off-By: Iris; design-review=2e5b Signed-off-by: Iris (Eduardo's coding agent) --- helios/src/server/runtime.rs | 69 ++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/helios/src/server/runtime.rs b/helios/src/server/runtime.rs index c01403baf..3a06e36a3 100644 --- a/helios/src/server/runtime.rs +++ b/helios/src/server/runtime.rs @@ -695,14 +695,13 @@ impl ModelRuntime { let mut executor = match unsafe { RankExecutor::new(manifest, peers) } { Ok(executor) => executor, Err(error) => { - if let Some(mut store) = store { - let _ = store.close(); - } - let _ = ready_tx.send(Err(error.clone())); - return Shutdown { + let mut shutdown = Shutdown { drained: true, - error: Some(error), + error: Some(error.clone()), }; + let _ = ready_tx.send(Err(error)); + close_store(store, &mut shutdown); + return shutdown; } }; let mut scheduler = match crate::model::scheduler_capabilities_with_manifest( @@ -714,13 +713,7 @@ impl ModelRuntime { Err(error) => { let _ = ready_tx.send(Err(error.clone())); let mut shutdown = executor.close(); - if shutdown.drained { - if let Some(mut store) = store { - let _ = store.close(); - } - } else if let Some(store) = store { - std::mem::forget(store); - } + close_store(store, &mut shutdown); shutdown.error = Some(error); return shutdown; } @@ -784,13 +777,7 @@ impl ModelRuntime { { let _ = ready_tx.send(Err(error.clone())); let mut shutdown = executor.close(); - if shutdown.drained { - if let Some(mut store) = store { - let _ = store.close(); - } - } else if let Some(store) = store { - std::mem::forget(store); - } + close_store(store, &mut shutdown); shutdown.error = Some(error); return shutdown; } @@ -1147,6 +1134,28 @@ struct CopyoutResources { next: Option<(usize, u32, bool)>, } +fn close_store(store: Option>, shutdown: &mut Shutdown) { + let Some(store) = store else { + return; + }; + // Retain registered slabs if either drain fails, including an unwind + // inside the store's close operation. + let mut store = std::mem::ManuallyDrop::new(store); + if !shutdown.drained { + return; + } + shutdown.drained = false; + match store.close() { + Ok(()) => { + shutdown.drained = true; + drop(std::mem::ManuallyDrop::into_inner(store)); + } + Err(error) => { + shutdown.error.get_or_insert(error.into()); + } + } +} + struct Worker<'a> { config: &'a ModelConfig, frontend: &'a crate::frontend::Frontend, @@ -1342,25 +1351,7 @@ impl<'a> Worker<'a> { } fn close_store(&mut self, shutdown: &mut Shutdown) { - let Some(store) = self.store.take() else { - return; - }; - // Retain registered slabs if either drain fails, including an unwind - // inside the store's close operation. - let mut store = std::mem::ManuallyDrop::new(store); - if !shutdown.drained { - return; - } - shutdown.drained = false; - match store.close() { - Ok(()) => { - shutdown.drained = true; - drop(std::mem::ManuallyDrop::into_inner(store)); - } - Err(error) => { - shutdown.error.get_or_insert(error.into()); - } - } + close_store(self.store.take(), shutdown); } fn clear_active_slot(&mut self, slot: usize) -> Option> {