Conventions report · NVIDIA/hyperflare-inference #590

Raw Markdown for agents: https://autobot.eidonix.com/p/e68e8d7f-017d-4029-9237-ebd7cd0c8e47.md

Review — PR #590 (helios, ignition: fix Engram reader bugs + PLE lookahead publish), lens: conventions & duplication

Key findings


Should fix

1. helios/src/engram/reader/windows.rs:56,91,94 — the Windows backend keeps the exact dispatch this PR fixes on Unix

The PR rewrites the lane dispatch in DiskReader::gather (helios/src/engram/reader.rs:787-800):

let lane_depth = DEPTH / self.lanes.len();
if self.lanes.len() == 1 || self.reads.len() <= lane_depth { /* lane 0 */ }
else { let active_lanes = self.reads.len().div_ceil(lane_depth).min(self.lanes.len()); ... }

windows::Readers::gather is the structural twin of that block and was not touched (pr_diff confirms no file matching "windows" is in the change set):

So on Windows with --embedding-table-workers 4|8, batches of 17..=128 reads still collapse onto lane 0 — the 4x–8x NVMe queue-depth collapse this PR ships a test for on Unix (unix_disk_reader_fans_out_when_reads_exceed_single_lane_depth_below_total_depth, reader.rs:2200+). The rest of the two bodies is otherwise identical (scoped helpers, flare-table-io-N naming, local.gather(first, ...) then joining), so this is one decision implemented twice with only one copy corrected.

Why it matters: AGENTS.md:497-500 — "When a potential correctness, memory, or performance deficiency appears in one model, inspect the shared components and equivalent paths in every supported recipe before scoping the fix. Track follow-up work across all affected models; distinguish confirmed findings from untested paths." The charter's Code Review Standards likewise ask reviewers to check "every supported … parallel layout … and hardware target named in the docs", and docs/windows.md (not opened) exists as a supported target. Either Windows Engram is in scope (then the fix belongs in both), or it is out of scope (then it needs to be said in the description and tracked).

Fix: apply the same lane_depth / active_lanes computation in windows::Readers::gather, or factor the lane fan-out (active-lane count + chunking + scoped join) into one function both backends call — the bodies are otherwise line-for-line the same. Note the Windows lane type has no lanes field, only windows::Readers, so a shared helper would need a small trait or a closure over &mut [Lane].

2. ignition/components/ngram_delivery.py:157-164 — PreparedPLELookup.publish_lookahead allocates two GPU tensors on every call, unlike publish and unlike the Engram precedent

def publish_lookahead(self, token_ids, query_start, history, num_seqs, num_tokens, live_rows, mailbox):
    g = self.geometry
    ids = torch.empty_like(self.ids)
    requests = torch.empty(self.ids.shape[0], dtype=torch.int32, device=self.ids.device)
    _advisory_requests(...)

Both tensors are write-only scratch (mutates_args=("ids","requests","mailbox"), :78); the caller never sees them, so their identity carries no information.

The closest precedent is the sibling method in the same class, publish (:148-155), which reuses the buffer prepared in __init__ (self.requests, :122) and only allocates in the functional() case where it was dropped (:144, :151-152). The abstraction this PR is mirroring — PreparedEngram.publish_lookahead (ignition/components/engram.py:280-283) — likewise reuses prepared scratch: it calls _hash_window(...) with dest=self.hashes on the serving path (engram.py:273-277) and only allocates when args/dest are absent (:242-254). This new method is therefore the only preparation-time hashing path in either component that unconditionally allocates.

Why it matters: AGENTS.md:417-419 — "Do not introduce an eager serving fallback, runtime compilation, graph recapture, or GPU allocation in steady-state execution"; AGENTS.md:176-179 rejects "steady-state GPU allocation" as an architectural violation. The docstring (:158) says the method hashes "an upcoming prompt window during graph capture", so the honest framing is: either it runs inside capture, in which case the two allocations are baked into every replay while a persistent buffer would be reused, or it runs per step, in which case it is straight steady-state allocation. Either way the prepared-buffer pattern exists two methods above and was not followed.

Fix: hoist ids/requests next to self.ids/self.requests in __init__ (:121-122) and keep a functional()-style lazy fallback exactly as publish does; pass self.requests through.


Nits

3. helios/src/engram.rs:325-377 — WaitBackoff is a third hand-rolled spin-then-park policy, with no reference to the two existing ones

Existing policies in helios: execution/threaded.rs:65-88 spin_wait_until (32 fast spins → spin to HANDOFF_POLL 500us → yield_now, with a documented reason per rung, :66, :82-86; receive at :34-59 is the same shape), and runtime_core/persistent_worker.rs:26-29,507-512 (WORKER_DRAIN_SPIN_POLLS = 64 then a 1 ms drain poll). server/runtime.rs:1176-1182 parks with executor.park()/yield_now. The new WaitBackoff spins SPIN_ROUNDS = 4096 then thread::sleep(25us * n).min(250us).

Two verifiable deltas: the neighbours park with yield_now() or a wall-clock-bounded poll, while this uses thread::sleep and so is subject to Linux timer slack on the 25–75 us rungs; and WaitBackoff::step has no elapsed-time bound, so a repeated WaitReady can sleep indefinitely with no diagnostic and no metric. NAP_MAX's doc (:330-331) asserts "under one decode step", an invariant nothing enforces or measures (flare_replay_readiness_wait_nanoseconds_total is the counter from #519's review that would show the cost). No design doc states a wait policy today (docs/runtime-core-design.md (not opened) is the natural home). Inherited from #519 rather than invented here, but this PR is where it lands; a doc comment naming the other two mechanisms and why the reader needs sleep would keep the next reader from reconciling four policies.

4. ignition/components/ngram_delivery.py:78-95 — _advisory_requests duplicates _requests and sits beside the already-named publish_advisory_requests

_advisory_requests (:78) is _requests (:59) with two call arguments flipped to their constexpr variants: _copy_requests[...](ids, mailbox, mailbox, n, 256, False) → (ids, live_rows, mailbox, n, 256, True) and _publish[...](mailbox, mailbox, sequence, ..., False) → (mailbox, live_rows, sequence, ..., True). The Triton kernels already take the flag as tl.constexpr (_copy_requests :18-25, _publish :29-33, HAS_LIMIT/HAS_COUNT), so one custom op with live_rows: Optional[Tensor] would cover both without the duplicated op + duplicated fake + duplicated wrapper. Naming also collides: the existing "publish to an advisory mailbox" op is the public publish_advisory_requests (:47-51), while the existing "hash + publish" precedent is private and PLE-specific (_requests, :59). The new name is neither, and the two ops differ only in whether hashing happens first. Nit, because the two-op split is cheap if publish_lookahead stays the only caller — the names are the real cost. (AGENTS.md:404 "prefer proven operators … over duplicate kernels" applies at the kernel layer; this duplication is one level up.)

5. helios/src/engram/reader.rs:1085-1139 vs :1001-1079, and helios/src/engram.rs:843-882 vs runtime_core/engram.rs:272-322 — two duplicated bodies

(a) CachedReader::warm is now a chunk loop whose body is a near-verbatim copy of CachedReader::gather: build/filter miss_ids (:1086-1091 vs :1011-1018), filter by pin_if_present (:1098-1105 vs the cache.get loop :1022-1034), disk.gather(planes, &self.miss_ids, &mut self.miss_output[..count * (weights + scales)]) (:1110-1114 vs :1052-1056), per-miss split into w/s and insert* with resident_rows/evictions fetch_add (:1117-1132 vs :1057-1076). The only real differences are insert_advisory vs insert, copying into the output, and the new prefetch_rows_loaded bump. warm already duplicated gather before this PR; the PR deepens the copy by ~40 lines instead of factoring the "miss → disk gather → split into w/s" tail into a helper taking a closure for the insert. AGENTS.md:188-193 ("Refactoring must directly support the requested behavior or remove a demonstrated source of defects or cost") makes this defensible either way — flagged because the duplicated miss_output indexing (count * weights + index * scales) is where a future width change would desynchronize.

(b) The new mailbox capacity checks in Transfers::new (engram.rs:843-882, e.g. "n-gram request mailbox is smaller than staged capacity" at :856) mirror validate_mailbox (runtime_core/engram.rs:272-301, shape[0].checked_mul(8) at :287; min_request_len = max_staged_rows + 1 / max_prefetch_len = max_staged_rows + 2 at :303-322) in a second place with different arithmetic. The scopes legitimately differ (declared shape vs mapped buffer byte length against max_tokens * heads), and Transfers::new is the layer that actually has the address, so the check belongs there — but a one-line comment naming the runtime_core twin would prevent a future drift whose symptom would be a startup error pointing at the wrong layer.

6. helios/src/engram/reader.rs:139-143 — the one silent fallback in the EPERM fix

let readonly_view = if !writable { Self::open_readonly_view(file).ok() } else { None }; discards the reason the reopen failed and silently falls back to the writable fd, i.e. straight back into the pre-6.7 EPERM. AGENTS.md:184-186 forbids "suppress errors, silently substitute execution paths". The EPERM hint (:151-159) partly compensates by naming /proc/self/fd, but cannot say why the reopen failed (procfs absent, fd closed, permission). Nit: procfs is effectively always present on a box that mounts a disk Engram table, and the fallback is the pre-PR behaviour, so nothing regresses; map_err(|e| format!("reopen resident embedding table read-only: {e}")) carried into the hint would cost one line.

Related, recorded so the next reviewer does not ask: the hand-rolled reopen is not a duplicate of eos/src/unix.rs:60-65 direct_reopen (that is direct_file(..., false), which adds O_DIRECT, and an O_DIRECT descriptor cannot back an mmap); other /proc/self/fd idioms in the tree (heliopause/src/export/archive.rs:350 (not opened), heliopause/src/export/io.rs:777, helios/src/runtime_core/archive.rs:566,666, helios/src/core/container.rs:730) are direct-I/O or path-only. map_fd (reader.rs:113-129) and crate::os::map_host (eos/src/unix.rs:85-103) do different jobs (MAP_SHARED on an fd vs anonymous MAP_PRIVATE|MAP_ANONYMOUS|MAP_POPULATE + MADV_HUGEPAGE). Also note the description says the reopen uses O_RDONLY | O_CLOEXEC while the code uses File::open (:108-111), which is read-only + O_CLOEXEC by default — behaviour matches, text does not; a reviewer reading only the description will look for OpenOptions::custom_flags.


Positive: the GraphKind change adopts the established pattern (no finding)

Both filters in helios/src/runtime_core/engram.rs (:224, :333) now use GraphKind::try_from(g.kind.as_str()).is_ok_and(crate::engram::consumes), replacing two hard-coded five-kind lists and matching the exact expression that already existed at runtime_core/model.rs:480-481 with consumes defined at engram.rs:1011-1021. That is the de-duplication the lens asks for. Two notes: the try_from half cannot fail here in practice (unknown kinds are rejected at manifest decode, e.g. runtime_core/protobuf.rs:886,909, selection.rs:216 (not opened)) — it exists only because consumes takes a typed GraphKind, and keeping it matches model.rs:480, which is right; and runtime_core/selection.rs:318 (not opened) still has a hard-coded list ("init" | "restore" | "snapshot" | "resume"), but that is a different set (lifecycle kinds, not Engram consumers), so leaving it is correct.

Checked and found consistent

Open questions / not covered