PR #694: selene,helios: add write-side NVMe and pool spill profitability gate

Raw Markdown for agents: https://autobot.eidonix.com/api/v1/cases/60c5607d-8be7-4a6b-b8b2-3ee22540ffec

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

explore

Author: yatesdr (COLLABORATOR; dominant contributor to helios/selene/docs; 82 merged PRs in 180 days); Discord D-Rock Motivation: Hybrid-attention models carry large fixed recurrent-state rows per checkpoint, so persisting short, unshared prompts to local NVMe or a shared pool spends disk and write bandwidth on restores that admission pricing would reject. This PR adds a write-side profitability gate that keeps those prefixes in DRAM (or refuses the pool spill) instead of writing them. Scale: +22,770 / −3,868 lines in 52 files Proposal:

Full report · Notes

Classify intake

Selected: triage:review, performance, enhancement, area:caching, area:selene

Threshold: 65%

Triage

Priority

Type

Area

Model

Apply Labels (Intake)

Applied: +triage:review, +performance, +enhancement, +area:caching, +area:selene

Value Proposition

Value Proposition — PR #694 (selene,helios: add write-side NVMe and pool spill profitability gate)

Charter alignment — strong. Prefix-cache checkpointing in host memory and sharing it across Flare instances via Selene is an explicit Goal, and this change stays inside that path: no Protobuf, Ignition, model-core, graph-contract, or on-disk v4 files in pr_files, and the dossier finds no per-model branches, flags, or env switches (policy derives from measured rates plus per-checkpoint prefill_saved_ns). It builds on the lineage it extends (worth_restore, row-role/packed-record semantics from #415/#413, disk-offload latency from #497/#496) rather than adding a parallel mechanism.

Novelty & status — additive, but stacked. Nothing in the searchable window supersedes or obsoletes it; the only prior art is the stacked parent #674 (same author, same day), and no competing write-gate proposal exists. So it is neither Superseded nor Obsolete. It cannot be judged standalone until #674 lands: the PR-vs-main diff carries ~2,961 lines of selene-manager/src belonging to #674, and it re-touches helios/src/cache.rs, runtime_core/cache_memory.rs, and docs/prefix-cache-offload.md, which #674's body already flags for merge-order coordination with #665 and #659.

Value vs cost — real benefit, thin evidence at head. Beneficiaries are operators running hybrid-attention models with --prefix-cache-disk or a Selene pool. But the charter requires a measured speedup over main on a served workload, and the headline A/B was taken on development commit 09400ad8, not head d74e810; 2 of 3 rows show zero skipped spills, so only Qwen3.8 exercises the gate; the fleet replay is an offline replay over .ckpt headers, and "shared forks promoted" is simulated. Cost is high — 52 files, ~+22.8k/−3.9k, with large rewrites of selene/src/memory.rs, composite.rs, disk_store.rs — supported by a solid test story (640/640 selene, 1,841 helios, plus targeted new unit tests), but only defensible if the benefit reproduces at head.

Changes needed before merge. (1) Rebase onto main after #674 and rerun the A/B at head, including a configuration where the gate actually fires on TP2/TP4. (2) Add the two new flare_host_cache_spill_skipped_unprofitable_* series to the host-cache metric table at docs/api.md:341-398 — every other family is documented there, yet docs/api.md has no mention of them. (3) Document the fail-open semantics (prefill_saved_ns == 0 ⇒ spill, selene/src/store.rs:529-534), which decides whether non-helios Selene embedders see any change. (4) Correct the "zero selene-manager changes" claim to top-commit-only, and mention the docs edits the description omits.

Verdict: Worth it with changes. Charter-aligned, additive, and authored by the dominant contributor to these files — but merge only after the stack lands, the evidence is reproduced on head d74e810, and the metric docs and description corrections are made.

(No injection-style or instruction-directing content was present in the PR body or repository material examined; the PR's "review only the top commit" note was treated as context, not instruction.)

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

Subtraction and simplicity

Subtraction/simplicity review of PR #694. The gate core is lean — one worth_restore predicate, prefill_saved_ns == 0 fail-open, no flags — but the machinery around it carries removable weight, and several pieces are the same function written twice.

Findings, highest value first:

  1. The GPU-compaction lineage + fork-vote cache (~250 lines, 5 fields, MAX_COMPACTED_PARENTS, a new empty-bodied HostStore::compacted trait method at selene/src/store.rs:396-399, a helios walker at sharing.rs:137-156, 8 test stubs) exists to keep fork votes linear-across-compaction — while the same PR decides the identical predicate with plain node.children() >= 2 at selene/src/memory.rs:1152 and selene/src/disk_store.rs:2253. Drop the cache and hook; keep dram_only.
  2. helios computes prefill savings inline at helios/src/server/runtime.rs:2917-2921, duplicating the pre-existing estimated_prefill_saved_seconds helper at runtime.rs:3276-3297 (same call, same .max(1.0) fallback).
  3. memory_pool_standalone_profitable (memory.rs:429-444) and disk_pool_standalone_profitable (disk_store.rs:2191-2206) are one function twice, both re-doing the saved_ns == 0 check inside standalone_spill_profitable; "logical chain bytes" appears three times (memory.rs:424, disk_store.rs:2186, composite.rs:572).
  4. standalone_nvme_bytes returns the same u64 twice (composite.rs:572-577) and the caller divides it by two rates.
  5. PoolSpillPolicy.level (store.rs:280-293) is only compared, never used for pricing; two producers duplicate the level→rate match (pool/store.rs:202-214, 242-258).
  6. Conventions: the two new series rendered at metrics.rs:872-885 are missing from the host-cache table in docs/api.md:341-398; unprofitable is double-counted (metrics.rs:536 host_store_reasons[6] vs composite.rs:1028), and the DRAM-retained path returns Stored, so the counters describe different populations.

Open: no PR-vs-base diff available locally (missing git objects), so top-commit vs #674 split is inferred; tests cannot be run; disk_store.rs and pool/cascade.rs not read line by line.

Full report · Notes

Correctness and contracts

Reviewed the top commit at pr/694 by reading changed files, callers and contracts in full (PR-vs-base diff tooling is broken in the local copy, so citations are file reads at head, not diff hunks). The gate primitives themselves are sound; the problems are in which records get priced, how one branch prices them, and what is documented.

Findings that matter most:

  1. Major — pool gate fail-opens for the entire cold-restart population. Scan-recovered records are inserted with prefill_saved_ns: 0 (selene/src/shared/index.rs:468, selene/src/disk_store.rs:2306-2320) and 0 means "unpriced = profitable" (disk_store.rs:2199-2202, selene/src/store.rs:529-533). Only a republish backfills the price (selene/src/composite.rs:810-824), so records never re-offered spill to the pool unconditionally — the very population the PR's cold-restart table measures.
  2. Major — the NVMe gate silently drops the upload charge under DRAM pressure. composite_rates is passed only when memory.fits() (composite.rs:546-551), so spill_eligible_nvme_with_rates prices bytes/disk_rate alone (disk_store.rs:3579-3584) instead of the restore-side disk/disk_rate + bytes/memory_rate (composite.rs:420-421) — up to ~2× more permissive exactly when pressure makes skipping attractive, contradicting the PR's stated costing. The composite-side gate (composite.rs:587-591) uses the stricter formula, so the two gates can disagree about the same record.
  3. Major — new user-visible contracts undocumented. flare_host_cache_spill_skipped_unprofitable_total/_bytes_total{tier} and the unprofitable reason on flare_host_cache_store_reasons_total (helios/src/server/metrics.rs:872-885, 922-933) are absent from docs/api.md:341-398; the public StoreOutcome::Unprofitable (selene/src/store.rs:268-276) is absent from the publication-outcome contract (docs/prefix-cache-offload.md:1462-1465).
  4. Minor — O(n) full-index rescan per blocked capture retry (composite.rs:506-532, 473-492; disk_store.rs:2612-2668), O(n·retries) under sustained disk pressure on the store's single thread.
  5. Minor — reap_evicted_dram_only drains the eviction list then discards removal errors (composite.rs:447-464), stranding dram_only bookkeeping with no retry.
  6. Claim accuracy — the A/B was measured on 09400ad8, not head d74e810; two of three served rows report zero gated spills, and the fleet table is an offline replay (Charter #210).

Open: whether the 0-price-at-scan behavior is deliberate (the backfill test suggests tolerated, not accidental) and whether the head commit reproduces the A/B. Bounded, well-tested change overall — no protobuf/ignition/model-core/v4 changes; the predicates, hysteresis, O(1) clean_slots and remove_nodes atomicity check out.

Full report · Notes

Final review

Recommendation: Changes Requested

The core write-side profitability gate, top-down pool coverage, O(1) clean_slots accounting, dram_only warm L1 retention/reclamation, compaction-lineage canonicalization, and cascade anchor retention are technically sound — no core correctness, safety, or concurrency blockers were found after direct verification at head d74e810. Changes are requested before merge because (1) this PR is stacked on unmerged #674 and its headline A/B numbers were measured on an earlier combined dev commit (09400ad8) where two of three models had zero gated spills (conflating #674's byte reduction with this gate) and without reporting the mandatory verification/helios-lifecycle/check.py gate, and (2) the new user-visible Prometheus metrics, StoreOutcome::Unprofitable contract, and prefill_saved_ns == 0 fail-open / cold-restart recovery semantics are missing from docs/api.md and docs/prefix-cache-offload.md.

Merge Risk

Level: Medium

Walkthrough

Pre-merge Checks

Blockers

None.

Should Fix

  1. Rebase after #674 and refresh head-commit verification and A/B evidence (PR description, docs/design-review.md:106-115, 209-251):

    • The served SM120 A/B table was measured on combined dev commit 09400ad8 rather than head d74e810, and two of the three rows (GLM-5.3-Flash TP2 and DeepSeek-V4.1-Flash TP4) report 0 skipped spills while showing NVMe byte reductions (5.10 → 3.79 GB on GLM-5.3) attributable to #674 rather than this gate. Once rebased onto main after #674, rerun the A/B against post-#674 main at head (explicitly distinguishing any row where the gate does not fire from the gate's own savings) and label the production fleet table as an offline header replay directly alongside its headline figures.
    • Because the top commit modifies helios/src/scheduler.rs, helios/src/scheduler/sharing.rs (eviction/compaction tracking), and helios/src/server/runtime.rs (publication/pin lifecycle), run python3 verification/helios-lifecycle/check.py on head and include the result in the PR's Verification section per docs/design-review.md:211-215, 234-251.
  2. Document the new Prometheus metrics, StoreOutcome::Unprofitable, and fail-open recovery semantics (docs/api.md:340-398, docs/prefix-cache-offload.md:685-696, 1454-1465):

    • helios/src/server/metrics.rs:872-885, 922-933 adds flare_host_cache_spill_skipped_unprofitable_total{tier}, flare_host_cache_spill_skipped_unprofitable_bytes_total{tier}, and flare_host_cache_store_reasons_total{reason="unprofitable"}, none of which appear in docs/api.md:340-398 (which documents every other flare_host_cache_* family). Add them to docs/api.md, clarifying that ..._bytes_total counts skipped write bytes (packed stored bytes when compressed in L1 DRAM per selene/src/composite.rs:1023-1029, otherwise uncompressed tail+row bytes per disk_store.rs:3621-3622 and memory.rs:848-850).
    • docs/prefix-cache-offload.md:1462-1465 lists only Present, Oversize, and Retry under Publication outcomes; add Unprofitable (selene/src/store.rs:275) with its terminal unpin-without-deferral semantics (helios/src/server/runtime.rs:2940-2966).
    • Explicitly document in docs/prefix-cache-offload.md:685-696 (and the PR description) that prefill_saved_ns == 0 intentionally fails open (selene/src/store.rs:528-534) — including for on-disk records recovered after restart (selene/src/disk_store.rs:2306-2320, 2199-2201, preserved due to zero v4 header changes) until Helios republishes the key and backfills prefill_saved_ns (selene/src/composite.rs:810-825, 7992-8038).

Subtract / Simplify

  1. Stop forwarding set_pool_spill_policy into CompositeStore's flat MemoryStore (selene/src/composite.rs:2473-2476, selene/src/memory.rs:1243-1265, 1299-1305):
    • In CompositeStore, self.memory is flat (flat = true) and never spills to the pool (CompositeStore::set_spill only calls self.disk.set_spill(enabled) at composite.rs:2470-2472, and CompositeStore::spill_eligible_pool only queries self.disk.spill_eligible_pool(key) at composite.rs:2477-2479). Calling self.memory.set_pool_spill_policy(policy) at composite.rs:2475 allocates and maintains a full HashMap<PrefixKey, PoolCoverage> across every L1 DRAM record and runs an O(n) recompute_clean_slots() scan on every >= 5% pool rate update for zero behavioral effect. Delete line 2475 (or guard pool_coverage in MemoryStore on !self.flat).
  2. Simplify CompositeStore::record_is_packed to query self.disk directly (selene/src/composite.rs:2483-2493):
    • CompositeStore's TierStore implementation retires exclusively from PoolTier::Nvme (self.disk.take_retiring(), self.disk.retirement_predecessor(), self.disk.pin_export_files()), so checking self.memory.record(&key) before self.disk is backwards and unnecessary. Replacing lines 2483-2493 with self.disk.record_is_packed(key) matches the actual NVMe export source and removes 9 lines.
  3. Deduplicate estimated_prefill_saved_* in helios/src/server/runtime.rs:2917-2921 vs 3276-3297:
    • Both sites run scheduler.estimate_prefill_delta_ns(...) with the identical gained as f64 / prefill_rate.max(1.0) cold fallback. Extract a shared estimated_prefill_saved_ns(...) -> u64 helper (or have estimated_prefill_saved_seconds wrap it) to eliminate the second fallback formula.
  4. Deduplicate pool standalone profitability and chain-byte helpers (selene/src/memory.rs:424-444, selene/src/disk_store.rs:2186-2206, selene/src/composite.rs:572-577):
    • memory_pool_standalone_profitable and disk_pool_standalone_profitable are identical apart from MemoryRecord/DiskRecord, and both repeat the saved_ns == 0 => true check already performed by standalone_spill_profitable (selene/src/store.rs:529-534). Moving standalone_profitable(&self, bytes: u64, prefill_saved_ns: u64) -> bool onto PoolSpillPolicy removes both helpers and the redundant zero-checks.
    • CompositeStore::standalone_nvme_bytes (selene/src/composite.rs:572-577) returns (raw_bytes, raw_bytes) (the same u64 twice); returning a single u64 simplifies both the helper and its caller at composite.rs:587-592.
  5. Collapse duplicated PoolSpillPolicy construction (selene/src/pool/store.rs:202-214 vs 242-258):
    • PooledStore::new and PooledStore::pool_spill_policy repeat the identical remote_manager() → Level → rates[2]/rates[3] match. Extracting one free helper pool_spill_policy(remote_manager: bool, rates: &Ranking) -> PoolSpillPolicy removes the duplicate block.

Nits

Dropped on verification

Full report

Classify triage

Selected: triage:review

Threshold: 65%

Triage

Apply labels

No label changes Decision to Test: no (100%): 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.