Correctness scratchpad · NVIDIA/hyperflare-inference #590

Raw Markdown for agents: https://autobot.eidonix.com/p/8e7de751-2e86-45e8-b9f6-f1aeca00f333.md

#3 [high] Verified OK: prefetch_rows_loaded moved to reader, no double count; lane fan-out has no panic

helios/src/engram/reader.rs:1081-1140 vs :1293-1304 (and helios/src/engram.rs:672-684).

CachedReader::warm now returns a chunked total and adds prefetch_rows_loaded per chunk internally (reader.rs:1133-1136); Reader::warm no longer adds it (the old add in the caller was deleted, diff at :1295-1303). Checked every other reader of that counter:

Also verified DiskReader::gather fan-out (reader.rs:787-796): lane_depth = DEPTH / lanes.len() (128/1,2,4,8 = 128,64,32,16, always nonzero because from_files restricts workers to 1|2|4|8 at :687), active_lanes = div_ceil(lane_depth).min(lanes.len()) — with lane_depth = 64 and 128 reads, div_ceil gives 2, min(2,2)=2; with 8 workers and 128 reads, 8. self.lanes[..active_lanes].split_first_mut() is safe because active_lanes >= 1 whenever reads.len() > lane_depth >= 1, and jobs.next().unwrap() cannot be None because active_lanes <= reads.len() (div_ceil >= 1 and min with lanes.len(); if lanes.len() > reads.len() the chunk = reads.len().div_ceil(active_lanes) > 0). No panic path found.

#4 [high] Verified OK: mailbox bounds and graph-kind filter unification are consistent

helios/src/engram.rs:843-880 (Transfers::new new mailbox lower bounds) and helios/src/runtime_core/engram.rs:245-347 (decode-side validation).

  1. The runtime-side check is nbytes < max_tokens * heads + 1 slots * 8 (engram.rs:848-857) and nbytes < (max_rows + 2) * 8 (:866-874). Both feed address + nbytes - 8 / address + nbytes - 16; since the new checks guarantee nbytes >= 24 for prefetch and >= 16 for request, the subtractions cannot underflow there. Transfers::new is reached only through the core decode path, which already enforces the same shape (check at runtime_core/engram.rs:302-329) and reference.offset + mailbox.nbytes <= allocation.nbytes (:289-296), plus format.rs:325 (offset.checked_add(size) ... <= a.nbytes). So the two layers agree; no ignored-configuration path.

  2. Transfers::new derives required from binding.shared.max_tokens x table.heads, while the core-side check uses max_staged_rows = tokens * core_heads where tokens is the max packed_tokens() over consuming graphs and table_heads becomes core_heads. Shared::new passes the same tokens as max_tokens (model.rs:857-871, engram_tokens computed from the same graph filter at model.rs:478-485). Both filters now use GraphKind::try_from(..).is_ok_and(crate::engram::consumes) — identical to engram::consumes (engram.rs:1011-1021) and to engram/prepared.rs:216,266. So max_tokens * table.heads equals max_staged_rows; no off-by-one or divergence. For compact-headed TP (compact_heads = heads / world, runtime_core/engram.rs:209-241) table_heads = core_heads, and Shared::new gets tokens from the graph scan in model.rs, so heads used in the two places agree.

  3. GraphKind::try_from(...).is_ok_and(consumes) silently drops graphs with an unknown kind string instead of erroring. Previously the hardcoded matches! on g.kind.as_str() also dropped unknown kinds, so no behaviour regression; and manifest parsing rejects unknown kinds elsewhere (GraphKind::try_from at manifest.rs:122-143 is used when the manifest is built, so decode of an unknown kind fails before this filter — runtime_core/serving.rs:58-70 only looks up names). Worth a one-line note, not a finding.

Net: no blocking issue found in the overflow/bounds work.

#5 [high] Research summary

Reviewed all four changed files (helios/src/engram/reader.rs, helios/src/engram.rs, helios/src/runtime_core/engram.rs, ignition/components/ngram_delivery.py) through the correctness lens, following the callers of each changed function and checking the project rules in AGENTS.md, docs/design-review.md and helios/manifest.md / docs/cli-design.md.

No blocking correctness defect found. The four headline fixes hold up in the code:

Two non-blocking findings are recorded: (1) yield_core's nap ladder is cfg(not(windows)), so the #519 wait fix does not apply on Windows (a documented supported platform) — the reader still busy-spins there; the PR's limitation paragraph says Windows was not re-run but does not say the fix is inapplicable. (2) open_readonly_view(...).ok() discards the open error, so on a Linux host without procfs the operator gets the pre-6.7 kernel hint rather than the real reason the reopen failed — diagnostics only.

I did not finish reading ignition/components/ngram_delivery.py's publish_lookahead against the companion recipe path or Helios's AdvisoryMailbox layout invariants before the time limit; the mailbox layout ([cap] ids, count at nbytes-16, sequence at nbytes-8, flag = mailbox.numel()-1) looks consistent with AdvisoryMailbox::snapshot and the Engram equivalent in ignition/components/engram.py, but the recipe-side caller is outside this repository and was not available to verify.

#6 [high] Summary: PR #590 correctness review — scope, findings, no blocking defects

Scope of review (correctness lens) for PR #590, all four changed files:

  1. helios/src/engram/reader.rs (ResidentMapping::new / map_fd / open_readonly_view, DiskReader::gather fan-out, CachedReader::warm chunking, Reader::warm, new tests)
  2. helios/src/engram.rs (WaitBackoff/SPIN_ROUNDS/NAP_GROWTH/NAP_MAX/yield_core, Requests::read, ReaderAction::Warm clamp, ReaderAction::BlockRecv/WaitReady, Transfers::new mailbox bounds, new tests)
  3. helios/src/runtime_core/engram.rs (validate_buffer / validate_mailbox / allocation bounds / GraphKind::try_from(g.kind).is_ok_and(consumes) filters, new tests)
  4. ignition/components/ngram_delivery.py (flare::ple_advisory_requests _advisory_requests, PreparedPLELookup.publish_lookahead)

Rules consulted and cited: AGENTS.md (charter/contribution-scope criteria, "Reject weakened guarantees", "Preserve model core compatibility", env-var prohibition), docs/design-review.md principles 4, 6, 12, 13, helios/manifest.md:465-477 (prefetch_buffer layout contract: 1-D int64 MappedHost, stride [1], 8-byte aligned offset, rank-uniform shape[0], 3 <= shape[0] <= max_staged_rows + 2, ids at base, count at nbytes-16, sequence at nbytes-8), docs/cli-design.md:753, 774-816 (--embedding-table-workers 1|2|4|8, 128 shared I/O slots, prefetch enabled for disk tables with a row cache, cores without prefetch_buffer serve unchanged).

Findings recorded: entry 1 (Nit: Windows keeps the busy spin — yield_core cfg(windows) ignores rounds), entry 2 (Nit: /proc/self/fd reopen error dropped, EPERM hint does not say the reopen failed). Entries 3 and 4 record verified-OK conclusions (prefetch_rows_loaded move, lane fan-out arithmetic, mailbox bounds and graph-kind filter unification) — these should be stated as checked, not as findings.

NO BLOCKING OR SHOULD-FIX CORRECTNESS DEFECT FOUND. Every other checked path held: warm's chunk loop cannot exceed workspace capacity; address + nbytes - 8 / - 16 cannot underflow after the new lower bounds; Reference.offset MappedHost bound now matches format.rs:325 and serving.rs:33-38; resident mapping lifetime (mapping dropped before seal, ResidentMapping::drop munmap) unchanged.

NOT verified before the time limit: the recipe-side caller of PreparedPLELookup.publish_lookahead lives in local-inference-lab/hyperflare-recipes (not in this repo). Within this repo, publish_lookahead mirrors the shipped ignition/components/engram.py:280-283 Engram implementation and its mailbox layout ([cap] ids from base, count at mailbox.numel()-1... i.e. _publish(...marker... mailbox.numel()-1...) with count at FLAG-1) matches AdvisoryMailbox::snapshot (helios/src/engram.rs:254-267) reading count at nbytes-16 and the flag at nbytes-8. Note _advisory_requests allocates ids = torch.empty_like(self.ids) and requests = torch.empty(...) inside the op, so it adds capture-time allocations rather than persistent ones — consistent with the PR's "zero additional persistent GPU VRAM" claim but I did not confirm the allocation-lifetime/steady-state rule (design-review principle 2) beyond that.

#1 [medium] Verified: wait backoff is non-Windows only; Windows keeps busy spin

helios/src/engram.rs:340-352: yield_core nap path is #[cfg(not(windows))]; the #[cfg(windows)] variant ignores the round count and calls std::hint::spin_loop(). Both consumers of WaitBackoff (Requests::read, helios/src/engram.rs:310-316, and ReaderAction::WaitReady, :685-687) therefore still busy-spin for the whole wait on Windows, so the defect #519 describes (a permanently-waiting reader burning a core) remains there. The rationale in the doc comment (:334-339) is Windows timer granularity vs NAP_MAX=250us. Windows is a documented supported platform (docs/windows.md, helios README, and DiskReader has a windows::Readers lane implementation at reader.rs:699-700, so disk tables and their reader threads do run there). The PR's own Limitations paragraph discloses "Windows builds ... were not re-run", which is honest but understates that the fix is inapplicable rather than merely unverified. Severity: nit/should-fix at most — behaviour is unchanged from main on Windows, so this is an incomplete fix rather than a regression. Fix if desired: use std::thread::yield_now() (or a Sleep(0)-equivalent) after the spin budget on Windows instead of a pure spin, and say in the comment/docs that the nap ladder is POSIX-only.

#2 [low] Verified: /proc/self/fd reopen failure is silent; only an EPERM hint remains

helios/src/engram/reader.rs:108-159. Self::open_readonly_view(file).ok() (line 140) discards the open error, and the fallback is file.as_raw_fd() (line 147). On a Linux host where procfs is not mounted or /proc/self/fd is inaccessible (containers with a hidden procfs, hardened mounts), the mmap then fails exactly as on main, and the error text at :152-158 only says "kernels older than 6.7 require /proc/self/fd ..." without reporting why the reopen was unavailable, so the operator cannot distinguish "old kernel, procfs fine" from "no procfs at all". This is diagnostics only: the fix works on every normal Linux configuration, and the fallback can't do better (issue #481). Fix: keep the io::Error from open_readonly_view and include it in the EPERM message (e.g. ... (read-only reopen failed: {error})).