PR #696: helios: parallelize engram loading and report startup progress

Raw Markdown for agents: https://autobot.eidonix.com/api/v1/cases/55eda83e-4972-48c9-927e-e9a08aea2a5a

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

explore

Author: malventano (CONTRIBUTOR; 2 merged PRs — #578, #316; Discord: malventano) Motivation: RAM Engram startup load was serial and slow — 188.8 GiB read in 37.7s, versus 293.9 GiB of weights in 15.3s — so the author parallelizes the per-shard loads, keeps the populated mapping instead of remapping it, hints transparent hugepages, and adds byte progress plus a final "Startup complete" line. Claimed: Engram 37.7s → 9.6s, total startup 66.7s → 38.4s. Scale: +209 / −30 lines in 7 files Proposal:

Full report · Notes

Classify intake

Selected: triage:review, performance, area:engram

Threshold: 65%

Triage

Priority

Type

Area

Model

Apply Labels (Intake)

Applied: +triage:review, +performance, +area:engram

Value Proposition

Value Proposition — PR #696 “helios: parallelize engram loading and report startup progress”

Charter alignment. helios-only, no new flags, no per-model branches, no new dependencies (existing libc), so it fits “keep the runtime small and model-agnostic,” and the logging half mirrors the existing weights pattern in the shared startup module. Engram is scoped broadly under #267; this is a narrow perf/logging change inside it, not a design change. Two frictions: (1) the THP hint re-adds precisely the pattern that #616 condemned (“unconditionally advises MADV_HUGEPAGE over the entire range”) and that merged #625 replaced one day earlier with sysfs policy reads, /proc/buddyinfo probing and a base-page fallback. #696 reads no shmem_enabled/defrag, probes nothing, has no fallback, and its own numbers show the compaction cost (13.7 s fragmented vs 9.6 s clean/defragmented). (2) Two of three mechanisms are Linux-only unsafe syscall edits in the resident-table path used by every RAM and resident-scales startup, with no end-to-end test.

Novelty & status. Genuinely additive. No commits on main since cc0a49d touch the changed files (not obsolete); #664, #554 and #334 touch the same files for different purposes (not superseded); #470 (gathers) and #586 (export assembly) parallelized other engram stages — this is the last serial stage.

Value vs cost. The mechanisms have real value: removal of the second full page-table population pass (MADV_POPULATE_READ remap) and parallel group loads with layout and binding order provably unchanged. But the evidence misses the #210 / docs/design-review.md:106-115 bar: one private host, sequential build measurements self-described as “not an isolated A/B for every stage,” full test suite not run, startup time rather than a served workload, and no filed issue behind the goal — it is a self-set benchmark target. Costs: unbounded loader fan-out (one thread per group × up to 4 synchronous pread threads × per-reader CUDA streams and pinned staging), a relaxed has_resident_seals contract, no test for the new mprotect/F_SEAL_FUTURE_WRITE path, loading-display docs untouched, two cited docs that do not exist, and the claimed “final engram line includes resident size” not implemented.

Verdict: Worth it with changes.

Keep parallel rank loads and the retained read-only mapping. Required changes: drop or rework the unconditional MADV_HUGEPAGE along #625’s policy-probing style; implement or remove the resident-size claim; document the new byte counter and Startup complete row in docs/cli-design.md and docs/runtime-core-design.md; add a test covering the new seal/read-only path; bound and state the loader thread count; supply main-vs-head evidence per #210.

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

Five simplifications for PR #696, ordered by value; the rest of the diff is lean.

  1. Delete the THP hint (helios/src/engram/reader.rs:184-192) — unconditional MADV_HUGEPAGE over the whole writable memfd mapping: no policy read, no bound, no opt-out, return value discarded. It is the exact pattern issue #616 found produced a 914.6 s stall and merged PR #625 removed from eos/src/unix.rs (not opened), still listed as an audit item in docs/TODO.txt:1-6. The author's own data (13.7 s fragmented vs 9.6 s clean) shows the cost. Nothing else in the PR depends on it: delete, don't tune.
  2. Fold two Option<&Phase> shim pairs — Resident::load/load_with_progress (reader.rs:272-276) and Reader::from_files/from_files_with_progress (reader.rs:1352-1375). Every non-progress caller is in-crate (engram.rs test module, reader.rs tests), so add the parameter and delete both wrappers: ~23 lines, one fewer public name.
  3. Collapse the seal split (reader.rs:229-269): seal_resident_seals + seal_resident + seal_resident_future + a cfg-switched has_resident_seals accepting "either seal set". Keep one sealer called with a mask and make the predicate take the expected mask; removes two functions and the not(linux) => false arm (~20 lines). The either-set relaxation is speculative generality — after this PR only the non-Linux unix branch and tests produce the full-write set.
  4. Drop the intermediate Vec (helios/src/runtime_core/model.rs:873-879): let groups: Vec<_> = ...collect() exists only for .len() and is consumed on the next line; iterate engram.into_iter().zip(engram_tokens).enumerate() directly.
  5. StartupProgress::complete (helios/src/startup.rs:215-236) hand-builds a State and repeats the publish+write steps already owned by phase_named/Phase::drop; extract a shared State::new or route through the phase path, which also retires the special-cased started field.

Non-findings: the advance_bytes(0) byte-progress plumbing mirrors Load weights (model.rs:802-803) and is correct; the scoped-join block is necessary; the call-site insertions are trivial.

Open: whether the THP gain is worth a policy-aware follow-up reusing #625; whether complete's "Complete without a matching phase" publish is intentional for the observation consumer; whether the seal-predicate shape came from #590's author. No CI on head, so test claims are unverified.

Full report · Notes

Correctness and contracts

Correctness/contracts review of PR #696 at head 24ff7e1. Seven findings, four Major.

Major findings

Minor: stale kernel-floor comment (reader.rs:222-227 — the new path never calls MADV_POPULATE_READ); per-4 MiB Phase mutex + format! + snapshot clone hot-path cost (reader.rs:303-305, startup.rs:132-146,329-339); no test asserts the mprotect(PROT_READ) at reader.rs:409 (only the superseded full-seal test at reader.rs:1665-1678), and has_resident_seals (reader.rs:256-269) widened the seal contract; complete()'s timing base excludes config parsing (startup.rs:216-226) and uses StartupStage::Other.

Sound (verified, stated as non-findings): retained mapping/mprotect/seal sequence, group-ordered join + unchanged bindings.sort_by_key (layout preserved), no orphan-loader hazard via thread::scope, Windows and non-Linux unix parity, additive progress plumbing, unchanged rendering and Drop behavior.

Open questions: is shmem THP advice acceptable given #616/#625; where do the two cited docs come from; what bounds loader thread count (interacts with #576, #640); is resident size meant to appear at all; performance numbers unverifiable; DCO/sign-off not observable.

Full report · Notes

Final review

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

Walkthrough

Pre-merge Checks

Blockers

  1. Unconditional madvise(MADV_HUGEPAGE) re-introduces the THP compaction-stall hazard retired by #625 (helios/src/engram/reader.rs:184-192).
    • ResidentMapping::new unconditionally calls libc::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/buddyinfo or compact_stall probing, and no base-page fallback or opt-out.
    • On fragmented Linux hosts with shmem_enabled=advise and synchronous compaction (defrag=madvise, defer+madvise, or always), 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 in eos/src/unix.rs:463-740 (with remaining unconditional MADV_HUGEPAGE sites tracked for audit in docs/TODO.txt:1-6). The PR's own measurements already show a 4.1 s fragmentation penalty (13.7s fragmented vs 9.6s clean).
    • Fix (prefer subtraction): Delete the 9-line MADV_HUGEPAGE block at helios/src/engram/reader.rs:184-192 and 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.1s in the author's measurements). If shmem THP is wanted later, pursue it in a follow-up PR with shmem_enabled/defrag policy inspection and bounded fallback matching eos/src/unix.rs.

Should Fix

  1. Disk-only Engram loads display bogus 0.0 GiB progress (helios/src/runtime_core/model.rs:840-842).
    • Line 842 calls phase.advance_bytes(0) unconditionally even when resident_bytes == 0 (default Storage::Disk without --embedding-table-resident-scales, where progress_total is None and Resident::load_with_progress never runs). Phase::advance_bytes(0) (helios/src/startup.rs:329-336) sets state.detail = "0.0 GiB", printing a misleading 0.0 GiB byte 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);
      }
      
  2. 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, but phase.finish(...) at model.rs:941-948 passes only label (and optional row-cache/prefetch text). Because Phase::finish calls self.detail(detail) (helios/src/startup.rs:351-359), it overwrites the byte progress string, rendering Prepare embedding tables. RAM 9.6s.
    • Fix: Either prepend {:.1} GiB · (from resident_bytes, mirroring Load weights at model.rs:810-813) when resident_bytes != 0, or remove the claim and update the sample output in the PR description.
  3. Desktop controller.rs emits StartupStage::Other before 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:2779 constructs StartupProgress::observed() (no stderr output) and clears s.startup = None at controller.rs:2938. Calling progress.complete() at controller.rs:2914 right before mDNS Advertisement::start (:2916-2922) publishes stage: StartupStage::Other ("other") and total: None while view.state is still SessionState::Loading. If WinUI polls status() during mDNS setup (controller.rs:1020-1027), Dashboard.inl:14, 92, 95 maps "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 at flare/src/controller.rs:2914 (keeping the CLI call sites in flare-cli/src/main.rs:668, 737), or add a dedicated StartupStage handled in Dashboard.inl.
  4. 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 -> Documentation lists docs/FLARE_START.md (not opened) and docs/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 existing Resident::load tests (reader.rs:1708, 1762, 1812) now run the Linux initialize() path and check set_len/pwrite rejection, no test checks that the retained mapping itself is read-only (PROT_READ) or asserts F_GET_SEALS contains RESIDENT_FUTURE_SEALS and rejects a new mmap(PROT_READ | PROT_WRITE, MAP_SHARED) on the descriptor. Deleting mprotect(PROT_READ) at reader.rs:409 would leave all 18 tests green. Add a focused Linux unit test verifying the RESIDENT_FUTURE_SEALS bitmask, rejection of new writable mmap, and read-only protection of the retained mapping (e.g., inspecting /proc/self/maps or VMA permissions for the mapping range).
    • Validation & benchmark evidence (docs/design-review.md:106-115): Run the --release test 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 equivalent main-vs-head startup comparison including the exact command/model configuration.

Subtract / Simplify

  1. Drop the redundant groups: Vec<_> collection (helios/src/runtime_core/model.rs:873-879): engram is already a Vec, so engram.len() is known directly. Replace let groups: Vec<_> = engram.into_iter().zip(engram_tokens).collect(); with let mut handles = Vec::with_capacity(engram.len()); and iterate engram.into_iter().zip(engram_tokens).enumerate() directly.
  2. Collapse private *_with_progress forwarding wrappers (helios/src/engram/reader.rs:272-276, 1352-1385): helios/src/engram.rs:12 declares mod reader; privately, and every non-progress caller of Resident::load (5 test sites) and Reader::from_files (12 test sites + 1 #[cfg(test)] helper) is internal to helios::engram. Fold progress: Option<&Phase> directly into Resident::load and Reader::from_files (or restrict the no-progress convenience wrappers to #[cfg(test)]) to drop ~25 lines of boilerplate.
  3. Inline single-caller seal_resident_future (helios/src/engram/reader.rs:251-254, 417): seal_resident_future has only one caller (reader.rs:417); call seal_resident_seals(&backing, RESIDENT_FUTURE_SEALS)? directly.

Nits

Dropped on verification

Full report 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.

Classify triage

Selected: triage:review

Threshold: 65%

Triage

Apply labels

No label changes