PR #698: Open host prefix store before `RankExecutor::new()` to avoid `cuModuleLoadData` deadlock with persistent GPU workers

Raw Markdown for agents: https://autobot.eidonix.com/api/v1/cases/7b20174a-43dd-46c6-bea4-5cb388e97f0c

Opened by a workflow run, Dec 2, 2026 7:12 PM EST. decide malicious: all_clear (100%): No malicious content found

explore

Author: ebfio (first-time contributor; 0 merged PRs, 2 other open PRs #699, #682; Discord: ebfio) Motivation: Serving a persistent-worker core with GPU lossless KV compression (--lossless-kv-compression gpu, GKV1) hangs forever at startup, because the persistent GPU worker kernel is launched before the offload codec tries to load its CUDA module, and cuModuleLoadData waits for a quiescent context that never comes. The PR opens the offload store first so the module loads while the GPU is idle. Scale: +52 / −31 lines in 1 file (helios/src/server/runtime.rs) Proposal:

Full report · Notes

Classify intake

Selected: triage:review, bug

Threshold: 65%

Triage

Priority

Type

Area

Model

Apply Labels (Intake)

Applied: +triage:review, +bug

Value Proposition

Value Proposition — PR #698 ("Open host prefix store before RankExecutor::new()")

Novelty & status: genuinely additive. The hazard was created by merged PR #504 (2026-11-25, yatesdr), which added the very crate::offload::open(...) call inside ModelRuntime::start; #698 moves that call ~90 lines earlier and reverts none of #504's work. No commits on main since branching touch helios/src/server/runtime.rs, no open PR competes with it, and nothing supersedes or is superseded. It repairs a ~1-week-old regression with a single reporter (the author).

Charter alignment: strong. The dossier verifies the mechanism end-to-end (RankExecutor::new → finish_startup → control.start() persistent kernel; later offload::open → flare-offload-0 → GpuRankCodec::new → cuModuleLoadData on the same context). The fix corrects ordering/lifetime rather than retrying or swallowing the error, matching the #397 root-cause standard. Footprint is one file, +52/−31, no new flag, no per-model branch, no dependency or default change — consistent with "smallest footprint in shared code" and "keep the runtime small and model-agnostic." It repairs the host prefix-store/Selene path instead of widening scope.

Evidence: the weak point. The cited validation (cargo test -p flare-helios --features runtime-core, "1243 passed") does not enable the server feature that gates the changed file, so it compiles none of the diff; the suggested command names a non-existent package (helios); no test was added; there is no CI on the head commit; and the GB300 before/after numbers were explicitly not re-run for this submission, with no logs attached. One link of the stated cause chain (the prepare_kernels cubin deferral in runtime_core/mod.rs) is not locatable in the tree.

Maintenance risk. The new error paths are not symmetric as claimed: the RankExecutor::new failure branch discards store.close()'s error and returns drained: true, contradicting Worker::close_store and the in-file convention that startup errors retain owners conservatively; std::mem::forget(store) adds a second mechanism for an intent already handled by ManuallyDrop. The reordered block now runs for every offload configuration and emits metrics/warnings even when startup later aborts. The author's admitted SM103 Green Context / cooperative-decode contention remains open on a named charter target.

Verdict: Worth it with changes. The reorder is correct, small and worth review effort — but it should not land until it (1) is validated by a run that compiles the server feature (or adds a startup-ordering regression test), (2) aligns late-error-path drained/error semantics with close_store, and (3) justifies or removes the mem::forget leak. Author is a first-time contributor and not on the priority list; per #229 the review should state exactly these requirements rather than decline out of hand.

Full report Decide Value: yes (100%): This change is worth reviewing: it provides value to the project in line with its charter.

Subtraction and simplicity

PR #698's 12-line reorder is lean; the debt is in the cleanup code it piles on top.

  1. High — three hand-inlined copies of existing logic: runtime.rs:697-706, :714-726, :784-796 re-implement Worker::close_store (runtime.rs:1344-1364), which is already a free function over (Option<Box<dyn HostStore>>, &mut Shutdown) (field at :1164). Divergences from the helper: path (a) swallows the close error and drops the box anyway, against the contract at selene/src/store.rs:334-337; (b)/(c) introduce a second retention mechanism (std::mem::forget at :722, :792) where the helper uses ManuallyDrop, with no unwind guard — the case shutdown_retains_the_store_when_its_drain_panics asserts (phase_tests.rs:2340-2363). Fix: extract close_store(store, &mut shutdown) as a module fn, have Worker::close_store call it, replace all three blocks with one call each → ~30 lines, both forgets and the swallowed error gone, and the paths become testable with the existing FakeStore (phase_tests.rs:2262-2363). Minimal alternative: one-line mem::forget(store) per path, matching runtime_core/model.rs:1123-1128.
  2. Medium — runtime.rs:673-678 emits the codec_placement metric and intake_warning inline; crate::offload::open has one caller (offload/mod.rs:135-144, runtime.rs:679), so move both inside open and delete the block.
  3. Low — runtime.rs:663-691 threads copy_gate through a 3-tuple then .transpose()s; and_then + ? returns Option<Result<_>> in ~11 lines. Pre-existing shape moved verbatim, so optional.
  4. The reorder itself adds no flag, knob, wrapper or fallback; reading manifest.offload directly is a net deletion; the 6-line comment earns its lines. No structural AGENTS.md violation.
  5. Process: no test added, and the cited --features runtime-core run does not enable server (lib.rs:30-31, Cargo.toml:25 (not opened)), so none of the new branches were compiled; the suggested -p helios names a nonexistent package.

Open: no test guards this startup ordering; no CI on head; GPU numbers author-reported only; search_history unavailable due to git object errors.

Full report · Notes

Correctness and contracts

PR #698 moves crate::offload::open ahead of RankExecutor::new so GKV1's cuModuleLoadData no longer races a running persistent-worker kernel. The reorder itself is correct and safe; the new error-path cleanup it adds is not.

Findings:

Open: whether offload::open joins every transfer thread it spawned before returning Err; no startup-ordering regression test exists.

Full report · Notes

Final review

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

Walkthrough

Pre-merge Checks

Blockers

  1. Post-open error paths violate HostStore::close safety contract and duplicate Worker::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 drop store on scope exit while keeping drained: true (hardcoded at :703; preserved from executor.close() at :717 and :787). This directly violates selene/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"), causes flare/src/controller.rs:2905-2910 to treat drain as confirmed and release the GPU/core lease while host slabs may still be in use, and drops Transfers on a failed close (whose Drop unconditionally calls thread.join(), helios/src/offload/transfer.rs:841-852). Furthermore, none of the three sites wraps store in ManuallyDrop before calling store.close(), so an unwind inside store.close() drops store—the exact hazard Worker::close_store (runtime.rs:1344-1364) and shutdown_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 with Worker::close_store does not currently hold.
    • Concrete fix: Extract the body of Worker::close_store (runtime.rs:1344-1364, which only uses self to self.store.take()) into a shared helper fn close_store(store: Option<Box<dyn flare_selene::HostStore>>, shutdown: &mut Shutdown) and call it from Worker::close_store and all three startup failure paths:
      fn 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());
              }
          }
      }
      
      Then on RankExecutor::new failure (:697-706):
      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;
      }
      
      And on both scheduler failure paths (:714-726, :784-796):
      Err(error) => {
          let _ = ready_tx.send(Err(error.clone()));
          let mut shutdown = executor.close();
          close_store(store, &mut shutdown);
          shutdown.error = Some(error);
          return shutdown;
      }
      
      This fixes drain reporting, error preservation, unwind retention, and deletes ~25 lines plus both ad-hoc std::mem::forget(store) calls in one change.
  2. 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.rs is gated behind #[cfg(feature = "server")] (helios/src/lib.rs:30-31), and runtime-core does not enable server (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:2 is flare-helios). Per docs/design-review.md:180-184,247-251 and .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 -l per AGENTS.md:317-327):
      cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server
      
      and correct the suggested test command in the PR description.

Should Fix

None.

Subtract / Simplify

Nits

Dropped on verification

Full report

Classify triage

Selected: triage:review

Threshold: 65%

Triage

Apply labels

No label changes Decision to Test: no (100%): Testing will not add significant value as the code stands today. The code is either not yet ready to merge, or adequate testing has already been done to validate the contents of the code, or the available hardware is not suitable to test with. decide malicious: all_clear (100%): No malicious content found

explore

Author: ebfio (first-time contributor; 0 merged PRs, 2 other open PRs #699 and #682; Discord: ebfio) Motivation: Serving a core that uses a persistent GPU worker with --lossless-kv-compression gpu hangs forever at startup, because the GPU codec's cuModuleLoadData call is made while a persistent worker kernel is already running on the same CUDA context. The PR moves the host prefix store open ahead of executor construction so the cubin loads on an idle GPU. Scale: +65 / −53 in 1 file Proposal:

Full report · Notes

Classify intake

Selected: triage:superseded, bug, performance, duplicate

Threshold: 65%

Triage

Priority

Type

Area

Model

Apply Labels (Intake)

Applied: +triage:superseded, +performance, +duplicate, -triage:review

Gates and contracts

Contracts, Charter & Verification Gates Audit — PR #698 @ 501bb0e

Scope of this lens: the 4 hard gates only (signed contract/core-format boundaries, vendored upstream deps / cross-PR conflicts, mandatory verification evidence, material scope/claim contradictions). Algorithm and lifecycle-correctness findings belong to the Code Correctness lens and are not repeated here.

Verdict

1 hard gate violated: Gate 3 (mandatory Layer‑1 verification for the affected crate). Everything else passes, with one material non-gate fact (the PR is fully superseded by merged #709) and one claim contradiction inside the same evidence line.


Gate 1 — Signed contract, core-format, wire, captured-graph, normative docs: PASS

The diff (pr_diff, result 1) is 1 file, helios/src/server/runtime.rs (+65/−53). It adds no Protobuf field, no core-format enum or version, no wire kind, no captured-graph operation family, no new CLI flag or knob:

Gate 2 — Vendored upstream dependencies & cross-PR conflicts: PASS

Gate 3 — Mandatory verification evidence: FAIL (1 blocker)

Blocker 3.1 — The reported validation does not compile a single line of the diff

docs/design-review.md:180-184 makes Layer 1 mandatory for every affected Rust crate and names the exact form: "Run cargo test --locked --release on every affected Rust crate (… helios with --features runtime-core,server …)", and docs/design-review.md:247-251 removes the escape hatch: "Disclosure does not excuse skipping runnable CPU checks. … Leaving an applicable crate test … unrun blocks commit and PR acceptance; noting it as a limitation does not make the omission acceptable."

The PR's reported validation cannot satisfy this:

  1. helios/src/server/runtime.rs is gated #[cfg(feature = "server")] pub mod server; (helios/src/lib.rs:30-31).
  2. runtime-core does not imply server: helios/Cargo.toml:21 (runtime-core = ["dep:serde", … "dep:zstd"]) vs helios/Cargo.toml:25 (server = [ "dep:serde", "images", "grammar", … "dep:deepseek-recipe"]). They are disjoint feature lists.
  3. Therefore the stated Submission Validation — cargo test -p flare-helios --features runtime-core ("1243 passed; 0 failed; 37 ignored") — never compiles helios/src/server/runtime.rs, i.e. none of the +65/−53 is type-checked, let alone tested.
  4. The stated "Suggested test command" — cargo test -p helios --features runtime-core — additionally names a package that does not exist: helios/Cargo.toml:2 is name = "flare-helios", so that command fails outright.

This is not a "no CI observable" artifact of my tooling; it is an affirmative, checkable defect in the PR's own evidence claim. The authoritative command that would cover the diff is the one CI itself uses (native-serving.yml:63 and :68: cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server, with FLARE_TEST_TEMPLATE_DIR and ulimit -l/prlimit per .github/workflows/native-serving.yml:58-63 (not opened)).

No earlier-round evidence rescues this (per the Round‑2+ calibration): I checked ## Case File History and pr_comments (result 2, two flare-autobot comments). The only recorded run is the --features runtime-core one above; no --release run with server, no check.py output, and no A/B benchmark appears in any round. The Discovery Dossier states it explicitly: "No fresh GPU startup reproduction was run for this submission."

Concrete fix: run and report

cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server

(passing FLARE_TEST_TEMPLATE_DIR and raising memlock as in native-serving.yml:58-63), then correct both commands in the PR body.

Why this is a real gate for this change (not pedantry)

Layer 3 (TLA+ / Kani) — correctly not triggered; recorded so the omission is not mistaken for a skip

docs/design-review.md:212-215 requires python3 verification/helios-lifecycle/check.py when changing "admission, fences, generations, cancellation, speculation accounting, cache compaction, snapshot aliases, response buffering or ownership, offload aggregation, readiness, or rank coordination." The PR changes none of these:

Note that verification/helios-lifecycle/check.py:318 itself builds with --features server, so that run would have recompiled the diff. It is not required by the trigger list, so I do not raise it as a blocker — but it is the cheapest available substitute if maintainers prefer it over the full crate run.

Failing tests / failing CI: not reported — not flagged

The description reports 1243 passed; 0 failed; 37 ignored, and the Dossier reports no failing check. Per the calibration rules I am not flagging "no CI run observable."

Gate 4 — Material scope & claim contradictions: one material finding

Finding 4.1 (material) — Two claims in the PR description are contradicted by its own diff

  1. Evidence claim. "Suggested test command: cargo test -p helios --features runtime-core" and "cargo test -p flare-helios --features runtime-core … 1243 passed" present a green suite as validation of this change, but as shown in Blocker 3.1 that suite excludes the modified module and the suggested package does not exist. Under docs/design-review.md:150-160 the evidence part of the description must connect to the claim; here the stated evidence is provably disconnected from the diff.
  2. "What changed" claim is stale versus the head. The Changes section describes "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…)". Those ad-hoc blocks and the std::mem::forget(store) retention mechanism no longer exist at 501bb0e: the diff replaces them with the single close_store helper and routes all three sites through it (helios/src/server/runtime.rs:703, :716, :780), and Worker::close_store delegates (:1353-1355). Principle 16 requires the description's "what exactly changed" to be accurate, and a reader "must not need the diff … to reconstruct the argument."

This is a description-accuracy defect with a real governance basis (principles 12 and 16), not a phrasing nuance: it misdescribes the code under review and mis-attributes the evidence. Fix: rewrite the Changes and Verification sections against 501bb0e, state that the diff is superseded by #709, and link #701 as the follow-on.

Not flagged (deliberate)

Required actions to clear this lens

  1. Gate 3 (blocking): run and report cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server (with FLARE_TEST_TEMPLATE_DIR and the memlock setting from .github/workflows/native-serving.yml:58-63 (not opened)); correct the Suggested command to drop the nonexistent -p helios package. Alternatively, re-run the GPU ordering observation against 501bb0e and the CPU server-feature suite, since docs/verification.md:14 classifies this property as CUDA ordering.
  2. Gate 4 (should fix): rewrite the Changes and Verification sections against head 501bb0e — drop the removed ad-hoc cleanup / store.close()-directly / mem::forget description, describe the single close_store helper and its three call sites, and attribute evidence honestly.
  3. Disposition (governance, not a gate): since merged #709 already contains this diff on main (helios/src/server/runtime.rs:760-794, :1282-1302), the soundest close is "superseded by #709," explicitly crediting ebfio's cuModuleLoadData diagnosis and linking the P1 follow-on #701. Landing #698 after a rebase would add no code beyond comment wording.

No vendored-file or signed contract/core-format gate violations. One mandatory verification gate violation (Blocker 3.1) and one material claim contradiction (Finding 4.1).

Full report

Subtraction and simplicity

Subtraction & Simplicity Lens — PR #698 (helios/src/server/runtime.rs, +65/−53, head 501bb0e9)

The diff is small and mostly in the right direction: it replaces three hand-copied cleanup blocks with one helper and deletes the old in-line store-open block. It is not free of redundancy, and the single largest subtraction available is the PR itself (already merged to main via #709). Concrete items below, highest value first.

1. The largest subtraction: the whole diff is already on main via merged #709

Verified on main:

So #698 is 100% duplicated; the only deltas are comment wording and the get_or_insert nit in item 3. There is nothing here to "simplify into a merge" — subtract the PR (close as superseded), and if attribution matters, the reorder comment is the only artifact worth landing.

2. The new store-open block threads a tuple it immediately destructures (pr :663-691)

.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)| {

binding.copy_gate() is hoisted out of take() only because take() (helios/src/offload/mod.rs:78-82) returns Option<(Prepared, Vec<Arc<Vec<u8>>>)> while copy_gate lives alongside it in the same Binding struct (offload/mod.rs:40-42: inner, gpu_cubins, copy_gate). The tuple-of-three exists purely to carry one field through a closure. Subtraction: have Binding hand back what open needs — e.g. pub fn take_open(&self) -> Option<(Prepared, Vec<Arc<Vec<u8>>>, Option<Arc<CopyEngineGate>>)>, or a crate::offload::open_binding(binding: &Binding) that owns the .and_then/.map/.transpose chain. That removes the three-element tuple, the let copy_gate = … line, and keeps the invariant "one binding yields exactly one open" in the module that owns Binding, instead of repeating the copy_gate()+take() pairing in a third call site (ranks.rs:127 and parallel.rs:569 already fetch copy_gate separately).

3. close_store's error channel is dead at every new startup call site

close_store records a close failure only through shutdown.error.get_or_insert(error.into()) (pr :1154). At the three new call sites:

So 1 of 3 call sites can report a store-close failure and 2 silently discard it. main writes shutdown.error.get_or_insert(error.clone()); at :819 and twice as get_or_insert at :883. Simplification: pick one — either get_or_insert everywhere (two-line fix, matches main), or give close_store no error parameter at all and have the startup paths rely on the primary error, so the "which error wins" question stops existing.

4. Five early-return Shutdown literals in 140 lines can collapse to one helper

Shutdown { drained: true, error: Some(error) } appears at :651-655, :686-689, :697-701 (with clone), and via executor.close() at :715, :779. A single

fn failed_start(store: Option<Box<dyn flare_selene::HostStore>>, error: Error) -> Shutdown

(≈8 lines: build {drained: true, error: Some(error)}, close_store(store, &mut shutdown), return) replaces :684-690, :697-705, :771-783's tail and :713-719 — roughly 29 diff lines down to ~10, and makes the "open → executor → scheduler" ladder read as three match … else return failed_start(store, error) rungs with identical LIFO semantics. This is the same ownership reduction the helper already achieved for store, applied one level up to the shutdown value.

5. Keeping Worker::close_store as a one-line delegate is correct — do not subtract it

fn close_store(&mut self, shutdown: &mut Shutdown) {
    close_store(self.store.take(), shutdown);
}

(pr :1353-1355) looks like a removable indirection, but tests call it through Worker at helios/src/server/runtime/phase_tests.rs:1759 (not opened), :2275, :2281, :2305, :2331, :2355, and it keeps self.store.take() (the "only once" invariant) on the Worker side. Keep as-is.

6. Structural note (not this PR's to fix): close_store is a second implementation of the retain-unless-drained rule

helios/src/server/session.rs:110-133 already encodes exactly this rule as DrainGuard<T> (Drop → std::mem::forget(value) while !drained). close_store (pr :1137-1157) is a hand-rolled ManuallyDrop variant of the same idea with a close hook (shutdown.drained = false; store.close()). Not a #698 regression — but if a future PR wants one abstraction, DrainGuard growing a close_with(&mut self, f) is where the second copy should go. Do not do this in #698.

7. Evidence/scope subtraction (process, but it costs review time)

Verdict

Not lean enough to merge as-is, but the only substantive simplify items are #2 (drop the (prepared, gpu_cubins, copy_gate) tuple by giving Binding an open-shaped accessor), #3 (get_or_insert at :717/:781), and #4 (one failed_start helper). All three are ~15 lines of net deletion. Given #1, my recommendation is: close #698 as superseded by merged #709, crediting ebfio's cuModuleLoadData diagnosis (which main already credits by PR number at helios/src/runtime_core/persistent_worker.rs:2939), and land only the get_or_insert wording if anyone wants the error-preservation detail.

Full report · Notes

Code correctness

Deep Code Correctness Audit — PR #698 (helios/src/server/runtime.rs, +65/−53)

Verdict: no Blocker and no Major defect found. The reordering is semantically safe with respect to every callee I resolved, close_store is a faithful behaviour-preserving extraction, and the startup path is now LIFO-symmetric with the shutdown path as claimed. One Minor correctness divergence is reported below (new store teardown under a false drained: true claim), plus two informational notes. No hot-path code changed.

Because the PR is single-file / single-subsystem (1 file, 118 changed lines, helios/ only), it was audited directly rather than partitioned into sub-agents.


Diff sites audited

helios/src/server/runtime.rs at 501bb0e:


1. Callee / design-invariant resolution — the reordering is safe

(a) manifest.offload still carries everything RankExecutor::new reads. The moved block calls binding.take() (line 669), which drains Shared::prepared:

// helios/src/offload/mod.rs:78-83
pub fn take(&self) -> Option<(Prepared, Vec<std::sync::Arc<Vec<u8>>>)> {
    self.inner
        .take()
        .map(|prepared| (prepared, self.gpu_cubins.clone()))
}

RankExecutor::new reads only the gate, not the payload:

// helios/src/execution/ranks.rs:123-143
pub(crate) unsafe fn new(manifest: ExecutionManifest, peers: Option<RankPeers>) -> Result<Self> {
    let copy_gate = manifest.offload.as_ref().and_then(|b| b.copy_gate());
    ...
    Ok(Self { inner, leases: PeerGraphLeases::new(copy_gate, peer_copy_graphs) })
}

and copy_gate is a plain Arc field on the helios wrapper, unaffected by take() (helios/src/offload/mod.rs:42, 58-60). All three executor constructors (transport.rs:604-611, threaded.rs:625-644, parallel.rs:114-145) read only persistent_workers, graphs, peer_copy_graphs, completion_token_capacity, input_frame_bytes, buffers, tuning_graphs — never offload's taken payload. Contention check on the other manifest.offload readers: threaded.rs:1286-1290 (same_layout → a.shares(b)) and runtime.rs:645 (!binding.sharded()) both resolve against Shared, and selene/src/offload.rs:530-532 / 540-545 compare Arc::ptr_eq and prepared.shards; sharded() is evaluated at line 645, before the take() at 669, so the "requires every rank in one process" guard is not made dead code by the reordering. runtime.rs:609 binding.inputs() clones shared.inputs, also independent of prepared.

(b) offload::open has no dependency on RankExecutor having run. helios/src/offload/mod.rs:135-144 → selene/src/offload.rs:802-891 → Copiers::start (transfer.rs:2190-2210) → Transfers::start_parts → RankWorker::open (transfer.rs:395-421), which does its own Stream::open_lowest_priority(context, device); Stream::bind (cuda.rs:740-756) issues cuCtxSetCurrent itself, so it does not rely on the model thread's current context. The GKV1 module load happens inside RankCodec::new (transfer/codec.rs:102-132) → GpuRankCodec::new → stream.load_module(cubin) (transfer/gpu_codec.rs:282, cuda.rs:1152).

(c) The deadlock premise is confirmed in-tree. The codec module is deliberately skipped during kernel preparation (runtime_core/mod.rs:755-761, skip_module), documented normatively at docs/prefix-cache-offload.md:112-119 ("Helios skips loading that module when compression is off or cpu, and loads it lazily via cuModuleLoadData"), while the persistent worker is launched inside executor construction at transport.rs:793-805 (finish_startup → control.start()?) after tuning graphs have already run (transport.rs:604-611). So before this PR the module load really could be issued while the worker kernel was resident. The new order closes that window for all three peer modes (persistent workers are rejected for RankPeers::Threads/Processes, threaded.rs:632-638, parallel.rs:122-126, so the single-rank GraphExecutor path is the one that matters). The fix is effective.

(d) Reverse deadlock check (does opening first break the executor?) No. Post-open there is no further cuModuleLoadData on any path reachable after a worker launch: all CopierFactory::mapped/unmapped calls (transfer.rs:2213-2232) are reachable only from offload::open, and the multi-host peer path shard::join_peer (selene/src/offload/sharded.rs:477) runs before Server::start from the CLI (flare-cli/src/cluster.rs:254), i.e. before any worker launch. The store's transfer threads are idle at that point (no jobs queued), so control.start() at transport.rs:804 cannot be blocked by them.

(e) close_store extraction is exact. Original Worker::close_store and the new free function are character-identical apart from the Option source:

// helios/src/server/runtime.rs:1137-1157
fn close_store(store: Option<Box<dyn flare_selene::HostStore>>, shutdown: &mut Shutdown) {
    let Some(store) = store else { return; };
    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()); }
    }
}

self.store.take() is evaluated before the call at 1354, identically to the old let Some(store) = self.store.take() else { return; }, so the "store removed even when not closed" invariant (exercised by phase_tests.rs:2311, 2334, 2359) is preserved. Worker::close_store still exists with the same signature, so phase_tests.rs:1759/2275/2281/2305/2331/2355 still compile and pass unchanged. The early-return-on-!drained leak of ManuallyDrop matches the normative rule at docs/prefix-cache-offload.md:879-883 ("If either drain fails, the store and its resource owners remain alive together with the model resources"). Hot-path cost: zero — close_store is reached only at startup-failure and shutdown, never in the request loop.


2. Order-of-operations / state-transition tracing

The new startup sequence is now store.open → RankExecutor::new → scheduler → attach_store and shutdown is executor.close() → close_store — exact LIFO as the comment at 657-662 claims. Per-branch drain-flag trace:

path line drained before close_store behaviour result
store open fails 683–690 true (inlined) not called; store is None-transposed Err, nothing to leak drained: true, correct — open returns before any store object exists, and its partially started Transfers are joined by Drop for Transfers (transfer.rs:841-851)
RankExecutor::new fails 698–705 true asserted store close() + drop see Minor finding 1
scheduler construction fails 713–719 from executor.close() closes only if executor drained matches doc invariant
scheduler configuration fails 777–783 from executor.close() as above matches doc invariant

ready_tx.send(...) now precedes close_store on the RankExecutor::new path; the caller's thread.join() at runtime.rs:851 still synchronizes on the store close, so the reported StartFailure.drained cannot be observed before teardown finishes, and a panic inside close_store still surfaces as drained: false through unwrap_or_else at 851-854. No stale-flag read: shutdown.drained is written at 1147 and re-set at 1150 within the same call, and no later statement in any caller reads it before returning.


3. Adversarial boundary checks


4. Hot-path complexity / allocations

No changed line lies on a per-step, per-request, or eviction path. The moved block is one-shot startup: a Vec<Arc<Vec<u8>>> clone of gpu_cubins (offload/mod.rs:81), an Arc clone for the gate, and one Box<dyn HostStore> move — no new per-iteration allocation, no new O(N) scan. close_store adds one indirect call plus a ManuallyDrop wrapper at shutdown only.


Findings

Minor 1 — RankExecutor::new failure now tears down the store under an unverified drained: true

Sites: helios/src/server/runtime.rs:697-705 (diff) vs helios/src/execution/transport.rs:1383-1387 and helios/src/execution/ranks.rs:129-140 (callee).

// helios/src/server/runtime.rs:695-706 (diff)
let mut executor = match unsafe { RankExecutor::new(manifest, peers) } {
    Ok(executor) => executor,
    Err(error) => {
        let mut shutdown = Shutdown { drained: true, error: Some(error.clone()) };
        let _ = ready_tx.send(Err(error));
        close_store(store, &mut shutdown);   // <-- closes + DROPS the store
        return shutdown;
    }
};

RankExecutor::new can return Err after GPU resources exist and were retained, because a constructed GraphExecutor on the error path is dropped and Drop→close() deliberately leaks on a failed drain:

// helios/src/execution/transport.rs:1383-1387
if drained { drop(resources); } else { std::mem::forget(resources); }

Reachable Err-with-retained-resources paths inside ranks.rs:129-140: GraphExecutor::new's tuning loop and finish_startup() → control.start()? (transport.rs:604-611, 793-805).

Counterexample: a core with a persistent worker whose green-context control.start() fails after partially launching the kernel, or whose tuning graph fails such that cuStreamSynchronize times out. RankExecutor::new returns Err with the resources mem::forget-ed; the new code reports drained: true, calls store.close() and then drop(store) at 1151, releasing the store's registered host slabs and pool device parts on the very contexts whose drain just failed. Pre-PR this was harmless because no store existed yet on that path; post-PR it is a new teardown under a false drain claim. The claim also propagates outward as StartFailure.drained (runtime.rs:864 → server.rs:443 → session.rs:76 → DrainGuard), which is exactly the signal telling the caller it may release the prepared core's CUDA contexts.

Concrete fix: do not assert drain on a constructor that cannot report it. Either (a) keep the store un-closed on this path (Shutdown { drained: false, error }, so close_store hits the !shutdown.drained early return and leaks via ManuallyDrop, matching docs/prefix-cache-offload.md:879-883), or (b) add a RankExecutor::try_new that returns Result<Self> plus the drop-time Shutdown so the true status can be threaded through. Option (a) is a two-line change and is strictly conservative.

Minor 2 — no test covers the new early-error store teardown

The three newly added close_store(store, &mut shutdown) call sites (703, 716, 780) have no counterpart in phase_tests.rs; only the Worker::close_store paths are covered (phase_tests.rs:2263-2363, four tests). The riskiest new branch — RankExecutor::new failure (Minor 1) — is therefore unverified. Suggested test: a FakeStore (already present at phase_tests.rs:2122) attached through a start_retaining_drain failure injected after store opens, asserting close_calls == 0 and drops == 0 when the executor did not drain.

Informational — normative doc now contradicts the code

docs/prefix-cache-offload.md:840-842 states "ModelRuntime::start constructs the configured store on the model thread after the executor exists". That is the invariant this PR intentionally inverts (the doc's shutdown clause at 879-883 is still accurate). Flagged as an invariant-tracking note for the documentation lens, not counted as a code defect.


What I confirmed is not broken (checked, no finding)

Full report Merge Risk: medium_high (100%): Medium or high merge risk (core runtime/scheduler/GPU/CUDA/VMM/RoCE/multi-rank/contracts/ABI, large multi-crate changes, or Blocker/Major findings) — route to Super Agent.

Re-review

Recommendation: Close

Commit 501bb0e cleanly resolved Round 1's ownership/drain blocker by extracting the shared close_store helper and routing all three early-error paths and Worker::close_store through it (with zero verified code bugs remaining). However, PR #698 is now 100% superseded by already-merged PR #709 (e899a4f, which explicitly states it addresses #698 and #701), and #709 already landed this exact helios/src/server/runtime.rs reorder and close_store helper on main together with close_store unit tests, updated docs, and explicit #698 credit in code (helios/src/runtime_core/persistent_worker.rs:2939). Recommend closing PR #698 as superseded by #709 with explicit credit to @ebfio for the GB300 cuModuleLoadData deadlock diagnosis, rather than asking for a rebase and server-feature test re-run that would produce zero functional diff.

Merge Risk

Level: Low

Walkthrough

Pre-merge Checks

Blockers

  1. PR is fully superseded by merged PR #709 (helios/src/server/runtime.rs:657-783, 1137-1157, 1353-1355 vs main helios/src/server/runtime.rs:760-886, 1282-1302, 1465-1467)

    • Verified behavior & impact: Merged PR #709 ("Unblock lossless KV compression across Ignition, selene-manager, and Helios Green Contexts") explicitly addresses #698 and already landed every element of this single-file diff on main: the pre-RankExecutor::new crate::offload::open reorder (main :760-794), the byte-identical close_store helper (main :1282-1302), all three early-error call sites (main :805, :818, :882), and Worker::close_store delegation (main :1465-1467). #709 also landed the four-case close_store unit test (main helios/src/server/runtime/phase_tests.rs:2399-2459), updated docs (main docs/prefix-cache-offload.md:59-63, docs/runtime-core-design.md:684 (not opened)), and credited #698 in code (main helios/src/runtime_core/persistent_worker.rs:2939). Rebasing #698 onto main leaves zero functional diff.
    • Concrete fix: Close PR #698 as superseded by #709, explicitly thanking and crediting @ebfio for diagnosing the GB300 cuModuleLoadData startup deadlock (and noting that their follow-on P1 report #701 was addressed by #709's 3-way codec Green Context and extended in #723).
  2. Prior Blocker #2 (Gate 3) remains unresolved — 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.rs is gated on #[cfg(feature = "server")] (helios/src/lib.rs:30-31), which is disjoint from runtime-core (helios/Cargo.toml:21,25). The reported validation (cargo test -p flare-helios --features runtime-core) never compiled or tested any line of 501bb0e, and the suggested command (cargo test -p helios --features runtime-core) names a nonexistent package (helios/Cargo.toml:2 is flare-helios). Per docs/design-review.md:180-184, 247-251, leaving the applicable Layer-1 crate test unrun blocks merge.
    • Concrete fix: Moot if closing as superseded by #709 (which already validated the landed code under --features runtime-core,server). Only if this branch were ever rebased and pursued for any remaining change would it require running cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server.

Should Fix

None.

Subtract / Simplify

  1. Close PR #698 as superseded by merged #709 (helios/src/server/runtime.rs): The cleanest subtraction is closing the PR rather than carrying a redundant rebase; every functional line is already on main (main helios/src/server/runtime.rs:760-886, 1282-1302, 1465-1467).

Nits

Dropped on verification

Full report

Classify triage

Selected: triage:superseded

Threshold: 65%

Triage

Apply labels

No label changes