#1 [high] WIP: simplicity findings for PR #590
PR 590, head 4ea9ba0, lens D (simplicity). Candidates so far:
- helios/src/engram.rs:299-320 Requests::read keeps a full wait loop + local WaitBackoff that is unreachable in production (only call site engram.rs:654 after next_reader_action returned Gather, which already requires is_ready true -> same flag == sequence). Two tests only cover it.
- CachedReader::warm chunk loop (reader.rs:1081-1140) is redundant with caller clamp engram.rs:607-609 (warm_batch <= max_rows), and inconsistent with CachedReader::gather which rejects ids.len() > max_rows (reader.rs:~1002).
- Transfers::new lower-bound nbytes checks (engram.rs:848-857, 866-874) duplicate runtime_core/engram.rs decode mailbox validation (lines 272-329).
- new test wait_ready_backoff_naps_until_publication_or_cancellation_and_resets asserts spins > SPIN_ROUNDS, which a pure spin also satisfies -> does not prove napping.
- ResidentMapping::new: /proc/self/fd reopen fallback to O_RDWR fd is speculative compat (AGENTS.md rejection criteria: no fallback layers).
- DiskReader::gather if/else could collapse into active_lanes computation (active_lanes==1 covers both branches).
- ignition/components/ngram_delivery.py _advisory_requests duplicates _requests; publish_advisory_requests/ exist as reusable ops. To verify: gather max_rows check line, Transfers::new callers, prose skill rules on comments, docs/verification, docs/performance-work.
#2 [high] D-lens findings, PR #590 (final)
PR 590 head 4ea9ba0, base main a54a8b8. Lens D (simplicity). Rules cited: AGENTS.md "Contribution scope and rejection criteria" (reject "fallback layers", "speculative compatibility"; tests must exercise the affected behaviour), docs/design-review.md principle 1 (Helios as simple as possible) and 15, .agents/skills/repo-prose/SKILL.md.
-
SHOULD FIX — dead second wait policy. helios/src/engram.rs:299-320
Requests::readdevice arm spins/naps onreadyitself, plusWaitBackoff::new()at :310. Its only production caller is engram.rs:654 (grep:\.read(), reached only fromReaderAction::Gather, whichnext_reader_action(engram.rs:401-406) returns only whenjob.requests.is_ready(cancelled)is true, i.e. the same flag already equalssequence(:287-297). So the loop body never runs while serving; it is a second, divergent backoff policy (freshWaitBackoffper call, no reset) beside the reader loop'swait(:618). Smaller version:readassumes readiness (fn read(self) -> Result<Vec<i64>>, dropcancelled), ordebug_assert!. That also deletes 3 of the 4 new tests (:1094-1140) which cover only the dead loop; the tests exist because the code does. -
SHOULD FIX — new test does not prove napping. helios/src/engram.rs:1177-1180
assert!(rounds.0 > SPIN_ROUNDS, "expected WaitReady to enter nap phase")counts rounds ofnext_reader_action; aWaitBackoff::stepthat only spun (deleteyield_core, keepspins += 1) reaches > 4096 rounds in ~2 ms of the test's 5 ms sleep and stays green. Nothing observes that the thread slept. Fix: measure wall time between the last spin round and publication, or assert wall time >> spin time, or delete the test and rely on the existing after-spin tests (:1106-1116, :1129-1140) that at least run in the nap phase. -
NIT/SHOULD FIX — warm chunking fixes a case production cannot reach, and duplicates the caller's clamp. reader.rs:1081-1140 wraps the whole warm body in
for chunk in ids.chunks(self.max_rows); the production caller clamps first: engram.rs:607-609warm_batch = WARM_BATCH_ROWS.min(max_tokens*table.heads).max(1)=CachedReader::max_rows(both derive frommax_tokens*table.heads; engram.rs:539-547 vs :607). Sowarmcan never receive more thanmax_rowsids in serving, and the old&ids[..min(max_rows)]never truncated rows there. It is also now inconsistent withCachedReader::gather(reader.rs:1001-1004) which still rejectsids.len() > max_rows. Smaller version: keep one clamp, the caller's; restore the single-pass body; droptotal_loadedand theusizereturn ofReader::warm(reader.rs:1293-1304), since production now ignores it (let _ = catch_unwindat engram.rs:676) — returnResult<()>. -
NIT — duplicated mailbox capacity validation. engram.rs:848-857 and :866-874 recompute
max_tokens*heads+1/max_rows+2slots and compare withnbytes, but runtime_core/engram.rs:272-329 (same PR) already validates the same mailbox against the sametokens*core_heads(model.rs:478-485 computesengram_tokensfrom the same consuming-graph max) and boundsreference.offset + mailbox.nbytes <= allocation.nbytes.prefetch.max_rowsis itselflen-2from that validation (runtime_core/engram.rs:323-328). Smaller version: rely on decode's bound and keep only adebug_assert!(or nothing) inTransfers::new; thechecked_mul/checked_addchain is 20 lines for a value already established two layers up. -
NIT — speculative fallback in the new mapping path. reader.rs:138-149
let readonly_view = Self::open_readonly_view(file).ok()thenmap_or(file.as_raw_fd(), ...): if procfs is missing the code silently falls back to the exact O_RDWR descriptor that fails with EPERM on <6.7 kernels, which is the defect being fixed, and only the error string (:151-159) hints at it. AGENTS.md rejects fallback layers and speculative compatibility. Smaller version: one path — reopen and surface the reopen error; deletemap_fdand the#[cfg(not(target_os="linux"))]map_fd shadow (:113-129, :144-149), inlining the singlelibc::mmapcall. -
NIT — reader.rs:787-825:
if self.lanes.len() == 1 || self.reads.len() <= lane_depthand the else both computeactive_lanes = reads.len().div_ceil(lane_depth).min(lanes.len()), which equals 1 exactly under the guard. Delete the guard and always take the scoped path (~8 lines). -
NIT — ignition/components/ngram_delivery.py:78-95
_advisory_requestsrepeats_requests(:59-75) line for line exceptHAS_LIMIT; smaller version: one op taking an optionallive_rows(the file already models this with HAS_LIMIT constexpr). Alsopublish_lookahead(:157-164) allocatesidsandrequestson every call, so the docstring's "reusing the prepared ... plan" is the only reuse; not a defect, just note the transient allocation. -
Comments: engram.rs:610-611 new comment restates docs/same-process-tp.md:63-64 (the same claim #519 review asked to remove); engram.rs:328-332 "under one decode step" and reader.rs:154 EPERM hint embed unenforced assumptions. Nit.
Verified negatives: scored_prefill GraphKind filtering is a genuine de-duplication (good); the QD fan-out arithmetic (lane_depth, active_lanes) is correct; CachedReader::warm per-chunk stats accounting adds up (count unique, added/evicted summed).
#3 [high] Research summary
Reviewed PR #590 (helios,ignition: fix Engram reader bugs and add PLE lookahead publish) through the simplicity lens, reading each changed function in context and following its callers (engram.rs reader loop, runtime_core decode, prepared.rs, model.rs, ngram_delivery.py).
Findings (8, recorded in full with file:line and the smaller version in the scratchpad):
- Should fix:
Requests::read's spin/nap loop (helios/src/engram.rs:299-320) duplicates the reader loop'sWaitBackofffor a wait that cannot happen in serving — its only caller runs afteris_readyreturned true on the same flag — and three of the four new tests exist only to cover that dead loop. - Should fix: the new
wait_ready_backoff_naps_until_publication_or_cancellation_and_resetstest asserts onlyrounds > SPIN_ROUNDS, which a pure spin also satisfies; it does not prove napping. - Should fix/nit: the chunked
CachedReader::warm(reader.rs:1081-1140) fixes a case the production caller's clamp makes unreachable, and is now inconsistent withgather's ownids.len() > max_rowsrejection; the single-pass body could return andReader::warm'susizeresult (now ignored) be dropped. - Nits: duplicated mailbox capacity arithmetic in
Transfers::new(already validated in runtime_core/engram.rs:272-329); the/proc/self/fdreopen fallback that silently restores the EPERM-failing descriptor (AGENTS.md rejects fallback layers); the redundantif lanes.len()==1 || reads<=lane_depthbranch thatdiv_ceilalready covers; the duplicated_advisory_requestsop in ngram_delivery.py; and three comments that restate docs or state unenforced invariants.
Verified as genuine simplifications: the GraphKind::try_from(...).is_ok_and(consumes) de-duplication, the QD fan-out arithmetic, and the per-chunk cache statistics.
#4 [high] Report-ready: PR #590 D-lens findings (severity-titled, citations)
PR #590 "helios,ignition: fix Engram reader bugs and add PLE lookahead publish", open, ready for review, head 4ea9ba0, base main a54a8b8, 4 files +588/−112, CI passed on head, no reviews. Author lukealonso (COLLABORATOR, priority contributor per charter). Lens D (simplicity). Rules cited: AGENTS.md §"Contribution scope and rejection criteria" (reject "framework, extension points, speculative compatibility, fallback layers"; "Require focused, meaningful validation: tests must exercise the affected behavior or contract"), docs/design-review.md principle 1 ("Keep Helios as simple as possible") and 15, .agents/skills/repo-prose/SKILL.md (:38-39 comments explain invariants; :26-29 no history).
Lead paragraph for the report: the change is mechanically sound and some parts genuinely remove duplication (notably the new GraphKind::try_from(...).is_ok_and(crate::engram::consumes) filter and the active_lanes fan-out arithmetic), but two of its five fix strands are dead or untested in production, and three added paths duplicate checks made by their own callers — roughly 60-80 of the added lines could go without losing a tested behaviour.
FINDINGS
F1. Should fix — Requests::read keeps a second, unreachable wait policy.
helios/src/engram.rs:299-320. The device arm waits on ready with its own WaitBackoff::new() (:310), but the only production caller is engram.rs:654 (grep for .read( shows no others in engram.rs), reached only when next_reader_action returned ReaderAction::Gather, which requires job.requests.is_ready(cancelled) (:401-406) — the identical flag == sequence test in is_ready (:287-297). So the loop body never runs while serving; it is a second backoff policy beside the reader loop's reset-on-action wait (:618, :627, :673, :689) that differs (fresh counter per call, no reset). Why it matters: two policies for one wait invite drift, and it is what the three new tests below exist to cover. Fix: fn read(self) -> Result<Vec<i64>> that assumes readiness (or debug_assert!(self.is_ready(...))), delete wait; delete tests at :1094-1140.
F2. Should fix — new test cannot distinguish napping from spinning.
helios/src/engram.rs:1142-1182, assertion at :1177-1180 counts next_reader_action rounds and asserts rounds.0 > SPIN_ROUNDS. A WaitBackoff::step that only spun (spins += 1, yield_core deleted) still exceeds 4096 rounds in the test's 5 ms AFTER_SPIN sleep (:1092) and passes. Nothing measures elapsed time. AGENTS.md requires tests to exercise the affected behaviour. Fix: assert wall time between entering the nap phase and publication (e.g. capture Instant at rounds >= SPIN_ROUNDS and require >= ~1 ms), or delete this test and keep :1106-1116/:1129-1140 which at least execute the nap path.
F3. Should fix (scope) / nit (code) — 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 serving caller already clamps: engram.rs:607-609 warm_batch = WARM_BATCH_ROWS.min(max_tokens.saturating_mul(table.heads)).max(1), and CachedReader::max_rows is the same max_tokens*table.heads (engram.rs:539-547 → reader.rs:1217/1244). So warm never receives more than max_rows ids in production and the removed truncation never dropped rows there; the defect exists only for direct Reader::warm callers. Meanwhile CachedReader::gather still rejects ids.len() > max_rows (reader.rs:1001-1004), so warm now tolerates what gather refuses. Fix: keep one clamp (the caller's), restore the single-pass body, and drop the accumulated total_loaded plus the usize return of Reader::warm (reader.rs:1293-1304) whose value is discarded at engram.rs:676 (let _ = catch_unwind(...)).
F4. Nit — duplicated mailbox capacity validation.
helios/src/engram.rs:848-857 and :866-874 recompute required slots (max_tokens*heads + 1, max_rows + 2) and compare with nbytes; runtime_core/engram.rs:272-329 in the same PR already validates those mailboxes against the same tokens*core_heads (both engram_tokens, model.rs:478-485, and prepared::bind derive from the same consuming-graph max) and bounds reference.offset + mailbox.nbytes by the MappedHost allocation; prefetch.max_rows is itself len-2 from that validation (:323-328). Fix: a debug_assert! or nothing in Transfers::new; ~20 added lines go.
F5. Nit — 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(), ...). If procfs is unavailable the mapping silently uses the original O_RDWR fd, i.e. the exact condition that returns EPERM on <6.7 kernels — the defect the PR fixes — and only the error string (:151-159) says so. AGENTS.md rejects fallback layers and speculative compatibility. Fix: one path — reopen 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.
F6. Nit — redundant fan-out guard.
helios/src/engram/reader.rs:787-796: both the lanes.len() == 1 || reads.len() <= lane_depth branch 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 (~8 lines) keeps behaviour identical and leaves one path to read.
F7. Nit — duplicated Triton/custom-op for PLE advisory publish.
ignition/components/ngram_delivery.py:78-95 _advisory_requests repeats _requests (:59-75) line for line except the HAS_LIMIT/live_rows arguments; the module already parameterises exactly this (publish_requests vs publish_advisory_requests, :36-56, and HAS_LIMIT/HAS_COUNT in the kernels). One op taking an optional live_rows removes ~20 lines of near-identical signature, fake registration and call site. Secondary: publish_lookahead (:157-164) allocates ids and requests per call, so PreparedPLELookup reuses only the plan.
F8. Nit — comments that restate docs or state unenforced invariants. helios/src/engram.rs:610-611 repeats docs/same-process-tp.md:63-64 above untouched spawn code (the same claim an earlier review asked to remove from #519); engram.rs:328-332 "under one decode step" is true only while a step outlasts 250 us and nothing detects otherwise; reader.rs:151-159 embeds the kernel-version hint inside a runtime error string. Per the prose skill, state the invariant where it is enforced or drop it.
VERIFIED POSITIVES (say so in the report)
- runtime_core/engram.rs:224 and :333 replace two hardcoded five-kind lists with one shared
GraphKind::try_from(...).is_ok_and(crate::engram::consumes); genuine de-duplication, and thechecked_mul/checked_addrewrites are the same shape as the surrounding validators. - reader.rs:787-825 fan-out arithmetic is correct:
lane_depth = DEPTH/lanes.len()matchesDiskReader::from_files(:691-696),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, andself.lanes[..active_lanes]bounds the split. CachedReader::warm's per-chunk statistics are consistent: oneinsert_advisoryper unique miss,added/evictedsummed across chunks,prefetch_rows_loadedincremented per chunk and total returned.
OPEN QUESTION for the report: whether the PLE publish_lookahead addition belongs in this bug-fix PR at all — it is the only capability addition among four defect fixes and depends on a companion recipe PR (merge order stated in the description), which docs/design-review.md principle 15 and AGENTS.md "keep each PR focused on one coherent outcome" argue against.