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

Raw Markdown for agents: https://autobot.eidonix.com/p/876b1473-28a0-4413-8545-47c7badcb08f.md

#1 [high] Verified diff mechanics of PR 696 (reader.rs)

PR #696 head 24ff7e1, base main cc0a49d. 7 files +209/-30.

helios/src/engram/reader.rs:

helios/src/runtime_core/model.rs:

helios/src/startup.rs:

Call sites: flare-cli/src/main.rs:668 (serve), :737 (serve_local), flare/src/controller.rs:2914.

#2 [high] PR 696 correctness/system-consequences findings F1-F8

All verified by reading files at head 24ff7e1.

F1 MAJOR — unbounded loader fan-out (nested ×4). model.rs:877-906 spawns one thread per engram group with no bound (for (group, ((index, ranks), tokens)) in groups.into_iter().enumerate(), name flare-engram-rank-{group}). Inside each, engram.rs:629-651 builds one Reader::from_files_with_progress per table; reader.rs:1391-1405 calls Resident::load_with_progress for both planes (RAM) or plane 1 (resident scales); reader.rs:280-311 then spawns LOAD_READERS.min(extent.div_ceil(LOAD_CHUNK)) = up to 4 threads each issuing synchronous 4 MiB pread (eos/src/unix.rs:18-35). Pre-PR: groups serial, so peak = tables×planes×4. Post-PR: groups × tables × planes × 4. Plus one Stream::open per group (CUDA cuCtxSetCurrent on the new thread, cuda.rs:740-770) and STAGING_FRAMES pinned host bufs per table (engram.rs:681-693), previously serialized. Description says "prepare the four engram rank shards concurrently" — not what the code does (count comes from the core's engram catalog, model.rs:445-464). Impact: on a many-table catalog the O_DIRECT queue depth and thread count scale with catalog size; on a 3-drive RAID0 the extra interleaved 4 MiB preads can reduce sequential read locality, the opposite of the stated goal. Fix: cap concurrent groups (e.g. a bounded pool or min(groups, 4)) and/or derive from embedding_workers(), document the bound.

F2 MAJOR — THP policy reversal vs merged #625. reader.rs:187-192 unconditional libc::madvise(..., MADV_HUGEPAGE) on the writable memfd, return value ignored, no policy read, no fallback. Merged #625 replaced exactly this pattern in eos/src/unix.rs with detect_thp_policy() (eos/src/unix.rs:463) and conditional advice + base-page fallback (populate_linux, eos/src/unix.rs:718, advice at 727); the open-work note is docs/TODO.txt:1-6. #696's own measurements (13.7 s fragmented vs 9.6 s clean) are the compaction stall now sitting on every RAM-engram startup with no time bound. Fix: gate on /sys/kernel/mm/transparent_hugepage/{shmem_enabled,defrag} as eos does, or make it opt-in; at minimum check the madvise return.

F3 MAJOR — description claim "The final engram line includes resident size" is not implemented. model.rs:941-948 phase.finish(...) passes only the storage label / row-cache note; startup.rs:356-359 finish → detail() REPLACES the x / y GiB text set by advance_bytes (startup.rs:329-339). So the OK row renders Prepare embedding tables. RAM 9.6s, not 188.8 GiB · RAM. The weights phase it claims to mirror does add the size itself (model.rs:810-813). Fix: format the resident size into the finish label.

F4 MINOR — stale kernel-floor justification. reader.rs:222-224 says "The read-only resident mapping also uses MADV_POPULATE_READ (Linux 5.14), so this does not raise the existing minimum kernel dependency", but the new Linux initialize() (reader.rs:404-424) never calls from_shared, and MADV_POPULATE_READ only runs on !writable mappings (reader.rs:195-206). The floor actually drops to the 5.1 seal. Comment misstates the contract.

F5 MINOR — metric hot-path cost. reader.rs:303-305 calls phase.advance_bytes(nbytes) once per 4 MiB: one shared Phase.state mutex across all groups (created once at model.rs:841, passed to every group), plus a format! per call (startup.rs:333-336) and a full StartupSnapshot clone with label+detail Strings (startup.rs:132-146). ~48k calls per 188.8 GiB, contended by all reader threads; the 10 s emission interval exists only in the animation thread (startup.rs:276-280), so the counter/detail work is unbounded. Fix: accumulate in an AtomicU64 and refresh Phase at most every N MiB or on the tick.

F6 MINOR — untested new invariant. mprotect(PROT_READ) (reader.rs:409) is not asserted by any test; resident_sealing_rejects_a_retained_writable_mapping (reader.rs:1667-1678) still tests the full-F_SEAL_WRITE seal_resident, and shared_resident_plane_outlives_source_and_loader_and_rejects_mutation (reader.rs:1751-1783) proves immutability via pwrite/set_len failure, which the seals provide — so deleting the mprotect would keep the suite green. has_resident_seals (reader.rs:256-269) also silently widens the accepted seal set for from_shared callers.

F7 MINOR — the new row's timing base and stage id. complete() (startup.rs:215-236) uses self.started (set in the ctor, startup.rs:163/173) so "Startup complete. 38.4s" is not comparable to the per-phase rows and excludes argument/config parsing for flare run (progress created at flare-cli/src/main.rs:213, after config resolution). It publishes StartupStage::Other → "other" (startup.rs:51,219), which overwrites the desktop stage indicator (flare/src/controller.rs:1020-1027) and is then cleared immediately (controller.rs:2938).

F8 MAJOR (charter) — evidence. docs/design-review.md:106-115 requires equivalent baselines, complete GPU steps across ranks, actual Helios service measurements, raw measurements and disclosure of unrun checks; charter #210 requires a served-workload speedup. #696 offers phase-level startup timings from one host, self-described as "sequential build measurements, not an isolated A/B for every stage" and "Full test suite was not run", with no CI on the head commit. Startup time is not a served workload. Cited docs docs/FLARE_START.md and docs/FLARE_PATCH_SERIES.md do not exist (docs/ listing) and no docs file is changed; the loading-display contract in docs/cli-design.md:1567-1587 is untouched by the new byte row and the new Startup complete row.

#3 [high] Research summary

Reviewed every changed file in context (reader.rs, model.rs, engram.rs, startup.rs, plus the three call sites) and traced direct callers, the CUDA/Stream path, the O_DIRECT read helper in eos, the merged #625 THP-policy precedent, and the in-tree documentation of the loading display.

Highest-signal findings:

Sound areas: the retained mapping / mprotect / future-seal sequence itself is correct; joins are in group order and bindings.sort_by_key is unchanged, so layout and binding order are preserved; error propagation joins all group threads before returning (no detached loader); Windows and non-Linux Unix keep the old seal-and-remap path; load_segments is untouched; the startup row rendering and Drop ordering are unchanged.

#4 [high] PR 696 areas verified sound (non-findings, must be stated)

All verified at head 24ff7e1 by opening the files. These are deliberate non-findings; the report should say them plainly so the review is not read as uniformly negative.

  1. Retained-mapping mechanism is correct. reader.rs:404-424 does fill → mprotect(PROT_READ) (409) → seal_resident_future (417) → keeps storage; the writable mapping is never unmapped while still writable, and ResidentMapping's Drop (reader.rs:212-216) is the only munmap. Safe.
  2. Ordering/determinism preserved. model.rs:877-917 joins handles in group order and model.rs:918 bindings.sort_by_key(|(local, _, _)| *local) is unchanged; each thread returns (ranks, shared) so the (shared, rank) mapping is identical to the old serial loop. "Final table layout and binding order are unchanged" is TRUE.
  3. No detached-loader / orphan-thread hazard on failure. thread::scope (model.rs:877) joins every spawned thread even when an inner closure returns Err, and the loop at model.rs:908-915 collects errors with ?? only after the scope has all handles; a panic is mapped to invalid("Engram rank loader panicked") (911). Note the difference from NativeModel::parallel (model.rs:1059-1068), which explicitly joins every rank before erroring — #696 achieves the same effect via scope semantics, so no finding.
  4. Platform parity holds. Windows keeps Aligned + the unchanged block at reader.rs:431-438; non-Linux unix keeps drop→seal_resident→from_shared at reader.rs:425-430. open_readonly_view (reader.rs:124-126) and the pre-6.7 /proc/self/fd logic from #590 are untouched, and from_shared still requires matching extent (reader.rs:449-456).
  5. Resident::load_segments (reader.rs:323-362) is unchanged and still publishes sealed segments; the progress plumbing is additive (load delegates with None, reader.rs:272-274).
  6. Startup rendering untouched: State::render, Output::write, bar, truncate (startup.rs:401-517) unchanged; Phase::drop still emits FAILED for unfinished phases and joins the animation worker (startup.rs:362-381); the three progress.complete() call sites sit immediately after phase.finish(...) for "Start server" (flare-cli/src/main.rs:664-668, 736-737; flare/src/controller.rs:2913-2914), i.e. after readiness, and before the signal handlers, so no ordering hazard for shutdown rows.
  7. The new test complete_publishes_the_final_startup_total (startup.rs:566-576) is a real regression test for stage/status/label/detail; it simply does not cover elapsed or the rendered row.
  8. Observation cap respected: StartupObservation::publish (startup.rs:132-146) still truncates label/detail to 512 chars and monotonic sequence, so complete() cannot grow the retained snapshot.

Report framing: findings ordered F1 unbounded fan-out (Major), F2 THP policy (Major), F3 missing resident-size detail (Major), F8 evidence/docs (Major), then F4 stale comment, F5 metric hot-path, F6 untested mprotect, F7 timing base/stage id (Minor). Per-lens focus areas 1-4 each covered: 1 → F4/F6/F7 + sound-points 3/4; 2 → F1/F5/F2; 3 → F8 + F7 stage id; 4 → F3/F6/F8.