PR #659: perf(helios): alias null continuation row zero onto a single zeroed VMM granule

Raw Markdown for agents: https://autobot.eidonix.com/api/v1/cases/a92e42b3-b924-41b9-99bb-a3e11d38acde

Opened by a workflow run, Dec 1, 2026 1:32 PM EST. decide malicious: all_clear (100%): No malicious content found

explore

Author: lukealonso (COLLABORATOR; priority contributor named in the charter's "Respect contributors" rule, #229; 35 merged PRs in 180 days; Discord: lukealonso) Motivation: Models with continuation-state storage reserve row zero of their state pool as a permanent "null" row that holds only zeros, yet it was backed by its own physical VRAM for its whole span — tens of MiB per rank on GDN/Mamba models. Since CUDA VMM lets one physical allocation be mapped at many virtual offsets, the PR maps row zero's full leading 2 MiB granules onto one shared zeroed granule and reclaims the rest. Scale: +196 / −33 lines in 3 files Proposal:

Full report · Notes

Value Proposition

Value Proposition — PR #659 perf(helios): alias null continuation row zero onto a single zeroed VMM granule

Charter alignment — strong. The change lands in shared runtime code (helios/src/runtime_core/cache_memory.rs, memory.rs) and keys off sizing.capacity == 0 plus VMM alignment rather than any per-model branch, satisfying "keep the runtime small and model-agnostic" and the ban on per-model flags. It is runtime-only: no format, Protobuf, CLI or Prometheus schema change, so existing prepared cores still load — confirmed by the three-file diff. It touches no captured-graph op contract and needs no owner approval, and it benefits only already-supported continuation-state recipes (GDN/Mamba/hybrid) rather than widening the hardware/model matrix.

Novelty & status — genuinely additive. Nothing on main backs null-row storage differently; #391 created the handle budget this spends, #473 added the granule-padding/sentinel-range machinery it runs alongside, and #286 supplied the multi-address cuMemMap mechanism it reuses. No open PR supersedes, stacks on, or is undone by it. The "wrong layer" risk with a non-goal is low: row zero is a Helios-owned cache-planning artifact, not a recipe concern.

Value vs maintenance cost — real, but evidence stops one layer short. The arithmetic is verified in code and by CPU tests: sentinel_saved_bytes/Layout::sentinel_granules, the aliased map_cache_chunk loop, the fall-throughs for sentinel_granules <= 1, and the 158 MiB → 82 MiB / KV-page-gain test. Beneficiaries are operators serving continuation-state models with rows ≥ 2 VMM granules (≥ ~4 MiB) — a small but supported population. However the headline 32 MiB/rank / 76 MiB/rank figures are arithmetic, with no VRAM reading from a served core, which is the charter's "measured memory issue / served workload" bar (#210, design-review principle 12). Three costs are unaddressed: handle margin — +272 handles on the DCP16 fixture and up to 39 × row_readers per rank, spending margin that was a blocking review item by yatesdr in #391, with docs headroom falling 6,056 / 1.2% → 5,784 / 1.1% and no discussion in the description; weakened, unrun GPU test — cuda_aliases_preserve_rows_while_unowned_pages_are_rewritten now excludes row 0 from the distinct-pattern upload (.skip(1)) and was not run ("all local GPUs were occupied"), though #391 and #473 merged with the same tests unrun; and operator-visible capacity shift, since row_backing_bytes feeds capacities/gpu_bytes, so the same hardware now plans more KV pages and snapshot rows — intended, documented, but not stated to operators. The row-zero-never-written premise is enforced in Ignition (state.py, state_transfer.py), not Helios (offload/transfer.rs only bounds-checks row_capacity); the author discloses this, and it warrants at least a documented contract.

Changes needed before merge: (1) a live VRAM or memory-map delta on a real GDN/Mamba core; (2) run the CUDA VMM test, or replace the weakened assertion with one proving a row-zero write is visible at every aliased offset and stays in-granule; (3) answer the handle-margin question for wide-DP / 16-reader layouts; (4) state the planned capacity/row-count increase to operators; (5) confirm the Design-Signed-Off-By trailer (unverifiable with available tools).

Verdict: Worth it with changes. Right problem, right layer, correctly scoped, authored by a named priority contributor on code he dominates — but the GPU-layer evidence and the handle-margin answer are conditions, not niceties.

Note: no instruction-like or prompt-injection content was present in the PR material reviewed; the only external request was a Discord handle line, which is a normal description field.

Full report Decide Value: yes (100%): This change is worth reviewing: it provides value to the project in line with its charter.

Classify intake

Selected: performance, area:memory

Threshold: 65%

Triage

Priority

Type

Area

Model

Apply Labels (Intake)

Applied: +performance, +area:memory

Subtraction and simplicity

Subtraction/Simplicity review of PR #659: the diff is lean and honest (+196/−33, no new flags, knobs, env vars, per-model branches or dead symbols, no AGENTS.md structural violation), but three concrete cuts are available.

  1. row_backing_bytes (helios/src/runtime_core/memory.rs:383-414) is a verbatim copy of bytes (:357-381) — same capacity filter, same units > s.maximum error, same checked padding, same overflow message; only the trailing - saved is new. Replace with a saved fold plus bytes(core, 0, units).map(|span| span - saved); all five call sites (:486, :510, :523, :1003, :1249) unchanged and the 82 MiB assertion at :2041 still holds.

  2. The null-row physical decomposition is spelled four times: handle_charge (cache_memory.rs:81-102, four identical overflow closures), the mapping block (:1416-1447) and the zeroing block (:1467-1488). One derived count = sentinel_granules.max(1), granule = if count > 1 { alignment } else { fixed_bytes }, tail = fixed_bytes - granule*count reproduces today's handle counts exactly (1 + row_readers for n ≤ 1; 1 + n*row_readers plus 1 + row_readers when tailed) and deletes the else branches at :1438-1447 and :1483-1488, which are determinable code.

  3. The GPU-test edit branches inside the pattern closure (cache_memory.rs:1212-1225); assigning expected[0] = vec![0; …] after the untouched closure is −11/+2 lines with the same .skip(1) upload and assertion.

Lower value: sentinel_granules (:63, :259-262, :487) is derivable at its only allocation site, and sentinel_* is a second name for the docs' existing "null row" (docs/runtime-core-design.md:772-777).

Reuse is otherwise good — mapping goes through the existing multi-address map_cache_chunk (:1500-1534) rather than a new mechanism, and the two new CPU tests pin the formula at its real boundaries with no duplicated arithmetic.

Open: whether the author prefers bytes − saved over the parallel implementation, whether the count/granule/tail derivation is acceptable, and why "sentinel" was chosen over "null row".

Full report · Notes

Correctness and contracts

Review of PR #659 (null-row sentinel granule aliasing) — the arithmetic and mapping logic are correct, but three Major issues and several Minor ones remain.

Findings that matter:

  1. Major — the safety premise ("nothing writes row zero") is not enforced in the layer that can break it: helios/src/offload/transfer.rs:156-163 accepts slot 0, and helios/src/offload/gpu_tests.rs:1476-1481 actively writes row 0. Aliasing makes one stray write corrupt every leading granule (up to 39 offsets).
  2. Major — the new mapping/zeroing branch (cache_memory.rs:1416-1447, 1468-1488) has zero executed coverage; the only test that reaches it is #[ignore]d and was not run, and its row-0 assertions were weakened (.skip(1), cache_memory.rs:1226).
  3. Major — the saving costs sentinel_granules * row_readers handles (cache_memory.rs:82-102), verified +272 for the DCP16 fixture (518,232 → 518,504); on wide peer-read layouts this can flip a layout main loads into a plan_mapping_handles limit error (cache_memory.rs:611-616). Description does not mention the cost.
  4. Major — reclaimed bytes are redistributed into cache: row_backing_bytes feeds capacities/fits/minimum/pool budget (memory.rs:486,494,510,523,1003), so identical hardware now plans more KV pages and snapshot rows; the description presents it as a pure reclaim.
  5. Minor — duplicated alignment source between row_backing_bytes (memory.rs:398-409) and Layout::sentinel_granules (cache_memory.rs:259-262).
  6. Minor — startup "Allocate cache" total (memory.rs:1249,1291) now reports less while page/row counts rise; flare inspect stays virtual.
  7. Minor/process — evidence is CPU-unit + arithmetic only (no served-workload VRAM measurement), verification table row 14 covers exactly the unrun GPU test, and the design sign-off trailer could not be verified.

Verified sound: saved-bytes arithmetic, preserved virtual span, unique backing for live/snapshot rows, zeroing order before any read, teardown/unmap per mapping, peer grants, no hot-path or new unbounded buffering, checked arithmetic, no wire/CLI/metric/recipe-branch change.

Open: does a row-0 write guard belong in offload/transfer.rs? Should aliasing fall back when the handle plan would exceed RM_HANDLE_RANGE? And does the capacity shift need an operator-facing note?

Full report · Notes

Final review

Recommendation: Changes Requested

The core design and arithmetic are sound, model-agnostic, and well-scoped to shared cache-planning and VMM-allocation code (helios/src/runtime_core/cache_memory.rs, memory.rs). However, two concrete issues block merge: (1) the new CUDA VMM multi-aliasing and split-zeroing code in NativeResources::allocate_shared_cache has zero executed coverage on a GPU (including the modified GPU test) and no live-core verification, and (2) an existing in-repo GPU offload test writes and round-trips a distinct pattern through StateSlotId(0) and will fail on any continuation-state core where this optimization activates. Two clean subtractive refactors would also eliminate ~70 lines of duplicated logic.

Merge Risk

Level: Medium

Walkthrough

Pre-merge Checks

Blockers

  1. New CUDA VMM multi-aliasing and split-zeroing path is completely unexecuted on GPU (helios/src/runtime_core/cache_memory.rs:1106-1283, :1416-1488).

    • Verified behavior/impact: The only code that performs the multi-offset cuMemMap and split cuMemsetD8_v2 lives in NativeResources::allocate_shared_cache (:1416-1488). The new CPU unit tests only verify sentinel_saved_bytes, Layout::new, handle_charge, and capacities. The sole test covering allocate_shared_cache — cuda_aliases_preserve_rows_while_unowned_pages_are_rewritten (:1106-1283, which exercises both sentinel_granules == 0 at 3 * alignment / 2 and sentinel_granules == 3 at 7 * alignment / 2) — was modified and skipped ("all local GPUs were occupied"). Both docs/verification.md:14 (CUDA ordering / inactive rows / allocation stability require real GPU execution) and docs/design-review.md:106-115 (principle 12: validate the real path and back performance/memory claims with actual Helios measurements) apply directly here, especially given prior Blackwell driver cuMemMap aliasing constraints (cache_memory.rs:218-220).
    • Fix: Run cuda_aliases_preserve_rows_while_unowned_pages_are_rewritten on an assigned GPU against 16e2247 (and ideally verify in the equal_planes == true branch that row 0's leading granules stay zero while row 0's partial tail [sentinel_bytes, row_bytes) is independently backed from row 1), and report a before/after Plan cache / Allocate cache (or VRAM) reading from loading a real continuation-state core with row_bytes >= 2 * alignment.
  2. Existing GPU offload test writes and round-trips StateSlotId(0), breaking on affected cores (helios/src/offload/gpu_tests.rs:1476-1525, :1730-1804).

    • Verified behavior/impact: staged_store_round_trips_records_through_files_and_a_restart binds child_slot = StateSlotId(0) (:1478), uploads a distinct pseudo-random pattern across rank.row.unit_bytes into row 0 (:1519-1525), stores it to disk (:1730-1739), restores it into StateSlotId(2) (:1780-1790), and asserts byte-for-byte equality with the original pattern (:1798-1804). On any continuation-state core with row_bytes >= 2 * alignment, uploading to row 0 overwrites the single shared physical granule sentinel_granules times, so granules 0..sentinel_granules - 1 read back as copies of the last aliased granule and the test fails at :1800-1804.
    • Fix: Change child_slot at helios/src/offload/gpu_tests.rs:1478 to a nonzero slot (e.g. StateSlotId(4), adjusting the row_capacity assert at :1467 from >= 4 to >= 5).

Should Fix

  1. Enforce the non-zero row invariant in Helios's offload transfer layer (helios/src/offload/transfer.rs:156-163).

    • Verified behavior/impact: helios/src/offload/transfer.rs:156-163 only checks index >= geometry.row_capacity and accepts StateSlotId(0) for both inbound and outbound transfers. Now that row 0 is aliased onto one shared physical granule, an inbound transfer targeting slot 0 silently corrupts all sentinel_granules offsets simultaneously rather than affecting a single region. Production scheduling never allocates slot 0 (helios/src/scheduler.rs:946-948, 1753).
    • Fix: Reject index == 0 alongside index >= geometry.row_capacity at helios/src/offload/transfer.rs:156-163 (and update the two synthetic unit tests in helios/src/offload/transfer/codec.rs:1098, 1344 that pass StateSlotId(0) over standalone mapped host buffers to use StateSlotId(1) / a 3-row geometry).
  2. Guard Layout::grouped against execution == 0 and note the handle-margin trade-off in the PR description (helios/src/runtime_core/cache_memory.rs:259-262).

    • Verified behavior/impact: In Layout::grouped (:157, 259-262), sentinel_granules is computed solely from row_bytes / row_alignment without checking execution > 0 (or fixed_bytes >= n * row_alignment). While production capacities() guarantees execution >= 2 (memory.rs:459), Layout::new is callable directly and execution == 0 would leave fixed_bytes = 0 < sentinel_bytes. Separately, while the PR description mentions the 518,232 -> 518,504 test update, it omits explaining the handle-headroom cost (+17 handles/rank on DCP16, shrinking RM_HANDLE_RANGE headroom from 1.2% to 1.1%, and scaling by row_readers if state_pool ever has peer readers).
    • Fix: Compute sentinel_granules as if execution > 0 && row_bytes / row_alignment > 1 { row_bytes / row_alignment } else { 0 } (ensuring sentinel_bytes <= fixed_bytes by construction), and add one sentence to the PR description noting the RM-handle trade-off.

Subtract / Simplify

  1. Collapse row_backing_bytes onto bytes(core, 0, units) (helios/src/runtime_core/memory.rs:385-414 vs :357-381).

    • row_backing_bytes duplicates the exact capacity filter, units > s.maximum check, checked multiplication, alignment rounding, overflow errors, and try_fold from bytes. Calling let span = bytes(core, 0, units)?; first guarantees both validation and that sum(sentinel_saved_bytes) <= span (so neither summation overflow nor subtraction underflow is possible):
      fn row_backing_bytes(core: &Core, units: u64) -> Result<u64> {
          let span = bytes(core, 0, units)?;
          if units == 0 {
              return Ok(span);
          }
          let saved: u64 = core
              .allocations
              .iter()
              .filter_map(|a| a.sizing.as_ref().filter(|s| s.capacity == 0).map(|s| (a, s)))
              .map(|(a, s)| super::cache_memory::sentinel_saved_bytes(s.unit_bytes, a.alignment as u64))
              .sum();
          Ok(span - saved)
      }
      
    • Deletes ~20 lines of verbatim duplication and ensures virtual-span and physical-backing calculations share a single validation/rounding implementation.
  2. Describe the fixed-chunk split once on Layout (helios/src/runtime_core/cache_memory.rs:82-102, :1416-1447, :1468-1488).

    • handle_charge, allocate_shared_cache mapping, and allocate_shared_cache zeroing each repeat the same sentinel_granules > 1 / fixed_bytes > sentinel_bytes branching. A single helper on Layout:
      fn fixed_segments(&self) -> (u64, u64, u64) {
          let count = self.sentinel_granules.max(1);
          let granule = if count > 1 { self.alignment } else { self.fixed_bytes };
          (count, granule, self.fixed_bytes - granule * count)
      }
      
      eliminates both else branches in allocate_shared_cache (:1438-1447, :1483-1488) and collapses handle_charge (:82-102) into one checked expression (1u64.checked_add(count * row_readers) plus 1 + row_readers when tail > 0), removing ~50 lines of repeated branching and guaranteeing handle accounting, mapping, and zeroing cannot drift.

Nits

Dropped on verification

Full report Decision to Test: no (87%): Testing will not add significant value as the code stands today. The code is either not yet ready to merge, or adequate testing has already been done to validate the contents of the code, or the available hardware is not suitable to test with.

Classify triage

Selected: triage:validation

Threshold: 65%

Triage

Apply labels

Applied: +triage:validation