Recommendation: Changes Requested
Commit 66d6af3 cleanly resolved most of Round 1's feedback: max_sequence_pages: NonZeroU64 is now threaded through PlannedHostBudgets into NativeModel::prepare_offload (eliminating the duplicate lookup and model.rs None fallback), max_sequence_tokens == 0 is rejected in memory.rs, PrepareInputs::max_sequence_pages uses Option<NonZeroU64> with a single clamp in headroom_inner, and the tests and docs were tightened. However, one half of Round 1's Should Fix remains unfixed: helios/src/runtime_core/memory.rs:999 still calls context.div_ceil(contract.cache.page_tokens as u64) without guarding contract.cache.page_tokens == 0 (panicking on division by zero under default KvCacheLimit::Memory before PreparedContract::validate ever runs), and the new .ok_or_else(...) at :1000 is unreachable dead code. A 2-line non-zero check on contract.cache.page_tokens before div_ceil will make this ready to merge.
Merge Risk
Level: Low
- Small, localized startup-only change (+94/−21 across 9 files) with no CLI/config/wire/core-format surface and no hot-path runtime impact.
- Strictly relaxes pool-only host-budget sizing on single-process deployments (
--prefix-cache-pool --prefix-cache-memory 0, no disk tier); deployments with local memory/disk tiers and multi-host sharded ranks are unaffected. - Overlaps adjacent host-budget code in open PR #737 (
helios/src/runtime_core/memory.rs,model.rs,selene/src/offload.rs), requiring only routine rebase coordination if #737 merges first.
Walkthrough
selene/src/offload.rs: Addspub max_sequence_pages: Option<std::num::NonZeroU64>toPrepareInputs(:342-345), clampschain_pagesinheadroom_innerviainputs.max_sequence_pages.map_or(pages, |limit| pages.min(limit.get()))(:165-167), and destructures with..inprepare_with_inputs_budget_with_progress(:627) while forwardinginputsintoheadroom_inner(:703-709).helios/src/runtime_core/memory.rs: Addsmax_sequence_pages: std::num::NonZeroU64toPlannedHostBudgets(:34, :1595), rejectsmax_sequence_tokens == 0(:993-996), computesmax_sequence_pages(:998-1000), passesSome(max_sequence_pages)into initialheadroom_with_inputs_for_budget(:1134) without double-clampingminimum_pages(:1136), and clampspages.min(max_sequence_pages.get())incapture_growth(:1490) andplanned_offload_host(:1556-1560).helios/src/runtime_core/model.rs: ThreadsSome(planned.max_sequence_pages)fromallocate_cachesintoprepare_offload(:1047-1053, :1125) and directly intoPrepareInputs(:1167-1173), removing the duplicatedserver_config["max_sequence_tokens"]derivation.docs/prefix-cache-offload.md: Updates the pool-only capture buffer section (:1593-1609) to document the single-sequence ceilingmin(GPU page capacity, ceil(max_sequence_tokens / page_tokens))and capped minimum-capacity startup failure behavior, reflowed to ~79 columns.- Tests (
selene/src/offload/tests.rs,helios/src/runtime_core/memory.rs, and existing test fixtures): Folds(512, NonZeroU64::new(64))intopool_only_sizes_registered_capture_and_headroom_for_local_ranks(selene/src/offload/tests.rs:531-576), addspool_capture_growth_caps_at_max_sequence_pages_without_throttling_gpu_pagesassertingpages == uncapped_pages(memory.rs:2446-2465), and addsmax_sequence_pages: Noneacross existingPrepareInputs/prepare_offloadtest fixtures.
Pre-merge Checks
- [PASS] Security / malicious screen: No obfuscation, prompt injection, external network/secret access, or suspicious code paths.
- [PASS] Charter & value fit: Model-agnostic fix for a measured host-memory issue on target SM120/SM121 workstation hardware under the Selene prefix-cache offload goal; carries none of closed #718's out-of-scope surface.
- [PASS] Related / duplicate / conflict check: Not a duplicate; carves out only the #455 pool-only capture bound from closed #718. Already rebased onto
012219a1(#713); only minor adjacent overlap with open PR #737. - [WARN] Tests & verification evidence: Author reports all six workspace crates passing in
--locked --releaseon66d6af3; live RSS measurements (18.74–19.06 GiBvs7.83–8.04 GiB) come from av0.6.0(f705086) build running the same rule, and CUDA/integration/Windows/formal suites were not run on head (all transparently disclosed).
Blockers
None.
Should Fix
- Unfixed half of Round 1 Should Fix #1:
div_ceil(contract.cache.page_tokens as u64)still panics on zerocontract.cache.page_tokens, and the newNonZeroU64::new(...).ok_or_else(...)branch is dead code (helios/src/runtime_core/memory.rs:993-1000)- Verified behavior: In
allocate_caches(memory.rs:884),memory.rs:896-899validatesself.server_config["page_tokens"] != 0, notcontract.cache.page_tokens.contractis deserialized fromself.server_config["model_contract"]atmemory.rs:900-902without callingPreparedContract::validate(), andNativeModel::load_agreeingrunsallocate_caches(flare-cli/src/main.rs:323->model.rs:1038) beforeModelConfig::from_server_config/PreparedContract::validate(helios/src/model/contract.rs:536), whileprotobuf::serving_contract(helios/src/runtime_core/protobuf.rs:75-89) does not validatecontract.cache.page_tokens. Under the defaultKvCacheLimit::Memorymode,page_ceilingreturnsOk(None)immediately atmemory.rs:568-570before itscontract.cache.page_tokens == 0check at:571. Consequently:- If
contract.cache.page_tokens == 0, line999executescontext.div_ceil(0)unconditionally on every model load (even with offload disabled) and panics withattempt to divide by zerobeforeNonZeroU64::newis called — regressingmain, which returnedErr(invalid(...))viacache_geometry->CacheGeometry::validate()(memory.rs:1024,1890). - Because
context > 0is already enforced atmemory.rs:995andu64::div_ceilon a positive dividend with any positive divisor is always>= 1,.ok_or_else(|| invalid("model requires a positive prepared context ceiling"))?atmemory.rs:1000is unsatisfiable dead code.
- If
- Fix: Validate
contract.cache.page_tokensas non-zero before callingdiv_ceiland replace the dead.ok_or_elsewith.expect(...):let logical_page_tokens = std::num::NonZeroU64::new(contract.cache.page_tokens as u64) .ok_or_else(|| invalid("model requires a positive cache page size"))?; let max_sequence_pages = std::num::NonZeroU64::new(context.div_ceil(logical_page_tokens.get())) .expect("positive context divided by positive page size is non-zero");
- Verified behavior: In
Subtract / Simplify
- Take
NonZeroU64(instead ofOption<NonZeroU64>) in privateNativeModel::prepare_offload(helios/src/runtime_core/model.rs:1052,1125,1172):prepare_offloadis private (unsafe fn), its sole production call site passesSome(planned.max_sequence_pages), and only the two early-returning unit tests (model.rs:1562,1574) passNone. KeepingOption<NonZeroU64>only onPrepareInputs(for library callers) avoids redundantOptionwrapping at the private Helios boundary.
Nits
helios/src/runtime_core/memory.rs:34,999andhelios/src/runtime_core/model.rs:1125: Ause std::num::NonZeroU64;import matches crate convention and avoids repeating the full path.helios/src/runtime_core/memory.rs:2453:512u64.min(max_sequence_pages)withmax_sequence_pages = 128evaluates tomax_sequence_pagesdirectly; passingmax_sequence_pages(or assertingcapture_growth(&layout, 512, reserved, 0, 1).is_none()alongside the clamped call) makes the test intent sharper.
Dropped on verification
- Upstream Code Correctness F2 ("
pages.min(max_sequence_pages.get())inplanned_offload_hostatmemory.rs:1554-1560is a provable no-op; replaceSome(tier_host.max(chain_bytes))withSome(tier_host)"): Verified false (and applying its suggested fix would break pool-only startup).tier_hostis an immutableu64computed once atmemory.rs:1126-1138fromminimum_pages(capture.then_some(minimum_pages)) and is never mutated bycapture_growth. Whenever host RAM letscapacities()(memory.rs:1478-1492) selectpages > minimum_pages(e.g.minimum_pages = 512,max_sequence_pages = 16,384,pages = 99,008,intake_slots = 144,row_slots = 2),chain_bytes = (16,384 + 2) * page_record_bytes >> tier_host = (512 + 2) * page_record_bytes. PassingSome(tier_host)asplanned_host_budgettoprepare_offload->headroom_innerwould fail startup withhost budget cannot hold a full pool capture. - Upstream Discovery Dossier Amendment 3, Gates Audit Nit 1, and Subtraction Item 3 ("Round 1 Should Fix is closed" / "
page_tokens != 0is guaranteed bymemory.rs:896-899"): Verified false.memory.rs:896-899checksself.server_config["page_tokens"], notcontract.cache.page_tokens, andPreparedContract::validatedoes not run until afterNativeModel::load_agreeingreturns. - Upstream Discovery Dossier Amendment 7 & Gates Audit Nit 2 ("Base drift: branch is still on pre-
#713f46a9922and needs rebase onto012219a1"): Verified false on the branch history:66d6af33is already directly on top of012219a1(LinuxMemInfois present atmemory.rs:1568); only the PR description text still citesf46a99220a(not a review issue). - Upstream Subtraction Items 1, 2, 5 (extracting pre-existing
minimum_pageshelper; adding acapture_slotshelper / sharedchain_pageslocal; editingdocs/prefix-cache-offload.md:1605-1606): Dropped as out-of-scope refactoring on Round 2+ (minimum_pagesduplication at:704/:1001is pre-existing;pagesat:1490and:1556are distinct variables in different scopes and a newLayoutbyte/slot helper was already dropped in Round 1; "copies the full GPU chain" at:1605-1606accurately describes a single sequence's chain). - Upstream process/evidence escalations (unobservable CI runs, non-head RSS telemetry provenance,
#737merge-order overlap): Non-blocking per review calibration; provenance and unrun checks are transparently disclosed and#737overlap is routine rebase coordination.