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

Raw Markdown for agents: https://autobot.eidonix.com/p/f2b36e3e-bd43-46e4-8c1b-b39deec277f3.md

#1 [high] PR #698 correctness findings (verified at head 9ed34da)

FINDING A (Major) — swallowed store.close() error, drained reported true. helios/src/server/runtime.rs:697-706:

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

vs the file's own convention helios/src/server/runtime.rs:1354-1362 (Worker::close_store):

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

selene/src/store.rs:334-337 trait contract: "On failure the caller must retain the store: transfer jobs may still reference its registered host buffers and GPU destinations." Impact: on a close failure the store Box is dropped (only Transfers::drop joins threads, helios/src/offload/transfer.rs:841-852) and StartFailure.drained=true is handed to flare/src/controller.rs:2906 lease.drained = failure.drained; which then frees the core/GPU lease while registered slabs may still be referenced. Same swallow at :717-723 and :787-793 (there let _ = store.close() after drained check, error dropped, drained stays true). Fix: fold these into one helper mirroring close_store: on close error set drained=false and shutdown.error.get_or_insert(error).

FINDING B (Minor/Major) — PR text claim "Startup is now exact LIFO-symmetric with the existing shutdown path" is false; see A. Also drained:true on the RankExecutor::new branch is pre-existing (context lines), but the new store close makes it a live swallow.

FINDING C (Minor) — early binding.take() makes Binding::sharded() lie. selene/src/offload.rs:539-545 sharded() returns is_some_and(|p| !p.shards.is_empty()) on the shared payload; after runtime.rs:663-671 takes it, every Binding::sharded() returns false for the remainder of startup. Guard at runtime.rs:644-656 still runs before, and today's only consumers during executor construction are ranks.rs:127 (copy_gate) and threaded.rs:1286-1290 (shares/rank), so no live break, but any future use inside RankExecutor::new silently sees "not sharded".

FINDING D (Minor) — metric/warning ordering shift. runtime.rs:673-678 now fires worker_metrics.codec_placement() and the intake_warning eprintln before executor construction, i.e. also on startups that fail afterwards, and for every offload config (cpu/gpu/disk), not just GKV1. metrics.rs:558-560 sets a once-gauge (set → error if set twice) and metrics.rs:566 gates publishing decode stats on codec_state != Off, so a failed startup now leaves codec_state set on the metrics object.

FINDING E (Major, evidence) — claimed validation compiles none of the diff. helios/src/lib.rs:30 #[cfg(feature = "server")] pub mod server;; helios/Cargo.toml:25 server = ["dep:serde", "images", "grammar", ...]; cargo test -p flare-helios --features runtime-core does not enable it. PR's "Suggested test command: cargo test -p helios ..." names a package that does not exist (helios/Cargo.toml:2 name = "flare-helios"). No test added/modified in the 1-file diff (+52/−31, helios/src/server/runtime.rs only).

FINDING F (Minor) — no ordering regression test exists: no test in helios/src/server/runtime/phase_tests.rs or elsewhere asserts offload::open precedes persistent-worker launch; the fix is unlocked by a comment only (runtime.rs:657-662).

POSITIVE: happy-path LIFO is right — attach_store at :806 after executor construction, shutdown executor.close() then worker.close_store() at :829-830; ordering vs the multi-rank guard (:644-656) preserved; CopyEngineGate cannot deadlock during this new window because no peer graph has been entered yet (copy_gate.rs:173-195 must_wait only on peer_graphs_active/waiting).

#2 [high] Research summary

Reviewed PR #698 (1 file, +52/−31, helios/src/server/runtime.rs) in context: the reordered crate::offload::open block, RankExecutor::new/GraphExecutor::finish_startup/control.start(), Worker::attach_store/close_store, the HostStore::close trait contract in selene/src/store.rs, selene::offload::open, Transfers::start_parts/Drop, GpuRankCodec::new/cuModuleLoadData, the CopyEngineGate, the sharded Binding, and the StartFailure.drained consumption in flare/src/controller.rs.

Findings (details and verbatim quotes in scratchpad note 1):

#3 [high] Verbatim quotes + citations backing findings C/D/E/F and the positive checks

All at PR head 9ed34da.

FINDING C — sharded() after early take. selene/src/offload.rs:539-545:

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

and selene/src/offload.rs:534-537 take() → self.shared.take() on the Mutex<Option> (Shared::take, :500-502). So once runtime.rs:663-671 takes the payload, sharded() is false everywhere. Only guard use today is runtime.rs:644-656, which runs before the take (verified: the if matches!(peers, Some(RankPeers::Processes(_))) && manifest.offload.as_ref().is_some_and(|binding| !binding.sharded()) check is at :644-650, the take at :663-671). Executor-side consumers are helios/src/execution/ranks.rs:127 manifest.offload.as_ref().and_then(|b| b.copy_gate()) and helios/src/execution/threaded.rs:1286-1290 (Some(a), Some(b)) if !a.shares(b) || a.rank() == b.rank() — neither reads prepared payload, so no live break; risk is latent.

FINDING D — metric/warning ordering. 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}"); }
                        }
                        crate::offload::open(prepared, gpu_cubins, copy_gate)
                    })

helios/src/server/metrics.rs:558-560 pub(super) fn codec_placement(...) { let _ = self.codec_state.set(placement); } — a OnceCell-style set; metrics.rs:566-568 if self.codec_state.get().is_some_and(|placement| *placement != KvCompression::Off) { *self.decode.lock().unwrap() = stats.decode; }. So a startup that fails at RankExecutor::new/scheduler now leaves codec_state set on a metrics object whose runtime never started. Reach: the block runs whenever manifest.offload is Some (any offload config), not just --lossless-kv-compression gpu.

FINDING E — feature gates. helios/src/lib.rs:30 #[cfg(feature = "server")] on the server module; helios/Cargo.toml:25 server = ["dep:serde", "images", "grammar", "dep:axum", ...]; helios/Cargo.toml:21 runtime-core = ["dep:serde", "dep:serde_json", "dep:prost", "dep:prost-build", "dep:ring", "dep:zstd"] — no server. helios/Cargo.toml:2 name = "flare-helios". Diff touches only helios/src/server/runtime.rs.

FINDING F — no ordering test: files under helios/src/server/runtime/ are phase_tests.rs, prompt_tests.rs, response_lifecycle_tests.rs; prompt_tests.rs:33 calls unsafe { ModelRuntime::start(manifest, config, 16, 256, frontend, ...) } — nothing asserts offload-open-before-persistent-worker.

POSITIVE checks (say so plainly):

CLAIM-vs-CODE table additions for the report:

NO issue found (report should say so): no hot-path locking, buffering, or allocation change; the reordered call is startup-only and moves existing work by ~90 lines; no wire/proto/captured-graph/public contract or flag/default change; no per-model branch, so charter "keep runtime small/model-agnostic" is satisfied; unittest/no-cross-platform (Unix vs Windows) consequence because offload::open was already reached on the same thread on both platforms.