Recommendation: Changes Requested
PR #726 tackles a real startup bottleneck in the right shared runtime layer (helios/src/runtime_core), and its core mechanics—4 KiB-aligned zero-copy MappedHost reads with staged edges, 512 MiB registration chunking, RegistrationGate ordering, and reverse-order VMA/registration teardown—hold up well under boundary review. However, the PR is not ready to merge as-is: the headline 75.0 s → 45.5 s speedup was measured pre-rebase on the combined feat/gb300-tiered-runtime stack (#710) rather than on head 60d1b6b against main (violating Charter #210 / Principle 12 / AGENTS.md:99-100), and independent verification confirmed four real issues that should be fixed before merge: error-path RegistrationGate::close() bypass in register_pending_mapped_host, silent partial-load Ok(()) / unwoken sibling waiters in load_mapped_host_chunks, unconditional MADV_HUGEPAGE + 8-thread eager pre-faulting reintroducing the #616/#625 THP compaction-stall hazard, and un-updated normative loader/CLI docs paired with a multi-rank staging-cap overshoot in choose_io_plan.
Merge Risk
Level: High
- Shared startup critical path: Rewrites host allocation, weight loading, registration ordering, and background setup orchestration for all cores across
helios/src/runtime_core/{payload,mod,model}.rs(+1,886/−385across 8 files), with only 5 new CPU-only unit tests and no automated GPU or multi-rank startup coverage. - Self-disclosed unrun hardware paths:
host_vmm(Windows and non-identity-mapped Linux GPUs), integrated-GPUmlock,async_transfers, and multi-rank TP startup overlap were not executed on hardware; additionally, the unconditionalMADV_HUGEPAGE+ parallel pre-fault path has not been validated on fragmented SM120/SM121 Linux memory (defrag=madvise). - Stale diff base & active concurrent PRs: The PR diff base predates merged #709/#711/#721 (creating inherited diff noise), duplicates the host-VMA half of open draft #710 by the same author, and overlaps
model.rs/startup.rs/mod.rswith open #696 and #723.
Walkthrough
helios/src/runtime_core/payload.rs(+689/−80): Replaces fixed4 MiB / 4 readers / 4 slotsstaging constants with runtimeIoPlan(choose_io_plan,detect_optimal_io_size,available_host_memory_bytes), splitsDeviceloading (load_device) from CUDA-freeMappedHostloading (collect_mapped_host_chunks,load_mapped_host_chunks), addspush_span_chunks/read_direct_into_hostfor 4 KiB-aligned zero-copyO_DIRECTreads withAlignedBufferbounce fallback for unaligned edges, and introducesRegistrationGate. Adds 3 unit tests.helios/src/runtime_core/mod.rs(+618/−86) &format.rs(+1/−1): DerivesPartialEq, EqonMemory(format.rs:51); splitsallocate()intoallocate_device,allocate_mapped_host_vmm,prepare_mapped_host_vmas(coalescedMAP_FIXED_NOREPLACEVMAs, LinuxMADV_HUGEPAGE, ordered 2 MiB-strided multi-threaded pre-faulting without CUDA context locks),load_device_overlapping_mapped_host, andregister_pending_mapped_host(512 MiBchunkedcuMemHostRegister_v2signalingRegistrationGate, followed bycuMemHostGetDevicePointer_v2identity checks); tracks Unixhost_registrationsandhost_mmap_spansseparately for reverse-order teardown (release_execution_resources). Adds 2 unit tests (startup_overlap_tests).helios/src/runtime_core/model.rs(+402/−152): Overlapsprepare_mapped_host_vmaswithload_device_payloadwhenhost_bytes > 0 && device_payload_bytes > 0, and overlaps chunkedregister_pending_mapped_host+prepare_runtime(kernels, graphs, embedding tables,allocate_caches,prepare_offload) withload_mapped_host_chunkswhenhost_payload_bytes > 0, runningapply_payload_relocationsandprepare_async_transfersafter both join; spawns a backgroundflare-frontend-preloadthread on rank 0.helios/src/startup.rs(+31/−8): Removes#[cfg(test)]fromStartupObservation.completed/completed_phases()and addsStartupProgress::replay_completedto re-emit overlapped background stages with" · overlapped"detail while preserving original elapsed durations.helios/src/server/{config.rs,session.rs}&helios/src/server.rs(+145/−58): Extractsload_frontend_inner, addsPreloadedFrontend/preload_frontend/frontend_cache_key/Bootstrap::load_with_preloaded, and consumesowner.take_preloaded_frontend()inLoadedSession::new.
Pre-merge Checks
- [PASS] Security / malicious screen: Standard read-only
/proc/meminfoand/sys/dev/block/*/queue/optimal_io_sizeprobes plusmmap/madvise/mlock/munmapand existingflare_eosdirect I/O helpers; no new external crates, no env-var behavior switches, no untrusted input parsing hazards. - [WARN] Charter & value fit: Right problem in the right model-agnostic runtime layer with no package/ABI/captured-graph contract changes; however, the performance claim is pre-rebase from combined-stack branch #710 rather than
60d1b6bvsmain(Blocker #1), and unconditionalMADV_HUGEPAGE+ undocumented staging changes conflict with established host-mapping policy (#625) and design docs (Should Fix #3–#4). - [WARN] Related / duplicate / conflict check: Subsumes the host-VMA coalescing/THP/pre-fault portion of the author's own open draft #710 without referencing or resolving ownership between #710 and #726; rebase/merge-order coordination needed with open #696 (
model.rs,startup.rs) and #723 (mod.rs,model.rs). - [WARN] Tests & verification evidence: Reported
--locked --releaseCPU test suites (helios1,919,flare255,flare-cli250) and release build are plausible and consistent with recentmain, with 5 genuinely new unit tests (not 6; see Nits); however, CI status on60d1b6bis pending/unobservable here, and servedflare runA/B benchmarks on60d1b6bvsmainare missing (Blocker #1).
Blockers
- Performance claim is not measured on
60d1b6bagainstmain(combined-stack pre-rebase result from #710) — PR description ("Supporting Evidence and Limitations") vs Charter (#210),docs/design-review.md:109-115(Principle 12), andAGENTS.md:99-100.- Verified issue: The PR states that the
75.0 s → 45.5 scold-start measurement was collected "on the equivalentfeat/gb300-tiered-runtimebuild prior to rebasing cleanly ontomain". That branch is open draft #710, which also includes the host-VMA/THP/pre-fault changes (helios/src/runtime_core/mod.rs+120/−44), speculative cost/forecast changes, and GB300 AOT updates. Charter #210 requires performance PRs to show "an actual speedup overmainon a served workload", andAGENTS.md:99-100explicitly prohibits attributing a combined-stack measurement to a single PR. - Fix: Re-run the
flare runcold-startup A/B benchmark on rebased head60d1b6bdirectly against currentmain(attaching the raw per-phase timing output and hardware/THP configuration) and clarify ownership of the duplicated VMA work relative to #710.
- Verified issue: The PR states that the
Should Fix
-
register_pending_mapped_hostbypassesRegistrationGate::close()on every error path —helios/src/runtime_core/mod.rs:804-847(calleehelios/src/runtime_core/payload.rs:583-630; callerhelios/src/runtime_core/model.rs:1152-1170, 1359-1390).- Verified issue: Lines
804-843place?(805, 810-813, 831-834) andreturn Err(...)(836-839) directly inside anunsafe { ... }block rather than an immediately invoked closure. In Rust, those return immediately fromregister_pending_mapped_host, completely skippingif let Some(gate) = gate { gate.close(); }at844-846. In single-rank startup,model.rs:1165-1170happens to close all gates afterruntime_resultreturns, masking a permanent deadlock—but in multi-rank TP (devices.len() > 1),model.parallel(model.rs:1380-1388) joins every rank thread before returningErrto line1165, so a failing rank leaves its host readers parked until every other rank finishes registering all512 MiBchunks (and any direct caller relying onregister_pending_mapped_host's contract would deadlock permanently). - Fix: Wrap the body in
(|| -> Result<()> { unsafe { ... } })()(or aDropguard that closesgateeven on unwind) sogate.close()is structurally guaranteed on every return path.
- Verified issue: Lines
-
load_mapped_host_chunkssilently returnsOk(())on premature non-cancelled gate closure and does not wake parked sibling readers on I/O error —helios/src/runtime_core/payload.rs:682-696, 754-777(calleepayload.rs:620-629; callermodel.rs:1085-1143, 1180-1181).- Verified issue: Two error-handling defects in the host reader loop:
- At
payload.rs:691-696, when!gate.wait_for(required, cancel), the worker simplybreaks without recording an error. Ifgate.close()occurred before chunkrequiredwas registered whilecancel == false,load_mapped_host_chunksreturnsOk(())with unread/zeroedMappedHostweight chunks and an under-countedLoad weightsprogress total. (Note: whencancel == truedue to an external failure inruntime_result, returningOk(())is needed somodel.rs:1180-1181surfacesruntime_result's root error rather than a synthetic cancellation error—so the error should fire specifically when!cancel.load(Ordering::Relaxed).) - At
payload.rs:754-761, when a reader encounters an I/O error, it setscancel.store(true, Ordering::Relaxed)without callinggate.close(). Any sibling reader on the same rank already parked inCondvar::wait(payload.rs:626) will not wake untilregister_pending_mapped_hostfinishes its in-flight512 MiBcuMemHostRegister_v2call and closes the gate (andmodel.rs:1117cannot close gates untilload_mapped_host_chunksjoins all sibling readers).
- At
- Fix: On
!gate.wait_for(required, cancel)when!cancel.load(Ordering::Relaxed), record an error infirst_error(e.g.invalid("mapped host registration closed before chunk was ready")) and setcancel. On reader error atpayload.rs:754-761, also callif let Some(gate) = gate { gate.close(); }so parked sibling readers wake immediately.
- Verified issue: Two error-handling defects in the host reader loop:
-
Unconditional
MADV_HUGEPAGE+ 8-thread eager pre-faulting reintroduces the #616/#625 THP compaction-stall hazard —helios/src/runtime_core/mod.rs:2260-2265, 2274-2324vsdocs/prefix-cache-offload.md:540-557and merged #625.- Verified issue: Prior
main(pr/721mod.rs:623-658) did not callMADV_HUGEPAGEor pre-faultMappedHostspans. #726 unconditionally issueslibc::madvise(mapped, span_bytes, libc::MADV_HUGEPAGE)on every coalescedMappedHostspan (316.6 GiBin the PR's workload) and immediately faults it at2 MiBstride across up to 8 concurrent threads (mod.rs:2288-2324). Under Linux's default workstation THP settings (enabled=madvise, defrag=madviseordefer+madvise) on fragmented memory, this triggers synchronous direct reclaim/compaction (__GFP_DIRECT_RECLAIM) on every hugepage fault—the exact stall that caused #616 (>15 minutes on119 GiB) and that merged #625 retired ineos::map_host(docs/prefix-cache-offload.md:541-557, where #625 measured128.6 svs31.0 sfor just48 GiBon SM120). - Fix: Inspect
/sys/kernel/mm/transparent_hugepage/{enabled,defrag}(reusing or sharingeos/src/unix.rs's Linux THP policy logic) soMADV_HUGEPAGEis only applied unconditionally under non-blocking defrag policies (defer/never), or falls back cleanly to base pages when huge pages are scarce /compact_stallclimbs; disclose the THP policy behavior explicitly in the PR description.
- Verified issue: Prior
-
Normative loader/CLI design docs contradict the shipped changes, and
choose_io_plancan exceed its stated128 MiBcross-rank staging bound at high rank counts —helios/src/runtime_core/payload.rs:143-150, 205-251,helios/src/startup.rs:178-203,helios/src/runtime_core/model.rs:858-862vsdocs/runtime-core-design.md:1006-1018, 1095,docs/core-format-design.md:853-861,docs/cli-design.md:1589-1607.- Verified issue:
docs/runtime-core-design.md:1010-1018, 1095specifies 4 reader threads, 4 pinned staging buffers of4 MiB / rank_count, a16 MiBprocess-wide staging bound, staging copies for host-resident payloads, and readers joining before module/graph setup.docs/core-format-design.md:857-858states "The staging bound is process-wide; adding ranks must not multiply it."docs/cli-design.md:1589-1607describes startup rows without the new" · overlapped"replay suffix (startup.rs:186) or"(overlapping)"allocation detail (model.rs:859). None of these docs are updated.- In
choose_io_plan(payload.rs:222-244),optimal_io_sizecan roundchunk_bytesup toMAX_CHUNK(8 MiB) without dividing byranks, whileper_rank_budgetclamps at.max(chunk_bytes * 2)(240) andbudget_slotsclamps at.max(2)(242). On multi-rank setups with a largeoptimal_io_sizeor tight RAM (e.g.,ranks = 16, optimal_io_size = 8 MiB), total pinned staging across ranks reaches16 × 2 × 8 MiB = 256 MiB, violating bothdocs/core-format-design.md:857-858and the PR's claimed<= 128 MiBcross-rank cap.
- Fix: Cap
chunk_bytes(including afteroptimal_io_sizerounding) against(total_budget / ranks / 2)so multi-rank staging cannot exceedtotal_budget(<= 128 MiB), add a unit test assertingranks * slots * (chunk_bytes + 2 * BLOCK) <= MAX_STAGING_BYTESacross TP1/TP4/TP8/TP16, and updatedocs/runtime-core-design.md,docs/core-format-design.md, anddocs/cli-design.mdto document the new runtime staging budget, zero-copy host loading, and overlapped stage output.
- Verified issue:
Subtract / Simplify
- Replace four duplicated
cleanup(&mut outcome)sites with RAIIDroponMappedHostAllocation—helios/src/runtime_core/mod.rs:2167-2170, 2230-2258, 2325-2342. ImplementingDropto reverse-munmapself.mappings(disarmed whenattach_mapped_hostdrainsmappingsintoself.host_mmap_spans) eliminates thecleanupclosure and all four manual error/cancel teardown blocks while mechanically enforcing theSAFETYcomment at line2187. - Deduplicate the
read_atshort-read loop inChunk::readandChunk::read_direct_into_host—helios/src/runtime_core/payload.rs:363-422. Both implement identicalInterrupted-retry, EOF, andBLOCK-alignment checks; extracting onefn read_full_at(file: &File, offset: u64, dst: &mut [u8]) -> io::Result<()>removes ~25 duplicated lines. - Hoist the duplicated post-load tail and simplify
pending_registrationsround-tripping inNativeModel::load_agreeing—helios/src/runtime_core/model.rs:882-906, 1146-1155, 1182-1217. The four post-load statements (apply_payload_relocations, integratedrelease_page_cache,load_phase.finish) are identical in both arms (1182-1191and1208-1217), andpending_registrationsis convertedVec → Mutex<Vec<Option>> → Vec → Mutex<Vec<Option>>with silentunwrap_or_default()fallbacks. - Remove dead tuple element from
tier_io_planand redundantoptimal_io_sizebounds check —helios/src/runtime_core/payload.rs:173-175, 222, 482-522, 640, 792. Both callers discardtier_io_plan's second return value(plan, _), andchoose_io_plan:222re-checks the exactBLOCK..=MAX_CHUNK/% BLOCK == 0predicate already enforced bydetect_optimal_io_size:173-175. - Unify
PendingHostRegistrationplatform fields andRegistrationGateemptiness checks —helios/src/runtime_core/mod.rs:2132-2163, 797-856,model.rs:1053-1059,payload.rs:599, 621. MakingPendingHostRegistration.chunks: Vec<(u64, usize, u32)>unconditional (always empty off-Unix) removes redundant#[cfg(not(unix))]arms and duplicated emptiness checks. - Keep
StartupObservation.completedretention opt-in —helios/src/startup.rs:111-113, 136-138, 170-175. Onlymodel.rs:1075(overlapped background phases) and tests callcompleted_phases(); making completion retention opt-in avoids cloning and retaining every completed snapshot across all non-overlapping observed loads.
Nits
- Cluster rank 0 preloads the frontend twice:
helios/src/runtime_core/model.rs:709-720spawnsflare-frontend-preloadwhencluster.is_none_or(|c| c.rank == 0), buttake_preloaded_frontend()is only consumed inLoadedSession::new(helios/src/server/session.rs:27-36, which rejects clustered models); multi-host rank 0 inflare-cli/src/main.rs:638callsBootstrap::loaddirectly, discarding the preloaded frontend. Either gate preloading onmodel.cluster.is_none()or wire cluster rank 0 to consume it. - Silent preload error swallowing:
helios/src/runtime_core/model.rs:717-718, 1224swallows preload errors via.ok()/.flatten(), so a broken preload silently falls back to synchronous loading without telemetry or warning. - PR description test count: The PR body claims "6 new unit tests", whereas 5 are newly added by this PR (
payload.rs:989, 1013, 1071andmod.rs:2433, 2460);model.rs::async_transfers_reject_peer_copy_graphs_at_load_timealready existed on mergedpr/721(model.rs:1517).
Dropped on verification
- Unconfirmed write-after-unmap window during device-payload failure (
mod.rs:721-781+2274-2331) — Dropped (false): Insideprepare_mapped_host_vmas,std::thread::scope(mod.rs:2308-2324) joins every pre-fault worker before line2325and before returning; outside,load_device_overlapping_mapped_host(mod.rs:734-763) joinshost_workerbeforeattach_mapped_hostanddevice_result?(767-768). No fault write can outlive unmap. pub mod host;API expansion andhost_vmmintroduction (mod.rs:22, 369) — Dropped (false / diff-base artifact): Verified directly at mergedpr/721:helios/src/runtime_core/mod.rs:22already hadpub mod host;andmod.rs:365already hadlet host_vmm = host::use_host_vmm(&driver, device)?;.engram::reader::AlignedlacksDropand leaks (helios/src/engram/reader.rs:130-141) — Dropped (false): Verified athelios/src/engram/reader.rs:456-459thatimpl Drop for Alignedexists and callscrate::os::free_aligned(self.0, self.1).helios/src/server/config.rsomitted from the PR description's file list — Dropped (false):helios/src/server/config.rsis explicitly listed in the third bullet of## What Changed.- "All-host cores take the old serial path" (
model.rs:850) — Dropped (inaccurate):overlap_host_alloc(model.rs:850) only gates overlapping host VMA prep withDeviceweight uploads; all-host cores (host_payload_bytes > 0 && device_payload_bytes == 0) still take themodel.rs:1048branch overlappingMappedHostweight loading withprepare_runtime. Load weightsmulti-thread progress accounting defect (Code Correctness Finding 3) — Dropped (duplicate):Phase::advance_bytes(startup.rs:326-336) is mutex-serialized and exact; under-counting only occurs as a secondary symptom of Should Fix #2 (premature gate close).State.elapsedonly used to smuggle duration throughpublish— Dropped (inaccurate):State::render(startup.rs:439-442) also readsself.elapsedwhen writing replayed rows to stderr.- Unobservable CI status and open-PR overlap with #710/#696/#723 as blockers — Dropped from Blockers/Should Fix: Kept appropriately in
## Pre-merge Checksand## Merge Risk.