Correctness report · NVIDIA/hyperflare-inference #590

Raw Markdown for agents: https://autobot.eidonix.com/p/6cdb0f85-c079-45d4-a5ba-f55e87a2330f.md

PR #590 — helios,ignition: fix Engram reader bugs and add PLE lookahead publish

Correctness review at head 6fe7bed2 (merged; CI passed; 5 files, +464/−103). All four changed files were read in context with their callers, plus the core-side validation they must agree with.

Key findings

Verdict: clean. No blocking, no should-fix, no nit findings.

Every changed path holds up: the lane fan-out planner has no panic or over-capacity path, chunked CachedReader::warm cannot exceed its deliberately sized workspace and does not double-count or leak cache pins, the WARM_BATCH_ROWS clamp keeps every ReaderAction::Warm inside pending_warm, the new Transfers::new mailbox lower bounds make the address + nbytes - 8 / - 16 arithmetic unreachable-by-underflow for any manifest the core accepts, validate_mailbox's checked arithmetic and MappedHost allocation bound are consistent with engram::consumes and the scored_prefill filter unification, the resident read-only remap changes no mapping lifetime, and PreparedPLELookup.publish_lookahead publishes a mailbox layout that matches what Helios reads.

The two nits recorded in the previous pass are both resolved by this head and are deliberately not repeated below: WaitBackoff/SPIN_ROUNDS/NAP_MAX/yield_core no longer exist in the tree (search_code returns no matches; Requests::read keeps only its bounded std::hint::spin_loop() loop at helios/src/engram.rs:309-314, identical to main), and the /proc/self/fd reopen error is now carried into the EPERM diagnostic (helios/src/engram/reader.rs:169-182).

What was verified

1. Lane fan-out (both platforms)

lane_fanout(reads, lanes) (helios/src/engram/reader.rs:37-50) is called by Unix DiskReader::gather (reader.rs:810-841, replacing the old reads.len() <= DEPTH → lanes[0] dispatch) and by Windows Readers::gather (helios/src/engram/reader/windows.rs:91-93).

No panic path:

The fix does what it claims: 17–128 reads on 2/4/8 workers now spread across ceil(reads/lane_depth) lanes instead of collapsing onto lane 0. Unit tests cover the planner at 1/2/4/8 workers and assert an end-to-end Unix fan-out for 80 reads by counting which lanes actually executed I/O (reader.rs:2245-2300).

2. Chunked CachedReader::warm and the stats move

CachedReader::warm (reader.rs:1097-1156) now iterates ids.chunks(self.max_rows); each chunk clears and refills miss_ids, sorts/dedups, pins hits, gathers misses into miss_output[..count * (weights + scales)], and inserts. Workspace vectors are allocated with exactly max_rows entries (reader.rs:954-1015) and CachedReader::gather still rejects ids.len() > max_rows (reader.rs:1018-1020), so the per-chunk bound is the same capacity the reader was sized with — no overrun for any input length.

prefetch_rows_loaded is now incremented once per completed chunk inside the reader (reader.rs:1149-1153) and the old fetch_add in Reader::warm was deleted (reader.rs:1309-1320), so there is no double count. The only production caller is helios/src/engram.rs:677, inside a catch_unwind that discards the returned count; the tests assert exact totals, so the semantic shift (per-call rows → rows across all chunks) matches the metric's help text.

Duplicate IDs spread across chunks are harmless: RowCache::pin_if_present (helios/src/engram/cache.rs:163-170) and insert_advisory (cache.rs:193-214) set a PINNED bit on the entry rather than incrementing a counter, so a second touch in a later chunk cannot accumulate pin state that would need releasing.

3. ReaderAction::Warm clamp

warm_batch = WARM_BATCH_ROWS.min(max_tokens.saturating_mul(table.heads)).max(1) (helios/src/engram.rs:552-554), used for end at :614. pending_warm is capped at AdvisoryMailbox::snapshot's max_rows (engram.rs:244-267), which is the same max_tokens * heads the reader was sized with (engram.rs:484-496), so end <= pending_warm.len() and every Warm stays inside one workspace chunk. .max(1) prevents a zero-stride dead loop, and max_tokens == 0 is already rejected (engram.rs:521). On the no-prefetch path pending_warm stays empty and Warm is never selected (engram.rs:352-354, :565).

4. Mailbox bounds and overflow

Transfers::new verifies a checked minimum byte length before computing the flag/count addresses:

validate_mailbox now uses checked_mul(8) / checked_add and enforces reference.offset.checked_add(mailbox.nbytes) <= a.nbytes against the named MappedHost region (runtime_core/engram.rs:272-301), so a wrapped shape[0] such as (1 << 61) + 1 or 1 << 61 is rejected in release builds instead of reaching Transfers::new or Requests::read. validate_buffer's expected_nbytes chain (runtime_core/engram.rs:245-259) is unchanged and consistent.

5. scored_prefill filter unification

Both graph-kind filters now use GraphKind::try_from(..).is_ok_and(crate::engram::consumes) (runtime_core/engram.rs:221-227 and :330-347), matching engram::consumes (helios/src/engram.rs:948-958). Unknown kind strings are still dropped as before, and manifests reject unknown kinds at parse time (helios/src/core/execution/manifest.rs:122-143 (not opened)).

6. Resident read-only remap (pre-6.7 EPERM, #481)

ResidentMapping::new (reader.rs:108-199): map_fd keeps MAP_SHARED and only factors out the mmap call; on Linux with !writable it reopens /proc/self/fd/<fd> read-only (reader.rs:124-126) for the mapping, falls back to file.as_raw_fd() if procfs is unavailable, and preserves the reopen error alongside a pre-6.7 hint when mmap returns EPERM (reader.rs:169-182). Non-Linux unix keeps the old behaviour via #[cfg(not(target_os = "linux"))]. MADV_POPULATE_READ still applies only to !writable; munmap stays in Drop (reader.rs:202-207); the mapping is still dropped before seal_resident (reader.rs:357-362), so sealing order and mapping lifetime are unchanged. The writable path is untouched.

7. Ignition PLE lookahead

PreparedPLELookup.publish_lookahead(ids, count, step) (ignition/components/ngram_delivery.py:157-164) calls flare::ple_advisory_requests (ngram_delivery.py:78-95), which reuses the prepared ple_embedding plan and publishes with _copy_requests(..., HAS_LIMIT=True) and _publish(..., HAS_COUNT=True) at mailbox.numel()-1 (ngram_delivery.py:18-33): ids from base, count at numel()-2, flag at numel()-1. That is exactly what AdvisoryMailbox::snapshot reads (count at nbytes-16, flag at nbytes-8, helios/src/engram.rs:244-267) and mirrors the shipped Engram path (ignition/components/engram.py:280-283); the layout is documented at helios/manifest.md:465-477 (not opened). Like publish, it needs a non-functional() instance because it reads self.ids (ngram_delivery.py:141-155) — no new constraint. The ids/requests tensors are allocated inside the op at capture time, not persistent VRAM.

Rules cited

Open questions and what could not be verified

  1. Recipe-side caller. The only production user of PreparedPLELookup.publish_lookahead is the companion change in local-inference-lab/hyperflare-recipes#87, which is not in this repository. Only this side of the handshake (buffer layout, sequence flag, count slot) could be verified. Settled by running the paired recipe against the merged core.
  2. Pre-6.7 kernel behaviour. The EPERM path was validated by the author on Linux 6.18 via F_GETFL == O_RDONLY and mprotect(PROT_READ|PROT_WRITE) → EACCES (the test at reader.rs:2330-2360), not on a kernel older than 6.7. Only booting on such a kernel with --embedding-table-storage ram settles it.
  3. Windows ring fan-out execution. Windows now shares the unit-tested lane_fanout planner, but the Windows I/O-ring path itself was not executed on a Windows host here; only the planner is covered by tests.
  4. The paired benchmark does not exercise these fixes. The measured Qwen3.8 run used --embedding-table-workers 1, which bypasses multi-worker fan-out, so the fan-out, EPERM and overflow fixes rest on unit tests rather than on the served measurement — consistent with the PR body's own limitations section.