Skip to content

helios,ignition: fix Engram reader bugs and add PLE lookahead publish - #590

Merged
lukealonso merged 1 commit into
mainfrom
engram-ple-qwen38-and-bugs
Nov 29, 2026
Merged

lukealonso merged 1 commit into
mainfrom
engram-ple-qwen38-and-bugs

Conversation

@lukealonso

@lukealonso lukealonso commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

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 divide the fixed DEPTH (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 with reads.len() <= DEPTH to lanes[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::warm silently truncated &ids[..ids.len().min(self.max_rows)]; while the serving reader loop already bounds pending_warm.len() <= prefetch_max_rows <= max_staged_rows == max_tokens * table.heads == reader.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, RAM embedding tables fail on kernels < 6.7: map resident embedding table: Operation not permitted #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 refuse shared mappings whose descriptor retains write access (VM_MAYWRITE), failing --embedding-table-storage ram startup with EPERM.
  3. Unchecked mailbox byte-length multiplication and scored_prefill omission (helios/src/runtime_core/engram.rs, helios/src/engram.rs): validate_mailbox checked mailbox.nbytes != mailbox.shape[0] * 8 without overflow checking. In release builds, a malformed shape[0] such as (1 << 61) + 1 or 1 << 61 wraps * 8 to 8 or 0, bypassing validation and reaching out-of-bounds reads or pointer subtraction (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 perf(engram): add graph-driven advisory lookahead prefetch for disk-backed tables #566's EngramTable.prefetch_buffer contract.

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 a shared lane_fanout(reads, lanes) helper that compares reads against DEPTH / lanes and fans out 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 updated stats over only the truncated prefix.
    • After: CachedReader::warm iterates 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 preserves any reopen io::Error alongside a pre-6.7 kernel hint if mmap returns EPERM.
  • helios/src/engram.rs:
    • Before: ReaderAction::Warm sliced by unclamped WARM_BATCH_ROWS (1024), and Transfers::new subtracted 8 or 16 from nbytes without capacity checks.
    • After: ReaderAction::Warm clamps its batch size to WARM_BATCH_ROWS.min(max_tokens * heads).max(1), and Transfers::new verifies checked minimum byte lengths 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 that offset + nbytes fits inside the named MappedHost allocation, and skipped "scored_prefill" in both graph-kind filters.
    • After: Uses checked_mul(8) and checked_add, enforces allocation bounds against the named MappedHost region, 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 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 Unix io_uring and Windows I/O rings; prevents silent row drops for direct Reader::warm callers exceeding max_rows; prevents release-build u64 overflow and allocation overruns in mailbox loading; aligns scored_prefill validation with engram::consumes; and enables disk-backed PLE lookahead prefetch for 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 beyond max_rows, /proc/self/fd read-only remap verifying F_GETFL == O_RDONLY and mprotect(PROT_READ | PROT_WRITE) EACCES, u64 mailbox byte-length overflow and MappedHost allocation overrun rejection, and scored_prefill capacity/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.
  • Limitations:
    • The paired Qwen3.8 served benchmark ran with --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 behavior 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.

Merge order: Merge this PR before bumping uv.lock in local-inference-lab/hyperflare-recipes so Qwen3.8 exports detect PreparedPLELookup.publish_lookahead.

Discord: no username provided

@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 590.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

Four of the five changes are verified sound, but WaitBackoff re-lands the exact wait policy blocked in open PR #519 behind a factually inaccurate main baseline claim and with no attributable served or readiness-wait measurements. The identical multi-worker lane-collapse bug is also left untouched on Windows.

  • Blockers: 1
  • Should fix: 3
  • Subtractive suggestions: 0
  • Nits: 2

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

@lukealonso
lukealonso force-pushed the engram-ple-qwen38-and-bugs branch from 4ea9ba0 to 7035ea8 Compare November 29, 2026 00:04
@lukealonso

Copy link
Copy Markdown
Collaborator Author

@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]>
@lukealonso
lukealonso force-pushed the engram-ple-qwen38-and-bugs branch from 7035ea8 to 6fe7bed Compare November 29, 2026 00:04
@lukealonso
lukealonso merged commit 9031847 into main Nov 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RAM embedding tables fail on kernels < 6.7: map resident embedding table: Operation not permitted

2 participants