Re review report · NVIDIA/hyperflare-inference #674

Raw Markdown for agents: https://autobot.eidonix.com/p/b6f903a1-ed5e-42c0-9166-954cbfb39e6f.md

Recommendation: Changes Requested

The selene/ and selene-manager/ changes (direct O_DIRECT packed writes, StoreInvalidated propagation, clean L1 DRAM and buddy-coalesced manager RAM retention, lossless WindowReleaseSignal / epoch-tracked waiter wakeups, disk inventory/reservation metric split) and the helios/ GPU snapshot-alias packing and read-only prefill-delta estimator are well-engineered and sound. However, head 45fb380 (rebased onto main c513e46a, including #665) has three verified correctness blockers in helios/ — including a new rebase regression where page_pressure_victim_priority bypasses #665's scan-resistant is_protected(node) tier, an unconditionally dead observe_prefill_rate sampler (regression vs main), and an inverted upper-median index in RowRestoreLatency::observe — plus three per-victim O(N) / O(N * span) scheduler hot-path costs and stale pre-#665 A/B baselines.

Merge Risk

Level: High

Walkthrough

Pre-merge Checks

Blockers

  1. observe_prefill_rate is unconditionally dead code, freezing the cold-start restore fallback EMA (regression vs main) (helios/src/server/runtime.rs:3052-3075, helios/src/scheduler.rs:437-467, helios/src/execution/manifest.rs:85-87):

    • observe_prefill_rate computes let capacity = step.prefill_capacity() as u64; (runtime.rs:3058) and returns early if !step.kind.is_prefill() || step.lanes.len() != 1 || capacity == 0 || ... (runtime.rs:3059-3065).
    • ScheduledStep::prefill_capacity() (scheduler.rs:465-467) returns self.mixed.as_ref().map_or(0, |m| m.prefill_capacity). validate_mixed (scheduler.rs:437-462) forbids mixed.is_some() on any step with kind != GraphKind::Mixed, while GraphKind::is_prefill() (manifest.rs:85-87) matches only Prefill | TerminalPrefill | ScoredPrefill.
    • Consequently, !step.kind.is_prefill() || capacity == 0 is always true. self.prefill_rate never moves from flare_selene::INITIAL_PREFILL_RATE (8000.0, runtime.rs:1288), even though estimated_prefill_saved_seconds (runtime.rs:3248-3269) relies on it whenever estimate_prefill_delta_ns returns None on unmeasured/cold capacities (e.g., post-restart restores). On main, the sampler updated on every prefill with no capacity gate. No existing test calls observe_prefill_rate (pricing tests at helios/src/server/runtime/phase_tests.rs:8665, 8707, 8780 mutate worker.prefill_rate directly).
    • Fix: Replace step.prefill_capacity() as u64 with step.token_capacity as u64 (valid because !step.kind.is_prefill() already restricts to pure prefill steps), and add unit tests in helios/src/server/runtime/phase_tests.rs verifying that observe_prefill_rate updates worker.prefill_rate for single-lane pure prefills with tokens * 2 >= token_capacity and skips < 50% fills and multi-lane steps.
  2. page_pressure_victim_priority disables #665's scan-resistant reuse protection, inverts recency/role protection for overlapping unpinned checkpoints, and evicts unrelated hot leaves on pure backing conflict (helios/src/scheduler/cache_memory.rs:204-223, 391-409, 593-649, helios/src/cache.rs:353-380, 788-790, helios/src/scheduler.rs:1263, 1276-1280, docs/runtime-core-design.md:869-873):

    • New regression from 45fb380 rebase onto #665 (07e666e6): select_eviction_candidate (helios/src/cache.rs:788-790) minimizes (priority(node, *role_preserving), self.eviction_key(node)), where eviction_key (cache.rs:378-380) puts #665's self.is_protected(node) (node.reused) first. Because page_pressure_victim_priority (scheduler/cache_memory.rs:218-222) returns (!releases_page, node.retention_rank().use_epoch, !role_preserving_compaction), use_epoch sorts ahead of is_protected(node). Under page_pressure (both evict_for_pressure on decode/admission and simulate_snapshot_quote on capture), even when zero snapshots overlap (releases_page == true for every candidate), a reused protected checkpoint from epoch 100 is always evicted before an un-reused scan-pollution checkpoint from epoch 101 — completely defeating #665 on shared-alias deployments.
    • Recency and role inversion under overlapping unpinned checkpoints: When two cold unpinned checkpoints share a backing band (refs == 2), neither satisfies refs[page] == 1, so both get releases_page == false. Under mandatory page pressure (evict_for_pressure, where below = None, protected_token_budget = None), every hot Anchor/Message leaf with tail_pages (releases_page == true) is evicted ahead of those dead cold overlapping checkpoints. This also contradicts the policy sentence this PR added at docs/runtime-core-design.md:869-873 ("preserves completion recency").
    • Unrelated hot-leaf eviction on pure snapshot backing conflict (need_pages == 0): In ensure_resources (scheduler.rs:1263, 1276-1280), need_pages == 0 && backing_conflict == true sets page_pressure = true (scheduler/cache_memory.rs:599-601), causing evict_for_pressure to destroy a recent hot leaf in an unrelated band for pages that are not needed rather than evicting a cold overlapping checkpoint whose snapshot can directly satisfy available_snapshot(pages).
    • Fix:
      1. Preserve #665's is_protected(node) tier ahead of use_epoch (e.g., include is_protected ahead of recency in the page-pressure ordering, or apply the releases_page preference within the protection tier rather than ahead of eviction_key).
      2. Distinguish backing held by a pinned/in-flight owner (genuinely unfreeable right now) from backing shared only by other unpinned cold checkpoints (freeable together), or bound the !releases_page skip so it cannot sacrifice strictly newer protected / Anchor / Message leaves ahead of ancient unpinned overlapping entries.
      3. When need_pages == 0 && backing_conflict, prefer freeing an unblocked snapshot over evicting an unrelated hot leaf, align docs/runtime-core-design.md:869-873 with the resulting invariant, and add tests for #665 reuse protection under page pressure and overlapping unpinned pairs vs hot leaves.
  3. RowRestoreLatency::observe selects the upper median on count == 2, resurrecting a decayed latency spike on the first fast recovery probe (helios/src/server/runtime.rs:308-332, cf. selene/src/levels.rs:57-67):

    • RowRestoreLatency::observe sorts latencies ascending (lower is faster) and stores ordered[bucket.count / 2] with Instant::now() (runtime.rs:316-318). This mirrors selene::levels::Rate::observe (selene/src/levels.rs:65-67), where Rate tracks bytes/sec (higher is faster), so values[2 / 2] = values[1] selects the faster sample and clears a single slow spike on the first fast probe.
    • Because latency is inverted, ordered[2 / 2] = ordered[1] selects the slower sample on count == 2: after an aged 500 ms spike decays and admits a recovery probe that succeeds in 2 ms, observe(0.002) picks ordered[1] = 0.500 and resets the timestamp to now, locking out row-only restores for another full 10 s recovery window despite the fast probe succeeding. The new test (helios/src/server/runtime/phase_tests.rs:8829-8851) only covers start / finish(false) decay preservation, not an aged spike followed by a fast probe.
    • Fix: Use the lower median ordered[(bucket.count - 1) / 2] in RowRestoreLatency::observe and add a regression test in phase_tests.rs asserting that a single aged slow sample clears immediately on the first fast probe.

Should Fix

  1. Remove three per-victim O(N) / O(N * span) allocations and scans from the single-threaded scheduler loop during pressure eviction (helios/src/scheduler/cache_memory.rs:204-223, 391-409, 608-649, helios/src/cache.rs:740-753):

    • Unconditional Vec<u32> clone per victim (scheduler/cache_memory.rs:608-626): evict_for_pressure clones self.page_snapshot_refs (~628 KiB on DeepSeek-V4.1-Flash TP4's 156,956 pages) on every single call in ensure_resources and refill_reservations, even when self.cache.pending_retirement().is_empty() && self.retired.is_empty(). Use Cow::Borrowed(&self.page_snapshot_refs) when nothing is retiring; when retirements are pending, deduplicate retiring snapshot IDs via BTreeSet matching projected_fits (scheduler/cache_memory.rs:570).
    • Per-victim HashMap<CheckpointId, RetentionRole> over all checkpoints (cache.rs:744-753): Rebuilt on every call in evict_for_pressure and every loop iteration of simulate_snapshot_quote (up to 4,864 checkpoints). Track only_child: Option<CheckpointId> directly on Checkpoint (cache.rs:69-87) alongside child_count so role-preserving compaction checks become O(1) with zero heap allocation.
    • O(candidates * span) scan inside page_pressure_victim_priority (scheduler/cache_memory.rs:211-217): range.clone().any(|page| refs[page] == 1) runs up to 4,864 * 172 (~836k) checks per victim, whereas select_snapshots in the same file uses prefix sums. Build a prefix sum of u32::from(refs[p] == 1) once per pass so releases_page is O(1) per candidate.
  2. Re-baseline headline A/B measurements against current main (>= c513e46a) and sync PR metadata / #451 (charter #210, docs/design-review.md:106-115):

    • Tables A–C compare against 5d53040e (9 commits behind current main c513e46a, predating #665's cache-eviction policy change, #663/#660's scheduler pricing changes, and #667), and the PR description still reports base 4cc6f2fd and HEAD 0ebee3d4. After fixing Blockers #1–#3, re-verify the headline A/B against current main, update the PR body's base/HEAD and re-run test/TLA+ verification on the new head, and post the midpoint half-width conflict-span conclusion on open issue #451.

Subtract / Simplify

  1. Share greedy conditioned-window partitioning between conditioned_window_ends and set_conditioned_inputs (helios/src/scheduler.rs:2113-2142, 2181-2202):
    • Both methods implement the same features + input.feature_range.len() > capacity boundary split in the same impl RequestScheduler (conditioned_window_ends additionally filters input.token_span.end > consumed). Extract a single small window-partition helper so restore-pricing (helios/src/scheduler/checkpoints.rs:466, 482) and execution windowing cannot silently drift.
  2. Delete priority_uses_role_preserving / track_role_preserving after adding Checkpoint::only_child, and deduplicate the production priority closure (helios/src/cache.rs:732-811, helios/src/scheduler/cache_memory.rs:394-406, 627-638):
    • Once only_child: Option<CheckpointId> makes role_preserving O(1) with zero allocation (Should Fix #1), the priority_uses_role_preserving parameter and track_role_preserving guard disappear cleanly with no allocation penalty on eviction_candidate. Also hoist the duplicated page_pressure_victim_priority closure at scheduler/cache_memory.rs:394-406 and :627-638 into one helper method.

Nits

Dropped on verification