Recommendation: Changes Requested
The core startup reorder—opening the host prefix store before RankExecutor::new() launches persistent GPU workers—directly fixes a verified cuModuleLoadData deadlock with a minimal, model-agnostic footprint (helios/src/server/runtime.rs, +52/−31). However, the PR cannot merge as-is because (1) the three new post-open error-cleanup blocks violate the HostStore::close ownership contract by swallowing close errors, dropping the store on failure/unwind, and reporting drained: true anyway (duplicating the existing Worker::close_store helper that already handles all of this safely), and (2) the cited validation run omits the server feature and therefore never compiled or tested a single line of the diff.
Merge Risk
Level: Medium
- Blast radius:
ModelRuntime::start_retaining_drain(helios/src/server/runtime.rs:657-796) runs on every prefix-cache offload configuration (CPU/GPU compression, memory/disk/pool tiers, single-rank and multi-rank), not just--lossless-kv-compression gpu. - Happy-path / hot-path impact: Zero steady-state runtime cost and strictly less startup concurrency—
offload::opencompletes on theflare-modelthread beforeRankExecutor::newruns tuning graphs or launches persistent GPU workers. - Failure-path risk: Today, if
RankExecutor::newor scheduler setup fails andstore.close()fails or unwinds, the new ad-hoc cleanup reportsdrained: truetoflare/src/controller.rs:2905-2910and drops the store while transfer/pool/disk threads may still reference registered host slabs or GPU destinations.
Walkthrough
helios/src/server/runtime.rs:657-691: Movescrate::offload::open(prepared, gpu_cubins, copy_gate)ahead ofRankExecutor::new(manifest, peers), readingmanifest.offloaddirectly after the multi-process non-sharded guard (:644-656) soGpuRankCodec::new(helios/src/offload/transfer/gpu_codec.rs:268-283) loads the deferredkv_codec_gpucubin beforecontrol.start()?(helios/src/execution/transport.rs:793-808) launches persistent GPU workers.helios/src/server/runtime.rs:695-707: Adds early cleanup onRankExecutor::newfailure (let _ = store.close();), returningShutdown { drained: true, error: Some(error) }.helios/src/server/runtime.rs:714-726and:784-796: Adds cleanup on scheduler construction and scheduler configuration failures—callingexecutor.close(), thenlet _ = store.close()ifshutdown.drainedorstd::mem::forget(store)otherwise.helios/src/server/runtime.rs:806,:829-830: Preserves happy-pathworker.attach_store(store)and LIFO shutdown (executor.close()beforeworker.close_store(&mut shutdown)).
Pre-merge Checks
- [PASS] Security / malicious screen: Single-file startup reorder in
helios/src/server/runtime.rs; no newunsafeblocks, dependencies, flags, or external I/O. - [PASS] Charter & value fit: Addresses a real root-cause CUDA startup deadlock (introduced by #504) at the right layer with minimal shared-code footprint and no per-model branches.
- [PASS] Related / duplicate / conflict check: Additive follow-up to merged #504; no conflicts with
mainor competing open PRs. - [WARN] Tests & verification evidence: The cited
cargo test -p flare-helios --features runtime-corerun leaves#[cfg(feature = "server")]disabled (helios/src/lib.rs:30-31,helios/Cargo.toml:21,25), so none of the diff was compiled or executed; no CI checks ran on9ed34da.
Blockers
-
Post-open error paths violate
HostStore::closesafety contract and duplicateWorker::close_store(helios/src/server/runtime.rs:697-706,:714-726,:784-796)- Verified behavior & impact: All three new cleanup branches run
let _ = store.close();and dropstoreon scope exit while keepingdrained: true(hardcoded at:703; preserved fromexecutor.close()at:717and:787). This directly violatesselene/src/store.rs:334-337("On failure the caller must retain the store: transfer jobs may still reference its registered host buffers and GPU destinations"), causesflare/src/controller.rs:2905-2910to treat drain as confirmed and release the GPU/core lease while host slabs may still be in use, and dropsTransferson a failed close (whoseDropunconditionally callsthread.join(),helios/src/offload/transfer.rs:841-852). Furthermore, none of the three sites wrapsstoreinManuallyDropbefore callingstore.close(), so an unwind insidestore.close()dropsstore—the exact hazardWorker::close_store(runtime.rs:1344-1364) andshutdown_retains_the_store_when_its_drain_panics(helios/src/server/runtime/phase_tests.rs:2340-2363) prevent. Because of this, the PR's claim that startup cleanup is exact LIFO-symmetric withWorker::close_storedoes not currently hold. - Concrete fix: Extract the body of
Worker::close_store(runtime.rs:1344-1364, which only usesselftoself.store.take()) into a shared helperfn close_store(store: Option<Box<dyn flare_selene::HostStore>>, shutdown: &mut Shutdown)and call it fromWorker::close_storeand all three startup failure paths:
Then onfn close_store( store: Option<Box<dyn flare_selene::HostStore>>, 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()); } } }RankExecutor::newfailure (:697-706):
And on both scheduler failure paths (Err(error) => { let mut shutdown = Shutdown { drained: true, error: Some(error.clone()), }; let _ = ready_tx.send(Err(error)); close_store(store, &mut shutdown); return shutdown; }:714-726,:784-796):
This fixes drain reporting, error preservation, unwind retention, and deletes ~25 lines plus both ad-hocErr(error) => { let _ = ready_tx.send(Err(error.clone())); let mut shutdown = executor.close(); close_store(store, &mut shutdown); shutdown.error = Some(error); return shutdown; }std::mem::forget(store)calls in one change.
- Verified behavior & impact: All three new cleanup branches run
-
Mandatory
server-feature test suite was never compiled or run (helios/src/lib.rs:30-31,helios/Cargo.toml:2,21,25)- Verified behavior & impact:
helios/src/server/runtime.rsis gated behind#[cfg(feature = "server")](helios/src/lib.rs:30-31), andruntime-coredoes not enableserver(helios/Cargo.toml:21,25). The PR's Submission Validation (cargo test -p flare-helios --features runtime-core) therefore compiled zero lines of the diff, and the PR's Suggested test command (cargo test -p helios --features runtime-core) additionally names a nonexistent crate (helios/Cargo.toml:2isflare-helios). Perdocs/design-review.md:180-184,247-251and.github/workflows/native-serving.yml:63 (not opened),68, leaving the applicable CPU crate test unrun blocks merge. - Concrete fix: Run and report the repo's standard Helios test command (with
FLARE_TEST_TEMPLATE_DIR/ulimit -lperAGENTS.md:317-327):
and correct the suggested test command in the PR description.cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server
- Verified behavior & impact:
Should Fix
None.
Subtract / Simplify
- Deduplicate the three post-open cleanup paths into
close_store(helios/src/server/runtime.rs:697-706,:714-726,:784-796,:1344-1364): Covered in Blocker #1—extractingWorker::close_storeinto a module-level helper eliminates ~25 newly added lines, removes bothstd::mem::forget(store)calls, and unifies all four teardown paths under the existingManuallyDropcontract already tested byhelios/src/server/runtime/phase_tests.rs:2262-2363.
Nits
helios/src/server/runtime.rs:663-682: Pre-existing code moved verbatim, so optional—flattening the.and_then(...).map(...).transpose()3-tuple chain into a singleand_thenreturningOption<Result<_>>would make the store-open block a few lines shorter.
Dropped on verification
- Upstream Dossier #5 / Correctness table ("Cause #1:
kv_codec_gpudeferral inhelios/src/runtime_core/mod.rscould not be located in the tree"): Verified false.helios/src/runtime_core/mod.rs:755-792definesunsafe fn prepare_kernels(..., skip_module: Option<&str>)and skipsmodule.name == skip_module(:788-791), called withcodec_gpu_module.as_deref()athelios/src/runtime_core/model.rs:628,821. Cause #1 in the PR description is accurate. - Upstream Correctness A2 ("
drained: trueonoffload::openfailure atruntime.rs:684-690is an unverified assumption"): Verified safe / false alarm. No executor or GPU kernel exists yet at:684-690, and on mid-way failure insideflare_selene::offload::open(selene/src/offload.rs:802-891), already-started rank threads are joined byTransfers::drop(helios/src/offload/transfer.rs:653,841-852) and any started pool client is closed/joined byPoolClient::drop(selene/src/pool/client.rs:343-347). - Upstream Correctness B2 ("
worker_metrics.codec_placementnow leaves a metrics object advertising codec placement when startup aborts"): Verified false.metricsis a localArc<Metrics>constructed insideModelRuntime::start_retaining_drain(helios/src/server/runtime.rs:623-640) and is dropped without ever being returned or exposed when startup returnsErr(StartFailure)(:863-878). Printingintake_warning()slightly earlier to stderr on offload open is benign. - Upstream Subtraction #2 ("Move
codec_placementandintake_warninginsidecrate::offload::open"): Dropped as architecturally invalid / counterproductive.helios/src/offload/mod.rscompiles unconditionally (helios/src/lib.rs:19), whereascrate::server::metrics::Metricsonly exists under#[cfg(feature = "server")](helios/src/lib.rs:30-31). Threading callbacks and alog_to_stderrflag intooffload::openwould worsen coupling rather than simplify it. - Upstream Correctness B1 ("Early
binding.take()makesBinding::sharded()returnfalselater in startup"): Dropped as low-signal / no live issue. Verified the only caller (runtime.rs:645) executes beforebinding.take(), andRankExecutor::new/ThreadedExecutoronly readcopy_gate(),shares(), andrank()(helios/src/execution/ranks.rs:127,helios/src/execution/threaded.rs:1286-1290). - Upstream Correctness D2 ("Add a mock/test-double ordering regression test for
ModelRuntime::start"): Dropped as over-engineered.ModelRuntime::startconstructs a real CUDARankExecutor; introducing mock traits solely to test call ordering insideModelRuntime::startwould add abstraction overhead discouraged bydocs/design-review.md:187-189. Sharingclose_store(Blocker #1) plus running the realserver-feature test suite (Blocker #2) is the right bar. - Upstream Correctness D1 ("
exact LIFO-symmetricclaim inaccurate on error paths"): Folded into Blocker #1 as a direct corollary.