Simplicity review (lens D) — PR #590 helios,ignition: fix Engram reader bugs and add PLE lookahead publish
Head 4ea9ba0, base main a54a8b8, 4 files, +588/−112. Rules applied: AGENTS.md:188-198 ("Reject unsupported abstractions and churn… no frameworks, extension points, speculative compatibility, fallback layers"; "Require focused, meaningful validation. Tests must exercise the affected behavior or contract"; "Keep each PR focused on one coherent outcome") and docs/design-review.md:16 ("Keep Helios as simple as possible").
Key findings
The change is mechanically sound, and some parts genuinely remove code (the shared GraphKind::try_from(...).is_ok_and(crate::engram::consumes) filter and the active_lanes arithmetic are real simplifications). But two of the five fix strands are unreachable or unverified in production, and three added paths re-check what their own caller already guarantees — roughly 60–80 of the added lines could go without losing a tested behaviour.
- Should fix (2): a second, unreachable wait policy in
Requests::readwhose only existence is explained by three of the four new tests; and a new test that cannot tell napping from spinning. - Should fix (scope, 1): chunked
CachedReader::warmfixes a case the serving caller's clamp makes unreachable, and now contradictsgather's own rejection. - Nits (5): duplicated mailbox capacity arithmetic, the
/proc/self/fdfallback that silently restores the failing descriptor, the redundant fan-out guard, the duplicated PLE advisory op, and three comments that restate docs or state unenforced invariants.
No blocking issues in this lens: nothing here causes a wrong result or a missed contract; the concerns are that dead/duplicated paths will drift.
Should fix
F1. Requests::read keeps a second, unreachable wait policy — helios/src/engram.rs:299-320
The device arm spins/naps on the ready flag with its own backoff (let mut wait = WaitBackoff::new() at :310, loop :311-316). Its only production caller is :654 (job.requests.read(&stop)?; a search for .read( in the file shows only :654, plus the two tests at :1100/:1135/:1167). That call site is reached only from ReaderAction::Gather, which next_reader_action returns only when job.requests.is_ready(cancelled) (:401-406) — the identical ready == sequence test in is_ready (:293-296). So in serving the loop body never runs, and what remains is a second backoff policy with different semantics (fresh counter per call, no reset) beside the reader loop's wait that is reset on Gather/Warm/BlockRecv (:618, :627, :673, :689).
Why it matters: two policies for one wait invite drift, and the code is what the new tests exist to cover (three of the four new Requests tests — :1094-1140 — only exercise this loop).
Smaller version: fn read(self) -> Result<Vec<i64>> that assumes readiness (or debug_assert!(self.is_ready(...)) before it), delete wait, delete the cancelled parameter and the three tests at :1094-1140. The reader loop's cancel check at :651 already covers the serving case.
F2. The new test cannot distinguish napping from spinning — helios/src/engram.rs:1142-1182, assertion :1177-1180
wait_ready_backoff_naps_until_publication_or_cancellation_and_resets counts rounds of next_reader_action and asserts rounds.0 > SPIN_ROUNDS. A WaitBackoff::step that only spun (spins += 1, yield_core deleted entirely) passes: it exceeds 4096 rounds inside the test's 5 ms AFTER_SPIN sleep (:1092) with room to spare. Nothing observes that the thread slept, and nothing re-arms a new spin window after the nap, which is the only behaviour the fix adds. AGENTS.md:194 requires tests to exercise the affected behaviour.
Fix: assert wall time — capture Instant when rounds first reaches SPIN_ROUNDS and the Instant at publication, and require the gap to exceed the spin window by a margin; or delete this test and keep :1106-1116 and :1129-1140, which at least run in the nap phase.
F3. Chunked warm fixes an unreachable case, and contradicts gather — helios/src/engram/reader.rs:1081-1140
for chunk in ids.chunks(self.max_rows) (:1085) replaces &ids[..ids.len().min(self.max_rows)]. The only serving caller already clamps: helios/src/engram.rs:607-609 computes warm_batch = WARM_BATCH_ROWS.min(max_tokens.saturating_mul(table.heads)).max(1), and max_rows is constructed from the same max_tokens.checked_mul(table.heads) (engram.rs:539-541). So warm can never receive more than max_rows ids in production, and the truncation the PR removes never dropped a row there — the defect exists only for direct Reader::warm callers. Meanwhile CachedReader::gather still rejects ids.len() > self.max_rows (reader.rs:1001-1004), so warm now tolerates exactly what gather refuses; two entry points, two overflow policies.
Smaller version: keep one clamp — the caller's — and restore the single-pass body; then drop the accumulated total_loaded and the usize return of Reader::warm (reader.rs:1293-1304), whose value is discarded at engram.rs:676-678 (let _ = std::panic::catch_unwind(...)), returning Result<()>. That is ~10 lines net smaller and leaves one policy. If the author wants warm safe for arbitrary callers, the cheaper fix is a single if ids.len() > self.max_rows { return Err(...) } matching gather, not chunking plus per-chunk statistics.
Nits
F4. Duplicated mailbox capacity validation — helios/src/engram.rs:848-857 and :866-874
Transfers::new recomputes max_tokens*heads + 1 slots for the request mailbox and max_rows + 2 for the prefetch mailbox and compares with nbytes. helios/src/runtime_core/engram.rs:272-329, added by the same PR, already validates both mailboxes: shape[0].checked_mul(8) == nbytes (:287), reference.offset.checked_add(mailbox.nbytes) <= allocation.nbytes against a MappedHost allocation (:289-296), the request mailbox minimum max_staged_rows + 1 (:303-311), and the prefetch maximum max_staged_rows + 2 and shape[0] == len (:313-329), so prefetch.max_rows is already the validated len - 2 (:323-328). Smaller version: rely on that bound and keep a debug_assert! (or nothing) here; the checked_mul/checked_add chain is ~20 added lines proving a value two layers up already proved. Note the two are not perfectly equal today (tokens*core_heads vs max_tokens*heads), which is itself the drift risk.
F5. The read-only reopen silently falls back to the failing descriptor — helios/src/engram/reader.rs:138-149
Self::open_readonly_view(file).ok() then .map_or(file.as_raw_fd(), |ro| ro.as_raw_fd()): if procfs is unavailable the mapping silently uses the original O_RDWR fd — precisely the condition that returns EPERM on kernels < 6.7, the defect this PR fixes — and only the error string at :151-159 mentions it. AGENTS.md:188-189 rejects fallback layers and speculative compatibility. Smaller version: one path — reopen when !writable and surface the reopen error; this also deletes map_fd (:113-129) and the #[cfg(not(target_os = "linux"))] shadow (:148-149) by inlining the single libc::mmap call.
F6. Redundant fan-out guard — helios/src/engram/reader.rs:787-796
Both the self.lanes.len() == 1 || self.reads.len() <= lane_depth branch (:788) and the else compute active_lanes = reads.len().div_ceil(lane_depth).min(lanes.len()), which equals 1 exactly under the guard. Deleting the guard and always taking the scoped path keeps behaviour identical (one lane, one spawn-free local gather) and removes ~8 lines and a branch that has to be reasoned about twice.
F7. Duplicated PLE advisory custom-op — ignition/components/ngram_delivery.py:78-95
_advisory_requests repeats _requests (:59-75) line for line except the live_rows argument and the HAS_LIMIT flag — the same hash-plan call, fake registration and mailbox tail. The module already parameterises exactly this in publish_requests / publish_advisory_requests (:36-56) via HAS_LIMIT/HAS_COUNT constexprs, so the pattern to follow exists two screens up. Smaller version: one op taking an optional live_rows (default None, passed as the mailbox and HAS_LIMIT=False), removing ~20 lines of near-identical signature, registration and call site. Secondary: publish_lookahead (:157-164) allocates ids and requests on every call, so the docstring's "reusing the prepared ... plan" is the only reuse — not a defect, but the docstring implies more.
F8. Comments that restate docs or assert unenforced invariants
helios/src/engram.rs:610-611("One worker serves every rank whose rows this table holds; a rank-partitioned table becomes a separateShared…") restatesdocs/same-process-tp.md:63-64(not opened) above untouched spawn code; per the prose skill, state the invariant where it is enforced or leave the doc to say it.helios/src/engram.rs:328-332: "under one decode step so that a nap delays the published IDs by no more than its own length" is true only while a decode step outlasts 250 µs, and nothing detects the contrary.helios/src/engram/reader.rs:151-159embeds a kernel-version hint inside a runtime error string; it belongs in the issue/doc that the message can point at.
Verified positives (worth keeping)
helios/src/runtime_core/engram.rs:224and:333replace two hardcoded five-kind match lists with the sharedGraphKind::try_from(g.kind.as_str()).is_ok_and(crate::engram::consumes)— genuine de-duplication, and the fix that removes thescored_prefilldivergence permanently.helios/src/engram/reader.rs:787-825fan-out arithmetic is correct:lane_depth = DEPTH / lanes.len()matchesDiskReader::from_files;active_lanesnever exceeds the lane count;chunks(chunk)withchunk = reads.len().div_ceil(active_lanes)handssplit_first_mut's first chunk plushelpers.len() == active_lanes - 1jobs, soself.lanes[..active_lanes]bounds the split. (Only the guard above it is redundant, F6.)CachedReader::warm's per-chunk statistics add up: oneinsert_advisoryper unique miss,added/evictedsummed over chunks,prefetch_rows_loadedincremented per chunk — the accounting is right even though the chunking is unneeded (F3).
Open question
Whether the PLE publish_lookahead capability (ignition/components/ngram_delivery.py:157-164) belongs in this PR at all: it is the only capability addition among four defect fixes, carries a stated cross-repo merge-order dependency, and AGENTS.md:198 asks for one coherent outcome per PR. Splitting it would also let F7 be resolved in its own review.
What could not be established from the code
- F2 is a test-strength claim about wall-clock behaviour; only a measurement (or the suggested timing assertion) settles whether the current nap path ever sleeps in practice.
- F3's "unreachable in production" rests on the single caller at
engram.rs:607-609; if a recipe or future caller invokesReader::warmwith an unclamped id list, the chunking is load-bearing — the fix there is the one-line clamp, not the chunk loop. - Per instruction I did not re-run
cargo test; all findings are from reading the code at head4ea9ba0.