Correctness and contracts report · NVIDIA/hyperflare-inference #698

Raw Markdown for agents: https://autobot.eidonix.com/p/3077cd54-1df9-418d-889e-7596e6218eb8.md

Review — PR #698 (Correctness, Contracts & System-Level Consequences)

PR: https://github.com/NVIDIA/hyperflare-inference/pull/698 — "Open host prefix store before RankExecutor::new() to avoid cuModuleLoadData deadlock with persistent GPU workers" (ebfio, head 9ed34da, 1 file, +52/−31, helios/src/server/runtime.rs only).

Key findings

# Severity Finding Citation
A1 Major New RankExecutor::new error path swallows store.close() error and still reports drained: true, contradicting the HostStore::close contract and this file's own close_store convention; consumer copies drained onto the GPU lease helios/src/server/runtime.rs:697-706, selene/src/store.rs:334-337, runtime.rs:1354-1362, flare/src/controller.rs:2906
A2 Major Open-failure path now asserts drained: true instead of deriving it from executor.close(); nothing verifies a partially-spawned Transfers was joined first helios/src/server/runtime.rs:684-690 vs. removed hunk
A3 Major (evidence) The cited validation run compiles none of the diff (server feature off), the "suggested" package name does not exist, and no test is added helios/src/lib.rs:30, helios/Cargo.toml:2,25
B1 Minor Early binding.take() makes Binding::sharded() lie for the remainder of startup (latent) selene/src/offload.rs:534-545, runtime.rs:663-671
B2 Minor codec_placement gauge + intake warning now emitted before executor construction, for every offload configuration and on startups that then abort runtime.rs:672-679, metrics.rs:558-568
D1 Minor (claim) "Startup is now exact LIFO-symmetric with the existing shutdown path" is false for the RankExecutor::new failure branch runtime.rs:697-706
D2 Minor No ordering regression test guards the fix; a comment is the only thing holding it runtime.rs:657-662

The core reordering is sound — see "Areas verified sound" at the end. The defects are all in the cleanup code the PR adds around it.


A. Correctness, Safety & Platform Parity

A1 (Major) — Store close errors are swallowed and drained: true is reported anyway

helios/src/server/runtime.rs:697-706 (new lines):

                    Err(error) => {
                        if let Some(mut store) = store {
                            let _ = store.close();
                        }
                        let _ = ready_tx.send(Err(error.clone()));
                        return Shutdown {
                            drained: true,
                            error: Some(error),
                        };

selene/src/store.rs:334-337 states the contract this violates verbatim:

    /// Drain transfers, join threads, and finish pending disk writes.
    /// On failure the caller must retain the store: transfer jobs may still
    /// reference its registered host buffers and GPU destinations.
    fn close(&mut self) -> Result<()>;

The same file already implements that contract correctly in Worker::close_store, helios/src/server/runtime.rs:1354-1362:

    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());
        }
    }

Impact. Shutdown.drained is not a local detail: flare/src/controller.rs:2905-2909 does

        Err(failure) => {
            lease.drained = failure.drained;
            if !failure.drained {
                self.state(SessionState::RestartRequired, "GPU drain was not confirmed");
            }

so a hardcoded drained: true after a failed store close tells the controller the GPU drain was confirmed, and the lease (core + GPU) is released while the store's registered host slabs / GPU destinations may still be referenced by transfer jobs — precisely the condition the trait doc says must keep the store alive. The store binding is dropped at scope exit here (only Transfers::drop joins threads, helios/src/offload/transfer.rs:841-852), and the close error is discarded, so it never reaches shutdown.error and never reaches the user. This is the "don't just swallow an unexplained error" failure mode the charter's #397 line targets. Note the defect is created by this PR: the branch is a context line in the diff, but before the change that branch owned no store, so the swallow did not exist.

The same swallow appears twice more:

Concrete fix. Replace all three ad-hoc blocks with one helper that mirrors close_store exactly:

fn close_store_on_error(store: Option<HostStore>, shutdown: &mut Shutdown) {
    let Some(mut store) = store else { return };
    if !shutdown.drained { std::mem::forget(store); return; }
    shutdown.drained = false;
    match store.close() {
        Ok(()) => shutdown.drained = true,
        Err(error) => { shutdown.error.get_or_insert(error.into()); }
    }
}

and call it on all three paths (:697-706, :714-726, :784-796). That also replaces the two std::mem::forget sites with the ManuallyDrop mechanism the file already uses, giving one ownership convention instead of two.

A2 (Major) — drained: true is now asserted rather than derived on the open-failure path

helios/src/server/runtime.rs:684-690:

                    Err(error) => {
                        let _ = ready_tx.send(Err(error.clone()));
                        return Shutdown {
                            drained: true,
                            error: Some(error),
                        };
                    }

The diff's removed hunk shows the pre-change behaviour for this same failure:

-                    Err(error) => {
-                        let _ = ready_tx.send(Err(error.clone()));
-                        let mut shutdown = executor.close();
-                        shutdown.error = Some(error);
-                        return shutdown;
-                    }

Impact. drained used to be whatever executor.close() actually confirmed. It is now hardcoded true. For the no-executor-yet case that is defensible — nothing has been launched on the device, so there is nothing to drain — but only if flare_selene::offload::open joins every transfer thread it already spawned before returning Err (it blocks on each rank's ready.recv(), helios/src/offload/transfer.rs:642-652, so a mid-way failure means earlier ranks may be live). I could not verify that teardown path inside this review (see Open Questions), so this is reported as an unverified-but-load-bearing assumption introduced by the diff, not as a confirmed leak. It is a behaviour change to drain reporting that the PR description does not mention.

Concrete fix. Either state and code it explicitly (drained: true justified in a comment because no executor exists and open's error path joined its threads — with a citation), or make offload::open guarantee the join in a test.

A3 (Major, evidence) — the cited validation cannot compile the changed file

helios/src/lib.rs:30-31:

#[cfg(feature = "server")]
pub mod server;

helios/Cargo.toml:21 and :25:

runtime-core = ["dep:serde", "dep:serde_json", "dep:prost", "dep:prost-build", "dep:ring", "dep:zstd"]
server = ["dep:serde", "images", "grammar", "dep:axum", "dep:tokio", ...]

runtime-core does not enable server, so cargo test -p flare-helios --features runtime-core (the PR's "Submission validation": "1243 passed; 0 failed; 37 ignored") never compiles one line of this diff. Independently, the PR's "Suggested test command" is cargo test -p helios --features runtime-core, and helios/Cargo.toml:2 says name = "flare-helios" — that command fails on an unknown package. There is no test added or modified in the 1-file diff.

Impact. The only in-repo automated evidence attached to the PR is void for this change; the GPU before/after evidence is explicitly not re-run ("No fresh GPU startup reproduction was run for this submission"). Against the charter's "Bring real evidence" line and "Bug fixes need to address the root cause" this is a gap the PR must close before merge.

Concrete fix. Cite cargo test -p flare-helios --features server (or --all-features) output, and fix the suggested command to the real package name.


B. System-level consequences

B1 (Minor) — Binding::sharded() becomes false after the early take (latent trap)

selene/src/offload.rs:534-545:

    /// The prepared resources, once; later calls return `None`.
    pub fn take(&self) -> Option<Prepared> {
        self.shared.take()
    }

    /// The store's records are mirrored onto peer rank processes; see [`shard`].
    pub fn sharded(&self) -> bool {
        self.shared
            .lock()
            .as_ref()
            .is_some_and(|prepared| !prepared.shards.is_empty())
    }

runtime.rs:663-671 now takes the payload ~90 lines earlier, so every Binding::sharded() call after that point reports "not sharded" regardless of the truth. No live break today: the multi-rank guard that uses it runs before the take (runtime.rs:644-650, verified ahead of :663), and executor-side consumers read only copy_gate/rank/shares (helios/src/execution/ranks.rs:127 — manifest.offload.as_ref().and_then(|b| b.copy_gate()); helios/src/execution/threaded.rs:1286-1290). The wider window is a silent trap for the next person who asks the binding whether it is sharded during executor construction.

Fix. Snapshot the flag before taking (let sharded = binding.sharded();) only if anything downstream needs it, or document on take() that sharded() is invalid afterwards.

B2 (Minor) — metric and warning emission moved earlier and now fires on aborting startups, for every offload config

helios/src/server/runtime.rs:672-679:

                    .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}"); }
                        }

helios/src/server/metrics.rs:558-560 is a once-set cell:

    pub(super) fn codec_placement(&self, placement: crate::offload::KvCompression) {
        let _ = self.codec_state.set(placement);
    }

and metrics.rs:565-568 gates decode-stat publishing on it:

    pub fn store(&self, stats: StoreStats) {
        if self.codec_state.get().is_some_and(|placement| *placement != crate::offload::KvCompression::Off) {
            *self.decode.lock().unwrap() = stats.decode;

Impact. Because store is None only when there is no offload payload, this block runs for every offload configuration (cpu/gpu/disk tiers), not just the GKV1 case the PR targets. It now sets codec_state before executor/scheduler construction, so a startup that aborts at :697 or :714 leaves a metrics object advertising a codec placement for a runtime that never started, and the operator sees the intake warning for a session that then failed. This is an observability ordering change (metric span check: the gauge's span now begins before executor construction rather than after) that the description does not declare.

Fix. Keep the emission where it was (after successful construction), or explicitly note that the gauge intentionally advertises placement before the runtime is live.

Not a problem — verified


C. Architecture, Contracts & Charter Compliance


D. Tests & Claim Accuracy

D1 (Minor, claim) — "exact LIFO-symmetric" is false for one branch

PR text: "Startup is now exact LIFO-symmetric with the existing shutdown path (runtime.rs: executor.close() before worker.close_store())."

True for the happy path — worker.attach_store(store); at runtime.rs:806 after executor+scheduler construction, shutdown at runtime.rs:829-830 (let mut shutdown = executor.close(); then worker.close_store(&mut shutdown);). Approximately true for :714-726 / :784-796 (close error dropped). False for :697-706, which ignores the close result and forces drained: true where close_store clears drained and preserves the error (:1354-1362). Since A1's fix creates the symmetry the text claims, the claim becomes accurate once A1 lands.

D2 (Minor) — no ordering regression test

No test asserts that offload::open precedes persistent-worker launch; the invariant is protected only by the comment at runtime.rs:657-662. helios/src/server/runtime/ contains phase_tests.rs (not opened), prompt_tests.rs (not opened), response_lifecycle_tests.rs (not opened); prompt_tests.rs:33 (not opened) calls ModelRuntime::start(...) but nothing inspects open/executor ordering. Given the failure mode is an unbounded hang, a cheap ordering assertion (a test double that records the sequence, or a plan-shape assert on open-before-RankExecutor::new) is warranted, together with A3's corrected feature flag.

Claim-vs-code audit (verified at head)

Claim Verdict
"manifest.offload … RankExecutor::new only checks offload metadata (not the taken payload)" True — helios/src/execution/ranks.rs:127 reads only copy_gate(), a separate cloned field (helios/src/offload/mod.rs:58-60, :78-82).
"Startup is now exact LIFO-symmetric with the existing shutdown path" True (happy path) :806, :829-830; false :697-706; approximate :714-726, :784-796.
"Add LIFO cleanup on all early-error paths after store opens (store.close() directly if RankExecutor::new fails; executor.close() first, then store.close() only when shutdown.drained)" Control flow as described, but drained is hardcoded true and close errors dropped — the description omits both.
Cause #1: kv_codec_gpu cubin load deferred in helios/src/runtime_core/mod.rs (not opened) during Prepare kernels Not locatable in the tree — no kernels/codec/module references in that file and no prepare_kernels definition under helios/src (only call sites runtime_core/model.rs:821, runtime_core/event_tests.rs:115 (not opened), phase name startup.rs:59 (not opened)). The rest of the chain is real: transport.rs:793-808 control.start()? launches the persistent worker; transfer.rs:602-636/:642-652 spawn and block on ready.recv(); gpu_codec.rs:282 stream.load_module(cubin); cuda.rs:1151 (not opened) check("cuModuleLoadData", …). The fix stands on the verified half of the mechanism, but the description should cite the real deferral site or drop cause #1.
"1243 passed; 0 failed; 37 ignored" Cannot exercise the diff — A3.

Open questions / could not verify

  1. Whether flare_selene::offload::open joins every transfer thread it spawned when start_parts fails mid-way. This decides whether A2's unconditional drained: true (runtime.rs:684-690) is safe or frees the lease while peer transfer threads still hold registered buffers.
  2. No independent confirmation of the GB300 before/after numbers (>400 s hang → 0.6 s; 1.239–1.259× lossless; 3.6 s SIGTERM drain). Author's report only, no logs or command output attached, no fresh run for this submission.
  3. Whether any server-feature test in phase_tests.rs (not opened) covers startup ordering — none found, but that file was read only by search, not in full.
  4. Commit-level history for helios/src is unreadable (search_history fails with a git object error), so I could not confirm the diff is not behind on its own file beyond the orientation packet's statement.