Repository navigation
helios,ignition: fix Engram reader bugs and add PLE lookahead publish - #590
Conversation
|
A case file has been opened for 590. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedFour of the five changes are verified sound, but
Have your agent review the Full Review for complete verified findings, To opt out, include |
4ea9ba0 to
7035ea8
Compare
|
@flare-autobot Updated in 7035ea8: dropped WaitBackoff (paired alternating A/B/A/B validation on DeepSeek-V4.1-Flash TP4 confirmed +30% to +201% regression in flare_replay_readiness_wait_nanoseconds_total), unified Unix and Windows multi-worker lane fan-out through shared lane_fanout in reader.rs and reader/windows.rs, preserved /proc/self/fd reopen errors in the Linux EPERM diagnostic, and scoped the PR description and benchmark attribution to each change. |
Fixes #481 Why: Three defects affect Helios disk-backed and resident embedding tables, and PreparedPLELookup in core ignition lacked an advisory lookahead publish path needed for Qwen3.8's disk-backed per-layer embedding (PLE) table: 1. Multi-worker queue-depth collapse on Unix and Windows (helios/src/engram/reader.rs, helios/src/engram/reader/windows.rs) and direct Reader::warm truncation (helios/src/engram/reader.rs, helios/src/engram.rs): both Unix DiskReader and Windows Readers split the fixed DEPTH (128) slot budget evenly across workers (lane_depth = DEPTH / workers: 64, 32, or 16 for 2, 4, or 8 workers), yet both routed every batch with reads.len() <= DEPTH to lanes[0] alone. For 17-128 reads with 4 or 8 workers (including Windows' default of 4 workers), effective queue depth collapsed 4x-8x onto one lane. Separately, CachedReader::warm silently truncated &ids[..ids.len().min(self.max_rows)]; while the serving reader loop already bounds pending_warm.len() <= prefetch_max_rows <= max_rows through core validation, direct Reader::warm callers passing more than max_rows IDs silently dropped tail rows. 2. Pre-6.7 Linux EPERM on sealed resident tables (helios/src/engram/reader.rs, #481): Resident::initialize seals its O_RDWR memfd with F_SEAL_WRITE and then calls mmap(PROT_READ, MAP_SHARED) on the same O_RDWR descriptor. Linux kernels older than 6.7 reject shared mappings whose descriptor retains write permission (VM_MAYWRITE), causing --embedding-table-storage ram startup to fail with EPERM. 3. Unchecked mailbox byte-length multiplication and scored_prefill omission (helios/src/runtime_core/engram.rs, helios/src/engram.rs): validate_mailbox computed mailbox.shape[0] * 8 without overflow checking. In release builds, a malformed shape[0] such as (1 << 61) + 1 or 1 << 61 wraps to 8 or 0, bypassing validation and reaching out-of-bounds reads or pointer underflow (address + nbytes - 8) in Transfers::new and Requests::read. Both graph-kind filters in runtime_core/engram.rs also omitted "scored_prefill", diverging from engram::consumes. 4. Missing PLE advisory lookahead interface (ignition/components/ngram_delivery.py): PreparedEngramRequests exposed publish_lookahead, whereas PreparedPLELookup exposed only synchronous publish, blocking Qwen3.8 PLE recipes from using EngramTable.prefetch_buffer. What changed: - helios/src/engram/reader.rs and helios/src/engram/reader/windows.rs: - Before: both Unix DiskReader::gather and Windows Readers::gather dispatched to lanes[0] whenever reads.len() <= DEPTH (128). - After: both call shared helper lane_fanout(reads, lanes), which compares reads against DEPTH / lanes and fans across reads.div_ceil(lane_depth) .min(lanes) active lanes with reads.div_ceil(active_lanes) reads per lane. - Before: CachedReader::warm truncated &ids[..ids.len().min(self.max_rows)] and accounted only for the truncated prefix. - After: CachedReader::warm processes ids.chunks(self.max_rows) and increments prefetch_rows_loaded per completed chunk. - Before: ResidentMapping::new mapped file.as_raw_fd() directly for read-only remaps. - After: on Linux when !writable, ResidentMapping::new reopens /proc/self/fd/<fd> read-only (O_RDONLY | O_CLOEXEC) for mmap, falls back to file.as_raw_fd() if procfs is unavailable, and includes any reopen io::Error alongside a pre-6.7 kernel hint if mmap returns EPERM. - helios/src/engram.rs: - Before: ReaderAction::Warm sliced by WARM_BATCH_ROWS (1024) directly, and Transfers::new subtracted 8/16 from nbytes without capacity checks. - After: ReaderAction::Warm caps its batch size to WARM_BATCH_ROWS.min(max_tokens * heads).max(1), and Transfers::new verifies checked minimum byte sizes for both request and prefetch mailboxes before computing flag and count addresses. - helios/src/runtime_core/engram.rs: - Before: validate_mailbox used unchecked shape[0] * 8, did not check MappedHost allocation bounds against offset + nbytes, and skipped "scored_prefill" in both graph-kind filters. - After: uses checked_mul(8) and checked_add, verifies offset + nbytes fits inside the named MappedHost allocation, and includes "scored_prefill" in both graph-kind filters. - ignition/components/ngram_delivery.py: - Before: PreparedPLELookup exposed only publish. - After: adds PreparedPLELookup.publish_lookahead(ids, count, step), writing row IDs, row count (nbytes - 16), and sequence flag (nbytes - 8) into a prepared lookahead buffer during graph capture. Claimed benefit and result: - Expected: eliminates pre-6.7 Linux EPERM startup failure for resident RAM tables (#481), restores multi-worker NVMe queue depth for 17-128 read batches on both Unix io_uring and Windows I/O rings, prevents release-build u64 overflow and allocation overrun in mailbox loading, aligns scored_prefill validation with engram::consumes, and unblocks disk-backed PLE lookahead prefetch in Qwen3.8 recipes. - Measured (strictly attributable to PreparedPLELookup.publish_lookahead paired with the companion Qwen3.8 recipe change in local-inference-lab/hyperflare-recipes#87, not to the reader or validator fixes): on Qwen3.8-Flash-Next-NVFP4-MXFP8-CSF-QAD TP1 on RTX PRO 6000 Blackwell (SM120, /dev/md0 NVMe RAID, exported core gb202-tp1-202611282155, --embedding-table-storage disk --embedding-table-cache-size 4GiB --embedding-table-resident-scales --embedding-table-workers 1), synchronous PLE gather time dropped 76.5% (0.881 s -> 0.207 s; row-cache hit 43.1% -> 94.7%) and cold 111,915-token TTFT dropped 4.6% (7.778 s -> 7.418 s; 14,388 -> 15,087 tok/s) with flare_engram_prefetch_errors_total = 0 and 4/4 needle-in-a-haystack passkey matches. Supporting evidence and material limitations: - cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib -- engram: 45 passed, 0 failed (covers lane_fanout across 1/2/4/8 workers, Unix io_uring multi-lane fan-out for 80 reads below DEPTH, chunked CachedReader::warm past max_rows, /proc/self/fd read-only remap with F_GETFL == O_RDONLY and mprotect EACCES, u64 mailbox overflow and MappedHost overrun rejection, and scored_prefill validation). - cargo test --locked --release --manifest-path flare/Cargo.toml: 228 + 7 + 1 passed, 0 failed, 4 ignored. - cargo check --locked --release --manifest-path heliopause/Cargo.toml: clean. - cargo clippy --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib --tests: 0 warnings in modified lines. - pytest tests/preparation/test_core_boundary.py tests/cli -q: 137 passed. - Limitations: - The paired Qwen3.8 served benchmark ran at --embedding-table-workers 1, which bypasses multi-worker fan-out; multi-worker QD fan-out, pre-6.7 EPERM handling, and u64/scored_prefill validation are verified by unit tests rather than exercised by that served run. - Pre-6.7 Linux EPERM handling was verified on Linux 6.18 via F_GETFL == O_RDONLY and mprotect EACCES rather than on a kernel older than 6.7. - Windows compilation and runtime I/O ring execution were not run on this Linux host; Windows shares the unit-tested lane_fanout planner with Unix. Design-Signed-Off-By: Antigravity (Gemini); design-review=c3a9 Signed-off-by: Luke Alonso <[email protected]>
7035ea8 to
6fe7bed
Compare
Fixes #481
Why
Three defects affect Helios disk-backed and resident embedding tables, and
PreparedPLELookupin coreignitionlacked an advisory lookahead publish path needed for Qwen3.8's disk-backed per-layer embedding (PLE) table:helios/src/engram/reader.rs,helios/src/engram/reader/windows.rs) and directReader::warmtruncation (helios/src/engram/reader.rs,helios/src/engram.rs): Both UnixDiskReaderand WindowsReadersdivide the fixedDEPTH(128) slot budget evenly across workers (lane_depth = DEPTH / workers: 64, 32, or 16 slots for 2, 4, or 8 workers), yet both routed every batch withreads.len() <= DEPTHtolanes[0]alone. On 17–128 reads with 4 or 8 workers (including Windows' default of 4 workers), effective queue depth collapsed 4x–8x onto a single lane. Separately,CachedReader::warmsilently truncated&ids[..ids.len().min(self.max_rows)]; while the serving reader loop already boundspending_warm.len() <= prefetch_max_rows <= max_staged_rows == max_tokens * table.heads == reader.max_rowsthrough core validation, directReader::warmcallers passing more thanmax_rowsIDs silently dropped tail rows.EPERMon sealed resident tables (helios/src/engram/reader.rs, RAM embedding tables fail on kernels < 6.7:map resident embedding table: Operation not permitted#481):Resident::initializeseals itsO_RDWRmemfd withF_SEAL_WRITEand then callsmmap(PROT_READ, MAP_SHARED)on the sameO_RDWRdescriptor. Linux kernels older than 6.7 refuse shared mappings whose descriptor retains write access (VM_MAYWRITE), failing--embedding-table-storage ramstartup withEPERM.scored_prefillomission (helios/src/runtime_core/engram.rs,helios/src/engram.rs):validate_mailboxcheckedmailbox.nbytes != mailbox.shape[0] * 8without overflow checking. In release builds, a malformedshape[0]such as(1 << 61) + 1or1 << 61wraps* 8to8or0, bypassing validation and reaching out-of-bounds reads or pointer subtraction (address + nbytes - 8) inTransfers::newandRequests::read. Both graph-kind filters inruntime_core/engram.rsalso omitted"scored_prefill", diverging fromengram::consumes.ignition/components/ngram_delivery.py):PreparedEngramRequestsexposedpublish_lookahead, whereasPreparedPLELookupexposed only synchronouspublish, blocking Qwen3.8 PLE recipes from using perf(engram): add graph-driven advisory lookahead prefetch for disk-backed tables #566'sEngramTable.prefetch_buffercontract.What changed
helios/src/engram/reader.rsandhelios/src/engram/reader/windows.rs:DiskReader::gatherand WindowsReaders::gatherdispatched tolanes[0]wheneverreads.len() <= DEPTH(128).lane_fanout(reads, lanes)helper that comparesreadsagainstDEPTH / lanesand fans out acrossreads.div_ceil(lane_depth).min(lanes)active lanes withreads.div_ceil(active_lanes)reads per lane.CachedReader::warmtruncated&ids[..ids.len().min(self.max_rows)]and updated stats over only the truncated prefix.CachedReader::warmiteratesids.chunks(self.max_rows)and incrementsprefetch_rows_loadedper completed chunk.ResidentMapping::newmappedfile.as_raw_fd()directly for read-only remaps.!writable,ResidentMapping::newreopens/proc/self/fd/<fd>read-only (O_RDONLY | O_CLOEXEC) formmap, falls back tofile.as_raw_fd()if procfs is unavailable, and preserves any reopenio::Erroralongside a pre-6.7 kernel hint ifmmapreturnsEPERM.helios/src/engram.rs:ReaderAction::Warmsliced by unclampedWARM_BATCH_ROWS(1024), andTransfers::newsubtracted 8 or 16 fromnbyteswithout capacity checks.ReaderAction::Warmclamps its batch size toWARM_BATCH_ROWS.min(max_tokens * heads).max(1), andTransfers::newverifies checked minimum byte lengths for both request and prefetch mailboxes before computing flag and count addresses.helios/src/runtime_core/engram.rs:validate_mailboxused uncheckedshape[0] * 8, did not check thatoffset + nbytesfits inside the namedMappedHostallocation, and skipped"scored_prefill"in both graph-kind filters.checked_mul(8)andchecked_add, enforces allocation bounds against the namedMappedHostregion, and includes"scored_prefill"in both graph-kind filters.ignition/components/ngram_delivery.py:PreparedPLELookupexposed onlypublish.PreparedPLELookup.publish_lookahead(ids, count, step), writing row IDs, row count (nbytes - 16), and sequence flag (nbytes - 8) into a prepared lookahead buffer during graph capture.Claimed benefit and result
EPERMstartup failure on--embedding-table-storage ram(RAM embedding tables fail on kernels < 6.7:map resident embedding table: Operation not permitted#481); restores multi-worker queue depth for 17–128 read batches on both Unixio_uringand Windows I/O rings; prevents silent row drops for directReader::warmcallers exceedingmax_rows; prevents release-buildu64overflow and allocation overruns in mailbox loading; alignsscored_prefillvalidation withengram::consumes; and enables disk-backed PLE lookahead prefetch for Qwen3.8 recipes.PreparedPLELookup.publish_lookaheadpaired with the companion Qwen3.8 recipe change inlocal-inference-lab/hyperflare-recipes#87, not to the reader or validator fixes): OnQwen3.8-Flash-Next-NVFP4-MXFP8-CSF-QADTP1 on RTX PRO 6000 Blackwell (SM120,/dev/md0NVMe RAID, exported coregb202-tp1-202611282155,--embedding-table-storage disk --embedding-table-cache-size 4GiB --embedding-table-resident-scales --embedding-table-workers 1), synchronous PLE gather time dropped 76.5% (0.881 s -> 0.207 s, row-cache hit43.1% -> 94.7%) and cold 111,915-token TTFT dropped 4.6% (7.778 s -> 7.418 s,14,388 -> 15,087 tok/s) withflare_engram_prefetch_errors_total = 0and 4/4 needle-in-a-haystack passkey matches.Supporting evidence and material limitations
cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib -- engram: 45 passed, 0 failed (coverslane_fanoutacross 1/2/4/8 workers, Unixio_uringmulti-lane fan-out for 80 reads belowDEPTH, chunkedCachedReader::warmbeyondmax_rows,/proc/self/fdread-only remap verifyingF_GETFL == O_RDONLYandmprotect(PROT_READ | PROT_WRITE)EACCES,u64mailbox byte-length overflow andMappedHostallocation overrun rejection, andscored_prefillcapacity/hash-binding validation).cargo test --locked --release --manifest-path flare/Cargo.toml: 228 + 7 + 1 passed, 0 failed, 4 ignored.cargo check --locked --release --manifest-path heliopause/Cargo.toml: clean.cargo clippy --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib --tests: 0 warnings/errors in modified lines.pytest tests/preparation/test_core_boundary.py tests/cli -q: 137 passed.--embedding-table-workers 1, which bypasses multi-worker fan-out; multi-worker QD fan-out, pre-6.7EPERMhandling, andu64/scored_prefillvalidation are verified by unit tests rather than exercised by that served run.EPERMbehavior was verified on Linux 6.18 viaF_GETFL == O_RDONLYandmprotectEACCESrather than on a kernel older than 6.7.lane_fanoutplanner with Unix.Merge order: Merge this PR before bumping
uv.lockinlocal-inference-lab/hyperflare-recipesso Qwen3.8 exports detectPreparedPLELookup.publish_lookahead.Discord: no username provided