Correctness scratchpad · NVIDIA/hyperflare-inference #590

Raw Markdown for agents: https://autobot.eidonix.com/p/222725a1-5c6d-4b88-bf2c-bcd57026bb3a.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.

#8 [high] Report addendum: new commit 6fe7bed resolves both prior nits; new bounds checks consistent

PR #590, head 6fe7bed2 (helios,ignition: fix Engram reader bugs and add PLE lookahead publish).

Second pass — both nits from the previous report are resolved by this commit, and the two new changes hold up:

  1. Nit 1 (Windows busy spin) is moot: WaitBackoff/SPIN_ROUNDS/NAP_MAX/yield_core no longer exist in the tree (search_code for WaitBackoff|SPIN_ROUNDS|yield_core|NAP_MAX → no matches). Requests::read keeps its bounded std::hint::spin_loop() loop (helios/src/engram.rs:309-314) and ReaderAction::WaitReady its single spin_loop (:625-627), i.e. exact main behaviour, so nothing regressed.
  2. Nit 2 (/proc/self/fd error) is fixed: ResidentMapping::new now threads the reopen error into the EPERM message (reader.rs:146-182), including the "reopen failed: {reopen}" branch.

New code checked:

Not verified (unchanged): the recipe-side caller of PreparedPLELookup.publish_lookahead (local-inference-lab/hyperflare-recipes); real pre-6.7 kernel behaviour (author tested 6.18 via F_GETFL/mprotect); Windows ring execution (Windows now shares the unit-tested lane_fanout planner, reader/windows.rs:91, but the fan-out path itself was not executed on Windows).

Verdict: clean — no blocking, no should-fix.

#9 [high] Research summary

Correctness review of PR #590 at head 6fe7bed2 (superseding the earlier pass): verdict clean — no blocking, no should-fix findings. Both nits from the previous report are resolved by this commit (WaitBackoff is gone entirely, so the Windows busy-spin nit is moot; the /proc/self/fd reopen error is now carried into the EPERM diagnostic).

The commit's two new changes were checked in context: the warm_batch = WARM_BATCH_ROWS.min(max_tokens*heads).max(1) clamp keeps every ReaderAction::Warm slice inside pending_warm, which AdvisoryMailbox::snapshot already caps at the same max_rows the reader workspace uses, and .max(1) rules out a zero stride; the new Transfers::new mailbox lower bounds agree exactly with the core-side decode validation ((max_tokens*heads + 1)*8 for requests, (max_rows + 2)*8 for prefetch, where the core derives max_rows = shape[0] - 2), so address + nbytes - 8 / - 16 cannot underflow for any manifest the core accepts. The four headline fixes from the PR body (lane fan-out, chunked warm, pre-6.7 read-only remap, mailbox overflow/allocation bounds, scored_prefill filter unification) all hold, as does PreparedPLELookup.publish_lookahead's mailbox layout and sequence handshake against AdvisoryMailbox::snapshot.

Left unverified, and stated as such: the recipe-side caller in local-inference-lab/hyperflare-recipes, real pre-6.7 kernel behaviour (validated on 6.18 via F_GETFL/mprotect), and the Windows fan-out path, which now shares the unit-tested lane_fanout planner but was not executed on Windows. Details in scratchpad entries 8 (this pass) and 3/4/6 (earlier verified-OK paths).

#10 [high] FINAL REPORT to write for PR #590 (head 6fe7bed2) — supersedes entry #7

PR #590 "helios,ignition: fix Engram reader bugs and add PLE lookahead publish", head 6fe7bed2 (merged, CI passed, 5 files +464/−103). Correctness lens only.

IMPORTANT: entry #7 is the report for the previous head and is OBSOLETE. Its two nits are both resolved by 6fe7bed2 and must not be repeated:

Verdict

Clean. No blocking, no should-fix, no nit findings. State this plainly.

What was verified (all four changed files read in context)

  1. Lane fan-out — shared lane_fanout(reads, lanes) (reader.rs:37-50) used by Unix DiskReader::gather (reader.rs:810-841) and Windows Readers::gather (reader/windows.rs:91-93). No panic path: lane_depth = DEPTH/lanes = 128/64/32/16 is never zero because from_files and Readers::new restrict workers to 1|2|4|8 (reader.rs:709-712, windows.rs:53-56); active_lanes >= 1 whenever reads > lane_depth; self.lanes[..active_lanes].split_first_mut().unwrap() and jobs.next().unwrap() are therefore both safe, and the chunk size is nonzero. Fixes the 4x–8x queue-depth collapse on 17–128 reads. Unit-tested per worker count, including a Unix end-to-end 80-read assertion on which lanes actually executed (reader.rs:2245-2300).
  2. Chunked CachedReader::warm — reader.rs:1097-1156 iterates ids.chunks(self.max_rows), so miss_ids/miss_output can never exceed the deliberately sized workspace (reader.rs:954-1015); prefetch_rows_loaded is now incremented once per completed chunk in the reader (:1149-1153) and the old add in Reader::warm was deleted (reader.rs:1309-1320), so there is no double count. Only production caller is helios/src/engram.rs:677 inside a catch_unwind that discards the count; the tests assert exact totals, so the semantics change (per-call rows -> rows across all chunks) matches the metric's help text.
  3. warm_batch clamp — helios/src/engram.rs:552-554, used at :614. pending_warm is capped by AdvisoryMailbox::snapshot's max_rows (:244-267), which is the same max_tokens*heads the reader was sized with (Reader::from_files at engram.rs:484-496), so end <= pending_warm.len() and each Warm stays inside one workspace chunk. .max(1) prevents a zero-stride dead loop; max_tokens == 0 is already rejected (:521). On the no-prefetch path pending_warm stays empty and Warm is never selected (:352-354, :565).
  4. Transfers::new mailbox lower bounds — request mailbox required = (max_tokens*heads + 1)*8 via checked ops (engram.rs:780-797) vs core decode requiring shape[0] >= tokens*core_heads + 1 (runtime_core/engram.rs:302-311) with max_tokens derived by the same GraphKind filter (runtime_core/model.rs:478-485) and table_heads == heads (runtime_core/engram.rs:238-241); prefetch required = (max_rows + 2)*8 (engram.rs:798-817) where the core sets max_rows = shape[0] - 2 (runtime_core/engram.rs:313-328), so required == nbytes exactly and address + nbytes - 8/- 16 cannot underflow, with count and flag in distinct slots because shape[0] >= 3.
  5. Core-side validation — validate_buffer's expected_nbytes chain (runtime_core/engram.rs:245-259), validate_mailbox's checked_mul(8) plus the new reference.offset.checked_add(mailbox.nbytes) <= a.nbytes MappedHost bound (:272-301), and the two GraphKind::try_from(..).is_ok_and(crate::engram::consumes) filters (:221-227, :330-347) now match engram::consumes (helios/src/engram.rs:948-958), which is what fixes the scored_prefill omission. Unknown kind strings are still dropped, as before, and manifests reject unknown kinds at parse time (execution/manifest.rs:122-143).
  6. Resident read-only remap — map_fd (:128-144), MAP_SHARED unchanged, read-only /proc/self/fd reopen with fallback to the original fd, madvise(MADV_POPULATE_READ) still only for !writable, munmap in Drop (:202-207), mapping dropped before seal_resident (:357-362) — lifetime unchanged. Linux-only code; non-Linux unix keeps the old behaviour via #[cfg(not(target_os = "linux"))].
  7. Ignition — PreparedPLELookup.publish_lookahead (ignition/components/ngram_delivery.py:157-164) plus flare::ple_advisory_requests (:78-95) reuse the prepared ple_embedding plan and publish with _copy_requests(..., HAS_LIMIT=True) and _publish(..., HAS_COUNT=True) at mailbox.numel()-1 (:18-33), i.e. ids from base, count at numel()-2, flag at numel()-1 — matching AdvisoryMailbox::snapshot reading count at nbytes-16 and flag at nbytes-8 (helios/src/engram.rs:244-267) and mirroring the shipped Engram path (ignition/components/engram.py:280-283). It reads self.ids, so like publish it requires a non-functional() instance (:141-146, :148-155) — no new constraint. ids/requests are capture-time allocations inside the op, not persistent VRAM.

Limitations to state (not findings)

Rules cited

AGENTS.md (contribution scope, "reject weakened guarantees", preserve model core compatibility); docs/design-review.md principles 4, 6, 12, 13; helios/manifest.md:465-477 (prefetch_buffer layout: 1-D int64 MappedHost, stride [1], 8-byte aligned offset, ids at base, count at nbytes-16, sequence at nbytes-8, 3 <= shape[0] <= max_staged_rows + 2); docs/cli-design.md:753, 774-816 (--embedding-table-workers 1|2|4|8, 128 shared I/O slots, cores without prefetch_buffer serve unchanged); docs/windows.md (Windows is a supported platform).

#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})).