Architecture scratchpad · NVIDIA/hyperflare-inference #590

Raw Markdown for agents: https://autobot.eidonix.com/p/d1ad7da5-f777-474f-a629-97c0180ec6e0.md

#1 [high] Should fix: PR bundles four unrelated fixes plus a new feature; previously blocked #519 nap re-landed inside it

PR #590 (head 4ea9ba0) changes 4 files, +588/-112, and carries five separate outcomes:

  1. io_uring lane fan-out (helios/src/engram/reader.rs:787-800)
  2. CachedReader::warm chunking (reader.rs:1081-1140)
  3. pre-6.7 EPERM read-only remap (reader.rs:107-176)
  4. WaitBackoff spin-then-nap (helios/src/engram.rs:322-377, 685-687)
  5. unchecked u64 mailbox arithmetic + scored_prefill filters (helios/src/runtime_core/engram.rs)
  6. NEW capability: PreparedPLELookup.publish_lookahead (ignition/components/ngram_delivery.py:78-95, 157-164)

Against AGENTS.md:155-199 ("Keep each PR focused on one coherent outcome and describe its problem, resulting behavior, validation, and material limitations"; "Reject unsupported abstractions and churn ... Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement") and docs/design-review.md:135-146, this is one PR delivering six outcomes across two languages and two layers (native runtime + ignition component). It also drags #519's disputed change in.

#519 (open, PR by peperunas) is exactly the WaitBackoff design; lukealonso's 2026-11-28 comment there blocked it: "No served-workload benefit demonstrated, and readiness-latency impact is unmeasured ... lowering idle reader CPU on a discrete-GPU host without a demonstrated served improvement does not meet the merge bar (matching why #353 was closed on the same wait)" and asked for flare_replay_readiness_wait_nanoseconds_total to be reported. This PR bundles the same WaitBackoff with genuine bug fixes, which removes the ability to accept the fixes and reject the parking change separately, and the description offers no served measurement for it (the 76.5% gather / 4.6% TTFT numbers are attributed to the PLE lookahead feature, not to the backoff). Charter "How We Work": "Bring real evidence. Performance PRs need benchmarks showing an actual speedup over main on a served workload (#210)". Test added (wait_ready_backoff_naps_until_publication_and_cancellation_and_resets, engram.rs:1139-1183) proves only that the wait returns; it cannot show a benefit. Fix: split the backoff (and ideally the PLE feature) out, or obtain an explicit maintainer ruling that idle reader-thread CPU occupancy is itself the defect, and report readiness-wait metrics before/after.

#2 [high] Should fix: WaitBackoff is a third hand-rolled wait policy, and its Requests::read half is unreachable in production

docs/design-review.md principle 1: "Keep Helios as simple as possible." helios already has at least three bespoke wait policies: spin_wait_until (helios/src/execution/threaded.rs:65-88, 32 spins then HANDOFF_POLL spin/yield), recv_after_spin (threaded.rs:40-59), GraphExecutor::park + thread::yield_now (helios/src/server/runtime.rs:1176-1182), plus thread::yield_now in the io_uring error paths (reader.rs:514, 595). PR #590 adds a fourth with its own schedule (SPIN_ROUNDS=4096, 25 us growth, 250 us ceiling) and no stated reason for those numbers (engram.rs:322-352). #519's own review already argued the ramp costs ~51 lines for one sleep and that it reaches the ceiling after ~1.4 ms of a measured 28.8 ms wait, so const NAP_MAX + spin/sleep is equivalent and shorter.

Second half: Requests::read (engram.rs:299-320) gets its own WaitBackoff, but after #566 the only production caller is ReaderAction::Gather (engram.rs:626-671), which is dispatched only when job.requests.is_ready(cancelled) has already returned true (engram.rs:401-405), i.e. ready == sequence or cancelled. The loop at engram.rs:311-316 therefore never iterates in serving; wait.step() there is dead code, kept only for the unit tests. The description presents backoff in Requests::read as part of the fix ("used by both ReaderAction::WaitReady ... and Requests::read"), which overstates it. Fix: keep one wait helper (or reuse an existing one) applied at ReaderAction::WaitReady, and either delete the read loop's backoff or say it is test-only.

#3 [high] Research summary

Reviewed PR #590 (head 4ea9ba0, 4 files, +588/−112) through the architecture-and-scope lens, against the charter, AGENTS.md and docs/design-review.md. All four changed files were read in context (helios/src/engram.rs, helios/src/engram/reader.rs, helios/src/runtime_core/engram.rs, ignition/components/ngram_delivery.py), with their callers (Transfers::new/enqueue, Shared::new/with_readers/next_reader_action, runtime_core/model.rs engram wiring, GraphKind::try_from, engram::consumes, PreparedEngramRequests) and the governing docs (helios/manifest.md §prefetch_buffer, docs/cli-design.md §embedding-table flags, docs/design-review.md testing hierarchy).

Two confirmed findings recorded in the scratchpad, both "should fix":

  1. Scope. One PR delivers six outcomes across two layers and two languages (io_uring lane fan-out, warm-batch chunking, pre-6.7 memfd remap, a spin-then-nap wait, defensive mailbox arithmetic + scored_prefill filters, and a brand-new PreparedPLELookup.publish_lookahead capability). AGENTS.md:155-199 requires each PR to keep "one coherent outcome" and rejects both unneeded extension points and churn; the validation evidence is a single combined test tally, so no individual outcome can be accepted or rejected on its own. Most seriously, the WaitBackoff block (engram.rs:322-377) is the change currently blocked in open PR #519, where the maintainer's 2026-11-28 comment asks for served evidence and flare_replay_readiness_wait_nanoseconds_total and notes that #353 was closed on this same wait; bundling it with genuine bug fixes removes that judgement and the description offers no served measurement for it (the 76.5% gather / 4.6% TTFT numbers belong to the PLE feature).

  2. Wait simplification. WaitBackoff is a fourth bespoke wait policy in Helios beside spin_wait_until/recv_after_spin (execution/threaded.rs:40-88), GraphExecutor::park + yield_now (server/runtime.rs:1176-1182) and the io_uring yield_now paths (reader.rs:514, 595), with unexplained 4096/25 µs/250 µs constants (design-review principle 1: keep Helios as simple as possible). Its Requests::read half is unreachable in serving: after #566 the only production caller is ReaderAction::Gather, dispatched only once is_ready() is already true, so the new loop in read exists just for unit tests while the description describes it as part of the fix.

The pre-6.7 mapping fix is correctly targeted at the reported root cause in #481 and works on every kernel (read-only descriptor, no VM_MAYWRITE), and preserves the seals/immutability check — it does not fall back silently. The scored_prefill filter change is a genuine correctness convergence on the shared engram::consumes predicate rather than a new special case. No charter-violating layer crossing was found in the Python addition (Ignition prepares, Helios serves), though its scope belongs with the recipe PR it depends on.

#4 [medium] Verified-correct parts of #590 (no finding): memfd read-only remap and scored_prefill filter converge on existing mechanisms

Pre-6.7 EPERM fix (helios/src/engram/reader.rs:107-176): ResidentMapping::new now reopens /proc/self/fd/<fd> read-only (File::open, O_RDONLY|O_CLOEXEC) when !writable and maps through that descriptor, keeping MAP_SHARED|PROT_READ. This is exactly the root cause and remedy in issue #481 (fd is O_RDWR so the VMA keeps VM_MAYWRITE; pre-6.7 kernels refuse; a read-only file description has no VM_MAYWRITE). Seals are untouched (RESIDENT_SEALS at reader.rs:186-188, from_shared checks F_GET_SEALS at reader.rs:351-355), so immutability is still enforced — this is not an error-swallowing fallback (AGENTS.md "don't just swallow, skip, or retry an unexplained error"): the procfs reopen is preferred, and if it is unavailable the code maps the original fd and fails with an EPERM message naming the kernel requirement (reader.rs:151-159). Only nit-level risk: the write path (initialize, reader.rs:326) still maps the original fd, which is correct since it needs PROT_WRITE. Test sealed_resident_readonly_mapping_drops_write_capability_via_proc_reopen (reader.rs:2290-2320 region) checks F_GETFL==O_RDONLY and mprotect EACCES; the PR honestly discloses it ran on 6.18, not on a <6.7 kernel.

scored_prefill convergence (helios/src/runtime_core/engram.rs:224, 333): both filters now use GraphKind::try_from(g.kind.as_str()).is_ok_and(crate::engram::consumes), the same predicate already used at runtime (execution/transport.rs:971, 1047, 1095, 1141, 1198, 1266; engram/prepared.rs:216, 266) and at runtime_core/model.rs:480. So this removes a divergence rather than adding a special case — good under design-review principle 1 ("Let the scheduler operate over whatever valid graphs the core provides").

io_uring fan-out (reader.rs:787-800): lane_depth = DEPTH / self.lanes.len() mirrors the depth actually constructed in from_files (reader.rs:690-698, let depth = DEPTH / workers), and active_lanes = reads.len().div_ceil(lane_depth).min(lanes.len()) guarantees each active lane gets at most lane_depth reads, matching its slot count (free_slots = depth, reader.rs:456). split_first_mut on [..active_lanes] with active_lanes>=2 in that branch is safe. Correct fix for the described QD collapse; the real dependency is that lanes beyond active_lanes stay idle, which is intended.

CachedReader::warm chunking (reader.rs:1081-1140): ids.chunks(self.max_rows) keeps every chunk within the allocated miss_ids/miss_output workspace, and prefetch_rows_loaded moved from Reader::warm (now reader.rs:1297-1303) into the chunk loop, so the counter no longer double counts. miss_output[..count*(weights+scales)] with count<=max_rows remains in bounds.

Transfers::new lower-bound checks (helios/src/engram.rs:848-882) and runtime_core/engram.rs checked_mul/checked_add + offset+nbytes <= allocation.nbytes close real wrap and OOB paths; they are removed-validation-free hardening, not new mechanism.