Simplicity review — PR #590 helios,ignition: fix Engram reader bugs and add PLE lookahead publish
Lens D (simplicity: what can be deleted). Reviewed at head 6fe7bed (base main a54a8b8; 5 files, +464/−103). The PR is now merged and CI passed on the head commit; there were no human reviews. Rules applied: AGENTS.md:188-199 (reject "framework, extension points, speculative compatibility, fallback layers"; refactoring must support behaviour; "tests must exercise the affected behavior or contract"; one coherent outcome per PR) and docs/design-review.md:16-35 ("Keep Helios as simple as possible").
Key findings
The change is mechanically sound and two of its strands genuinely remove code (GraphKind::try_from(..).is_ok_and(crate::engram::consumes), and the shared lane_fanout planner). But two of the five strands add code that cannot execute or proves nothing, and three added paths duplicate checks their own callers or siblings already make. Roughly 40–60 of the added lines can go without losing a tested behaviour. No blockers; two should-fix items and five nits.
Should fix
S1. Transfers::new re-proves mailbox capacities the same PR already validates — deletable
helios/src/engram.rs:780-819 (request :785-794, prefetch :803-811).
Transfers::new recomputes required = (max_tokens * heads + 1) * 8 for the request mailbox and (max_rows + 2) * 8 for the prefetch mailbox, then errors if nbytes < required. Every input of that arithmetic is already established upstream by the same PR:
runtime_core/engram.rs:302-311enforces requestshape[0] >= max_staged_rows + 1, and:287enforcesshape[0].checked_mul(8) == Some(nbytes), sonbytes >= (max_staged_rows + 1) * 8.:313-329enforces prefetchshape[0] ∈ [3, max_staged_rows + 2], then setsprefetch_max_rows = shape[0] - 2— i.e. themax_rowsconsumed atengram.rs:816is derived fromnbytes, makingnbytes < (max_rows + 2) * 8arithmetically impossible.table.heads == core_headsis checked at:241, andShared::max_tokensis the group-max graph token count (model.rs:478-485,:857-863) — the same quantity asmax_staged_rows.Transfers::newhas exactly one caller (transport.rs:713), andmanifest.engramis only ever set atmodel.rs:1040.
So the block's only unique content is a cross-check between a group-max token count and a single rank's manifest capacity. That belongs once where Shared is built (model.rs:857), or as a debug_assert_eq!. Roughly 20–30 added lines go.
S2. Chunked CachedReader::warm fixes a case no caller can reach, and contradicts gather
helios/src/engram/reader.rs:1097-1156 (for chunk in ids.chunks(self.max_rows), total_loaded, Ok(total_loaded)), test at :2190-2234.
The PR description justifies this by "direct Reader::warm callers passing more than max_rows IDs". At head there are none:
Readerispub(crate)(reader.rs:1203) andwarmhas a single non-test caller,engram.rs:616-618.- That caller passes
&pending_warm[warm_cursor..end]whereend = (warm_cursor + warm_batch).min(pending_warm.len())(:614), withwarm_batch = WARM_BATCH_ROWS.min(max_tokens * table.heads).max(1)(:552-554) — the samemax_tokens * table.headsthat isCachedReader::max_rows(engram.rs:484-492→reader.rs:1213-1217). pending_warmis additionally length-clamped bymailbox.snapshotto the prefetchmax_rows(engram.rs:263,:607).- The return value is discarded:
let _ = std::panic::catch_unwind(..)at:616.
Meanwhile CachedReader::gather still rejects the same over-capacity input (reader.rs:1017-1020, ids.len() > max_rows ⇒ Err), so warm now tolerates what gather refuses — two policies for one workspace. The smaller version keeps the caller's clamp, restores a single-pass body, returns Result<()>, and deletes device_request_wait…-style chunk test at :2190-2234. If the intent is genuinely to make direct callers safe, the one-line fix is the same Err gather uses, not a loop.
Nits
Requests::readkeeps a spin loop that only a cancellation race can enter —helios/src/engram.rs:298-318, test:1016-1036. The only caller isengram.rs:595, reached only after the worker'sstopcheck at:592-594and only whennext_reader_actionreturnedGather, which already requiresjob.requests.is_ready(cancelled)(:346-351, the identicalflag == sequencetest at:286-289). The loop can therefore leave only throughcancelled, i.e. a stop flag flipped between two loads. Smaller: checkcancelledonce and read, ordebug_assert!(ready.load(..) == sequence)plus an unconditional read; the dedicated test then tests nothing production runs.- The read-only reopen falls back to the descriptor that fails on pre-6.7 kernels —
helios/src/engram/reader.rs:153-181.readonly_view.as_ref().map_or(file.as_raw_fd(), |ro| ro.as_raw_fd())(:163-165) maps the originalO_RDWRfd when/proc/self/fdreopen fails — the exactVM_MAYWRITEcondition the PR exists to avoid (#481) — and only the error string says so (:172-179, three message variants).AGENTS.md:188-199rejects fallback layers. One path (reopen, map, append the reopen error if any) also deletes themap_fdwrapper (:128-144) and the#[cfg(not(target_os = "linux"))]shadow (:166-167) by inlining the singlelibc::mmap. - A second PLE hash+publish custom op where the first already exists —
ignition/components/ngram_delivery.py:78-95repeats:59-75line for line exceptlive_rows/HAS_LIMIT. The module already parameterises exactly this:_copy_requests/_publishtake theHAS_LIMITflag (:68-69vs:88-89) andpublish_advisory_requestsexists at:47-56; the sibling component does hash-then-publish as two ops (ignition/components/engram.py:280-283). One op with an optionallive_rows(or hash-only op + the existing publish op) removes ~20 lines of duplicated signature, fake registration and call site. Secondary:publish_lookahead(:157-164) allocatesids/requestson every call, soPreparedPLELookupreuses onlyplan. - The fan-out integration test recomputes the planner's formula —
helios/src/engram/reader.rs:2315-2320recomputesDEPTH / workersand80.div_ceil(lane_depth).min(workers), which the table testlane_fanout_scales_workers_from_per_lane_depth(:2236-2248) already pins exactly. Assertused_lanes > 1(and== workersfor the 80-read/8-worker case) — the property the integration test is uniquely able to prove — and drop the arithmetic. - Restated allocation bound —
helios/src/runtime_core/engram.rs:289-296re-checksreference.offset + nbytes <= allocation.nbytesfor every buffer, whichserving.rs:30-38already enforces on these same buffers. Keep only theMemory::MappedHostrequirement that is unique here.
Verified positives (keep)
runtime_core/engram.rs:224and:333replace two hardcoded kind lists with oneGraphKind::try_from(g.kind.as_str()).is_ok_and(crate::engram::consumes)— genuine de-duplication, and it is what alignsscored_prefillwithengram::consumes(the fix cannot drift again).lane_fanout(reader.rs:37-50) is the right shape: shared by UnixDiskReader::gather(:810-841) and WindowsReaders::gather(reader/windows.rs:91-117), returnsOptionsoSomealways implies ≥ 2 lanes, and itsDEPTH / lanesmatchesDiskReader::from_files(:691-696). Do not try to merge the two gather bodies: the outputs are different types (UnixOutputvsOutput) and unifying them needs a trait larger than the duplication.warm_batchatengram.rs:552-554removes the previous reliance onWARM_BATCH_ROWSexceeding staging capacity, andprefetch_rows_loadednow has one increment site (reader.rs:1149-1152) with no double count.
Findings from earlier in the review that are now resolved (not repeated)
The author already deleted the local WaitBackoff in Requests::read (no hits at head; :298-318 now spins inline), which resolved two earlier findings (second wait policy; a test that could not distinguish napping from spinning). The redundant fan-out if/else is gone now that lane_fanout owns the guard. Ragged comments I flagged earlier (engram.rs:570, :573-574, :610) are pre-existing or unchanged, so they are not this PR's comment bloat and are not reported.
Open question
PreparedPLELookup.publish_lookahead (ngram_delivery.py:157-164) is the only capability addition among four defect fixes, and it carries a cross-repo merge order (this PR before the recipe uv.lock bump). AGENTS.md:198 ("keep each PR focused on one coherent outcome") and docs/design-review.md:22-25 argue for splitting it; as a reviewer question, not a finding, the bug fixes would be revertable independently.
What I could not settle from code, and limitations
- S2's "unreachable in production" is an argument from visibility (
Readerpub(crate)atreader.rs:1203) plus the single call site; a future caller passing unclamped ids would make the chunk loop load-bearing — which is why the cheaper fix is one clamp or oneErr, not the loop. - S1's unique cross-check could only matter if two ranks sharing an Index prepared different engram
packed_token_capacity; existingruntime_corefixtures do not build that case, so S1 is argued frommodel.rs:448-485rather than from a failing test. - Nit 1's "the loop never iterates" is a two-load race argument (
engram.rs:592-595vs:346-351); only an instrumented run, or replacing the loop, proves it. - I did not run
cargoorpytest; every finding above is from reading the code at head6fe7bed.