Recommendation: Changes Requested
The core optimizations—loading independent Engram shard groups concurrently (helios/src/runtime_core/model.rs:870-918) and retaining the populated Linux memfd via mprotect(PROT_READ) + F_SEAL_FUTURE_WRITE (helios/src/engram/reader.rs:404-424)—are technically sound and preserve deterministic table layout, binding order, CUDA context isolation, and cross-platform parity. However, the PR re-introduces an unconditional whole-mapping madvise(MADV_HUGEPAGE) (helios/src/engram/reader.rs:184-192) that mirrors the exact THP compaction-stall hazard just retired by #625, and also has four concrete gaps to resolve: spurious 0.0 GiB progress on disk-only tables, an unimplemented claimed finish-line resident size, a spurious desktop WinUI stage emission in flare/src/controller.rs, and missing test/evidence/description hygiene.
Merge Risk
Level: Medium
- Shared Linux resident-table path (
helios/src/engram/reader.rs): Every RAM-Engram (--embedding-table-storage ram), resident-scales (--embedding-table-resident-scales), andPreparedTables::loadstartup on Linux runs the newMADV_HUGEPAGE+mprotect(PROT_READ)+F_SEAL_FUTURE_WRITEpath. UnconditionalMADV_HUGEPAGErisks unbounded synchronous kernel compaction stalls on fragmented hosts undershmem_enabled=adviseanddefrag=madvise|defer+madvise|always. - Startup observability & desktop UI (
helios/src/startup.rs,flare/src/controller.rs,helios/src/runtime_core/model.rs): Disk-only startups (the default storage mode) now render0.0 GiBduringPrepare embedding tables, and the desktop worker publishesStartupStage::Otherright before mDNS advertisement while still inSessionState::Loading. - Unverified build/test status: No CI checks are attached to head
24ff7e1, and the author ran only 18 reader tests, 3 startup tests, andcargo checkrather than the--releasetest suites across the modified crates (helios,flare,flare-cli).
Walkthrough
helios/src/runtime_core/model.rs(+49/−19): Passesresident_bytesas the byte progress total forPrepare embedding tables(:840-842) and replaces the serial shard-group loop withthread::scopespawning oneflare-engram-rank-{group}thread per deduplicated local rank group, joining handles in group order before the existingbindings.sort_by_key(:870-918).helios/src/engram.rs(+4/−1) &helios/src/runtime_core/event_tests.rs(+1): Plumbsprogress: Option<&Phase>throughShared::newtoReader::from_files_with_progress.helios/src/engram/reader.rs(+114/−10): Adds unconditionalmadvise(MADV_HUGEPAGE)on writable Linux resident mappings (:184-192); splits sealing to addRESIDENT_FUTURE_SEALS(F_SEAL_FUTURE_WRITE) and letshas_resident_sealsaccept either seal set (:222-269, 444); retains the populated Linux mapping inResident::initializeviamprotect(PROT_READ)+seal_resident_futureinstead of dropping and remapping (:404-424); addsResident::load_with_progressandReader::from_files_with_progresscallingphase.advance_bytesper 4 MiB chunk (:272-320, 1352-1415).helios/src/startup.rs(+38): RecordsStartupProgress.startedat construction (:24, 163, 173), addsStartupProgress::complete()emitting[ OK ] Startup complete. X.Xsand publishingStartupStatus::CompletewithStartupStage::Other(:215-236), and adds unit testcomplete_publishes_the_final_startup_total(:566-576).flare-cli/src/main.rs(+2) &flare/src/controller.rs(+1): Callsprogress.complete()afterStart serverfinishes inserve(main.rs:668),serve_local(main.rs:737), and desktopWorker(controller.rs:2914).
Pre-merge Checks
- [PASS] Security / malicious screen: Standard
madvise/mprotect/fcntlLinux syscalls via existinglibcdependency; no new dependencies, env switches, network I/O, or untrusted input regressions. (Note: underF_SEAL_FUTURE_WRITE, the owner's retained VMA still carriesVM_MAYWRITEin-process, whileResidentnever exposes mutable pointers andPreparedTables::from_sharedpeers still map read-only via/proc/self/fd.) - [WARN] Charter & value fit: Narrow, model-agnostic Helios optimization with real speedup potential, but unconditional
MADV_HUGEPAGEreverses the THP policy direction established by #625, and the evidence/docs sections do not yet meetAGENTS.md:103-112/docs/design-review.md:106-115. - [WARN] Related / duplicate / conflict check: Additive to
main(no conflicting commits sincecc0a49d), but directly conflicts in THP policy with merged #625 (eos/src/unix.rs:463-740,docs/TODO.txt:1-6) and touches the same Engram loader files as open #664, #554, #334, and #640. - [WARN] Tests & verification evidence: No CI on
24ff7e1; full--releasetest suites forhelios/flare/flare-cliwere not run; no test asserts the newmprotect(PROT_READ)enforcement; timings are sequential build snapshots rather than an equivalentmain-vs-head comparison; two cited docs do not exist.
Blockers
- Unconditional
madvise(MADV_HUGEPAGE)re-introduces the THP compaction-stall hazard retired by #625 (helios/src/engram/reader.rs:184-192).ResidentMapping::newunconditionally callslibc::madvise(address, nbytes, libc::MADV_HUGEPAGE)over the entire writable memfd mapping and ignores the return value, with no inspection of/sys/kernel/mm/transparent_hugepage/{shmem_enabled,defrag}, no/proc/buddyinfoorcompact_stallprobing, and no base-page fallback or opt-out.- On fragmented Linux hosts with
shmem_enabled=adviseand synchronous compaction (defrag=madvise,defer+madvise, oralways), faulting up to ~188.8 GiB concurrently across all loader threads can trigger severe synchronous compaction stalls—the exact anti-pattern behind P2 issue #616 (>15-minute startup stall) that merged PR #625 replaced ineos/src/unix.rs:463-740(with remaining unconditionalMADV_HUGEPAGEsites tracked for audit indocs/TODO.txt:1-6). The PR's own measurements already show a 4.1 s fragmentation penalty (13.7sfragmented vs9.6sclean). - Fix (prefer subtraction): Delete the 9-line
MADV_HUGEPAGEblock athelios/src/engram/reader.rs:184-192and update the PR description accordingly. Parallel rank-group loading and retained read-only mapping are completely independent and already provide the bulk of the speedup (37.7s -> 15.1sin the author's measurements). If shmem THP is wanted later, pursue it in a follow-up PR withshmem_enabled/defragpolicy inspection and bounded fallback matchingeos/src/unix.rs.
Should Fix
- Disk-only Engram loads display bogus
0.0 GiBprogress (helios/src/runtime_core/model.rs:840-842).- Line 842 calls
phase.advance_bytes(0)unconditionally even whenresident_bytes == 0(defaultStorage::Diskwithout--embedding-table-resident-scales, whereprogress_totalisNoneandResident::load_with_progressnever runs).Phase::advance_bytes(0)(helios/src/startup.rs:329-336) setsstate.detail = "0.0 GiB", printing a misleading0.0 GiBbyte counter on stderr and publishing it to desktop startup status. - Fix: Guard the initial call so it only runs when resident bytes exist:
if resident_bytes != 0 { phase.advance_bytes(0); }
- Line 842 calls
- Claimed final resident-size output is not implemented (
helios/src/runtime_core/model.rs:941-948).- The PR description states "The final engram line includes resident size" and shows
[ OK ] Prepare embedding tables. 188.8 GiB · RAM 9.6s, butphase.finish(...)atmodel.rs:941-948passes onlylabel(and optional row-cache/prefetch text). BecausePhase::finishcallsself.detail(detail)(helios/src/startup.rs:351-359), it overwrites the byte progress string, renderingPrepare embedding tables. RAM 9.6s. - Fix: Either prepend
{:.1} GiB ·(fromresident_bytes, mirroringLoad weightsatmodel.rs:810-813) whenresident_bytes != 0, or remove the claim and update the sample output in the PR description.
- The PR description states "The final engram line includes resident size" and shows
- Desktop
controller.rsemitsStartupStage::Otherbefore mDNS setup, triggering a spurious WinUI loading step (flare/src/controller.rs:2914,helios/src/startup.rs:216-236,flare-winui/Dashboard.inl:2-15, 91-95).flare/src/controller.rs:2779constructsStartupProgress::observed()(no stderr output) and clearss.startup = Noneatcontroller.rs:2938. Callingprogress.complete()atcontroller.rs:2914right beforemDNS Advertisement::start(:2916-2922) publishesstage: StartupStage::Other("other") andtotal: Nonewhileview.stateis stillSessionState::Loading. If WinUI pollsstatus()during mDNS setup (controller.rs:1020-1027),Dashboard.inl:14, 92, 95maps"other"to"Prepare local serving", appends an out-of-order step after"Check the local server", and switches the progress bar back to indeterminate.- Fix: Remove the unnecessary
progress.complete();call atflare/src/controller.rs:2914(keeping the CLI call sites inflare-cli/src/main.rs:668, 737), or add a dedicatedStartupStagehandled inDashboard.inl.
- Missing read-only mapping test, unrun crate test suites, and inaccurate PR description evidence (
helios/src/engram/reader.rs:404-424, PR description).- Phantom doc references: The PR description's
Evidence -> Documentationlistsdocs/FLARE_START.md(not opened) anddocs/FLARE_PATCH_SERIES.md(not opened), neither of which exists in the repository (no docs are modified). Remove these citations (AGENTS.md:62-65, 112). - Untested
mprotect(PROT_READ)contract: While existingResident::loadtests (reader.rs:1708, 1762, 1812) now run the Linuxinitialize()path and checkset_len/pwriterejection, no test checks that the retained mapping itself is read-only (PROT_READ) or assertsF_GET_SEALScontainsRESIDENT_FUTURE_SEALSand rejects a newmmap(PROT_READ | PROT_WRITE, MAP_SHARED)on the descriptor. Deletingmprotect(PROT_READ)atreader.rs:409would leave all 18 tests green. Add a focused Linux unit test verifying theRESIDENT_FUTURE_SEALSbitmask, rejection of new writablemmap, and read-only protection of the retained mapping (e.g., inspecting/proc/self/mapsor VMA permissions for the mapping range). - Validation & benchmark evidence (
docs/design-review.md:106-115): Run the--releasetest suites for the modified crates (helios,flare,flare-cli), confirm green CI, and after removing the THP block, replace the sequential build table with an equivalentmain-vs-head startup comparison including the exact command/model configuration.
- Phantom doc references: The PR description's
Subtract / Simplify
- Drop the redundant
groups: Vec<_>collection (helios/src/runtime_core/model.rs:873-879):engramis already aVec, soengram.len()is known directly. Replacelet groups: Vec<_> = engram.into_iter().zip(engram_tokens).collect();withlet mut handles = Vec::with_capacity(engram.len());and iterateengram.into_iter().zip(engram_tokens).enumerate()directly. - Collapse private
*_with_progressforwarding wrappers (helios/src/engram/reader.rs:272-276, 1352-1385):helios/src/engram.rs:12declaresmod reader;privately, and every non-progress caller ofResident::load(5 test sites) andReader::from_files(12 test sites + 1#[cfg(test)]helper) is internal tohelios::engram. Foldprogress: Option<&Phase>directly intoResident::loadandReader::from_files(or restrict the no-progress convenience wrappers to#[cfg(test)]) to drop ~25 lines of boilerplate. - Inline single-caller
seal_resident_future(helios/src/engram/reader.rs:251-254, 417):seal_resident_futurehas only one caller (reader.rs:417); callseal_resident_seals(&backing, RESIDENT_FUTURE_SEALS)?directly.
Nits
- Join-all error collection (
helios/src/runtime_core/model.rs:908-916): Collecting allhandle.join()outcomes before propagating?—matchingNativeModel::parallelatmodel.rs:1060-1068—avoids a potential double-panic on scope exit if one group returnsErrwhile a sibling thread panics. - Description precision & docs: The PR description says "prepare the four engram rank shards concurrently"; the code spawns one thread per local shard group (
engram.len() <= cores.len(), e.g., 4 on a 4-GPU rank-sharded deployment, 1 when replicated). Also clarify thatStartup completemeasures fromStartupProgressconstruction (flare-cli/src/main.rs:213, post-config/API-key resolution) rather than full process wall time, and optionally note theStartup completerow indocs/cli-design.md:1567-1587.
Dropped on verification
- Upstream F1 ("Major — Unbounded, three-level loader fan-out
groups × tables × planes × 4; rising peak pinned-host memory"): Dropped as false.helios/src/runtime_core/model.rs:445-465buildsengramby iterating over localcoresand deduplicating equalIndexvalues, sogroups.len() <= cores.len()(bounded by local GPU count, not "whatever the catalog declares"). Within each group thread, tables load serially (helios/src/engram.rs:629-651) and planes load serially (helios/src/engram/reader.rs:1393-1404), so peak loader concurrency isgroups.len() × 4—identical toLoad weights(model.parallel×READERS = 4inhelios/src/runtime_core/payload.rs:141, 313). Each group binds a disjoint rank CUDA context (helios/src/cuda.rs:740-770, 869-896), and staging buffers live for the full serving lifetime so peak pinned-host memory is unchanged. - Upstream F4 / Dossier ("Stale kernel-floor comment:
MADV_POPULATE_READnever runs on Linux, so floor drops to 5.1"): Dropped as false.PreparedTables::from_shared(helios/src/engram/prepared.rs:180) callsResident::from_shared->ResidentMapping::new(&file, extent, false)->MADV_POPULATE_READ(helios/src/engram/reader.rs:195-206) on Linux in production, so the comment atreader.rs:222-224remains accurate. - Upstream F5 ("Per-4 MiB
phase.advance_bytesmutex contention + 48kStartupSnapshotclones"): Dropped as overstated / inaccurate. On CLI (StartupProgress::stderr()),self.observationisNone, soPhase::publish(helios/src/startup.rs:316-320) is a no-op with zero snapshot clones. Furthermore,Load weights(helios/src/runtime_core/payload.rs:246, 431) already callsphase.advance_bytesacross parallel rank threads every1 MiBon TP4 (~300k calls for 293.9 GiB in 15.3 s)—6× more frequent than Engram's 4 MiB chunks (~48k calls). - Upstream Subtraction #3 (
has_resident_sealseither-set relaxation claimed speculative; suggested checking onlyRESIDENT_FUTURE_SEALSon Linux): Dropped as incorrect.PreparedTables::from_shared(helios/src/engram/prepared.rs:180) is a live Linux caller ofResident::from_shared, andF_SEAL_WRITE(0x08) andF_SEAL_FUTURE_WRITE(0x10) are distinct bitflags on Linux—checking onlyRESIDENT_FUTURE_SEALSwould wrongly reject a strictly strongerF_SEAL_WRITE-sealed memfd. Accepting either set on Linux is correct. - Upstream Subtraction #5 ("
StartupProgress::completeduplicatesphase_named/Phase::drop; reusephase_named(...).finish(\"\")"): Dropped as regressive. Routingcomplete()throughphase_named(helios/src/startup.rs:242-295) would emit a spuriousStartupStatus::Runningevent, print an extra[ PENDING ] Startup complete.line on redirected stderr, spawn/join an unnecessary animation thread, and loseself.startedelapsed timing. - Upstream claim ("None of the 18 reader tests covers the new Linux path"): Refined—five existing tests (
reader.rs:1708, 1762, 1812, 1823, 2061) callResident::loadand therefore exercise the new Linuxinitialize()path (includingset_lenandpwriterejection atreader.rs:1769-1774). Retained only the verified narrow gap:mprotect(PROT_READ)andRESIDENT_FUTURE_SEALS/ writable-mmaprejection are not asserted directly. - Upstream F8 claim ("
docs/cli-design.md:1581anddocs/runtime-core-design.md:894-897are broken as a Major issue"): Downgraded—docs/cli-design.md:1581("Memory loading advances by bytes") is consistent with resident Engram byte progress, anddocs/runtime-core-design.md:894-897specifically describesAllocate model memoryandLoad weights. Retained the phantom doc references in Should Fix and movedStartup completedoc mention to Nits.