Recommendation: Changes Requested
The core pool-only capture-buffer bound in selene/src/offload.rs, helios/src/runtime_core/memory.rs, and helios/src/runtime_core/model.rs is sound: planning, binary-search growth charging, planned_offload_host, and final slab allocation agree on min(GPU page capacity, ceil(max_sequence_tokens / page_tokens)), and the docs and unit tests accurately match the implementation. One verified defect warrants a small fix before merge: the new context.div_ceil(contract.cache.page_tokens as u64) lines in memory.rs:996 and model.rs:1155-1157 are unguarded against contract.cache.page_tokens == 0 (turning a previously clean Err(invalid(...)) into an unconditional divide-by-zero panic under the default KvCacheLimit::Memory mode) and against context == 0 (which creates a 0-vs-uncapped mismatch with selene). Guarding those inputs and threading max_sequence_pages through PlannedHostBudgets resolves the defect cleanly.
Merge Risk
Level: Low
- Small, localized startup-only change (+115/−10 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 a local memory or disk tier and multi-host sharded ranks are unaffected. - Overlaps with open PR #737 in
selene/src/offload.rs,helios/src/runtime_core/memory.rs, andhelios/src/runtime_core/model.rs(host-budget accounting); coordinate merge/rebase order if #737 lands first.
Walkthrough
selene/src/offload.rs: Addspub max_sequence_pages: Option<u64>toPrepareInputs(:340-347), clampschain_pagesinheadroom_innertopages.min(limit)whenSome(limit)withlimit > 0(:165-169), and updates the destructure inprepare_with_inputs_budget_with_progress(:628) while forwardinginputsintoheadroom_inner(:704-710).helios/src/runtime_core/memory.rs: Computesmax_sequence_pages = context.div_ceil(contract.cache.page_tokens as u64)(:996), passesSome(max_sequence_pages)andminimum_pages.min(max_sequence_pages)into initialheadroom_with_inputs_for_budget(:1130-1132), and clampspages.min(max_sequence_pages)in bothcapture_growth(:1486) andplanned_offload_host(:1553).helios/src/runtime_core/model.rs: Derivesmax_sequence_pagesfromself.server_config["max_sequence_tokens"]andcontract.cache.page_tokens(:1155-1157) and passes it toprepare_with_inputs_budget_with_progress(:1168), wherelocal_pagesis the actual allocated GPUpage_capacity.docs/prefix-cache-offload.md: Updates the pool-only capture buffer section (:1593-1603) to document the single-sequence chain cap and capped minimum-capacity startup failure behavior.- Tests (
selene/src/offload/tests.rs,helios/src/runtime_core/memory.rs, and existingPrepareInputstest fixtures): Addspool_only_caps_capture_buffer_to_max_sequence_pagesandpool_capture_growth_caps_at_max_sequence_pages_without_throttling_gpu_pages, and setsmax_sequence_pages: Noneacross existing test 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 HTTP/routing/disaggregation surface.
- [PASS] Related / duplicate / conflict check: Not a duplicate; carves out only the #455 pool-only capture bound from closed #718. Open PR #737 touches adjacent host-budget code in
selene/src/offload.rs,memory.rs, andmodel.rs(rebase coordination only). - [WARN] Tests & verification evidence: Author reports all six Rust crates passing in
--locked --releaseon02990da; live RSS telemetry (18.74–19.06 GiBvs7.83–8.04 GiB) was collected on av0.6.0(f705086) build carrying the same patch rather than re-measured A/B on02990da, and hardware CUDA /tests/server/test_prefix_cache_offload.py(not opened) /qualify/host_cache.py(not opened) were not run on head (all transparently disclosed).
Blockers
None.
Should Fix
- Unguarded
div_ceil(contract.cache.page_tokens as u64)panics on zeropage_tokensand mishandlescontext == 0under defaultKvCacheLimit::Memory(helios/src/runtime_core/memory.rs:992-996,helios/src/runtime_core/model.rs:1155-1157)- Verified behavior: In
allocate_caches(memory.rs:995-996),page_ceilingreturnsOk(None)immediately whenoptions.kv_cache_limit == KvCacheLimit::Memory(the#[default],memory.rs:567-569), bypassing itsif context == 0 || contract.cache.page_tokens == 0check atmemory.rs:570. Becausecontractis deserialized fromself.server_config["model_contract"]atmemory.rs:899-901without callingPreparedContract::validate(),context.div_ceil(contract.cache.page_tokens as u64)atmemory.rs:996now runs unconditionally on every load (even with offload disabled) and panics with division by zero whencontract.cache.page_tokens == 0, whereas before this PRcache_geometry→CacheGeometry::validate()(selene/src/geometry.rs:114) returned a cleanErr(invalid(...)). The same unguardeddiv_ceilappears atmodel.rs:1155-1157. In addition, ifcontext == 0underKvCacheLimit::Memory,memory.rs:996computesmax_sequence_pages = 0, which clampsmemory.rs:1132,1486,1553to0pages whileselene/src/offload.rs:165-168treatsSome(0)as uncapped (pages), causing planning and preparation to disagree. - Fix: Validate both
context != 0andcontract.cache.page_tokens != 0inmemory.rs:992-996, returningErr(invalid(...))before callingdiv_ceil(matchingmemory.rs:570,696,897). Then either thread the validatedmax_sequence_pagesintoprepare_offloadviaPlannedHostBudgets(see Subtract / Simplify #1) or add the matching non-zero guard inmodel.rs:1155-1157.
- Verified behavior: In
Subtract / Simplify
- Thread
max_sequence_pagesthroughPlannedHostBudgetsinstead of recomputing it inmodel.rs(helios/src/runtime_core/memory.rs:32-35,1589-1592,helios/src/runtime_core/model.rs:1038-1047,1113-1168):allocate_cachesalready returnsPlannedHostBudgetsdirectly toprepare_offload. Passingmax_sequence_pagesthere eliminates the duplicateserver_config["max_sequence_tokens"]/div_ceillogic inmodel.rs:1155-1157as well as thememory.rs(error on missing) vsmodel.rs(silentNone/uncapped fallback) asymmetry. - Remove the redundant clamp at
helios/src/runtime_core/memory.rs:1132:headroom_with_inputs_for_budgetreceivesmax_sequence_pages: Some(max_sequence_pages)at:1130and already appliespages.min(limit)insideheadroom_inner(selene/src/offload.rs:165-168). Keepingcapture.then_some(minimum_pages)restores the pre-PR line and leaves clamping in a single place. - Avoid dual uncapped sentinels (
NoneandSome(0)) if desired (selene/src/offload.rs:165-168,346): Oncememory.rs:992-996rejectscontext == 0, Helios never passesSome(0). UsingOption<NonZeroU64>(or documenting/keeping onlyNoneas uncapped) removes the redundantlimit > 0branch and the duplicateSome(0)assertion inselene/src/offload/tests.rs:604-614.
Nits
helios/src/runtime_core/memory.rs:2456: Inpool_capture_growth_caps_at_max_sequence_pages_without_throttling_gpu_pages, assertingassert_eq!(pages, 1024)(the synthetic core's fullmaximum_pages) is sharper thanassert!(pages > max_sequence_pages)and directly proves zero GPU page throttling.selene/src/offload.rs:628:..in thePrepareInputsdestructure (instead ofmax_sequence_pages: _) avoids churn whenever another field is added toPrepareInputs.docs/prefix-cache-offload.md:1603: Re-wrap line 1603 (~91 chars) to match the ~80-column paragraph wrapping around it.selene/src/offload/tests.rs:567-621: Could share fixture setup withpool_only_sizes_registered_capture_and_headroom_for_local_ranksright above it (:526-564) to trim ~30 lines of boilerplate.
Dropped on verification
- Upstream Code Correctness F1 ("Major: capture slab is sized from
minimum_pages, undersizing the slab ~4× and livelocking full-context captures"): Verified false.memory.rs:1122-1134callsheadroom_with_inputs_for_budgetonly to compute the initial minimum-capacitytier_hostreservation beforecapacities()selects GPUpages; it does not allocate any slab. Actual slab allocation happens inmodel.rs:1158-1172→selene/src/offload.rs:700-755, wherelocal_pagesisgeometry.iter().map(|rank| rank.page_capacity).max()(the allocated GPU page capacity, e.g.99,008) andhost_budgetisplanned_offload_host(memory.rs:1550-1556, computed frompages.min(max_sequence_pages)). Both allocate and budgetmin(allocated_pages, max_sequence_pages) + row_slots. - Upstream Value Proposition ("automatic-intake floor
intake_slotsleft uncapped"): Intentional design, explicitly documented in both the PR description anddocs/prefix-cache-offload.md:1594-1597so concurrent publication bursts retain adequate streaming slots. - Upstream Contracts Nit 1 ("
docs/prefix-cache-offload.md:1596loosely saysGPU page capacityinstead ofminimum_pages"): Verified false. Lines 1595-1597 describe the capture buffer's slot count (which uses allocated GPUpage_capacityviamodel.rs:1158→offload.rs:700), while lines 1600-1602 separately and accurately describe the "capped minimum page capacity" startup check (memory.rs:1132). - Upstream Subtraction Item 4 ("add
Layout::chain_record_byteshelper onselene::Layout"): Not worth adding new public API surface toselene::Layout—offload.rs:169operates in slots (not bytes) andcapture_growthvsplanned_offload_hostintentionally usechecked_*vssaturating_*arithmetic. - Upstream process/evidence escalations (unobservable CI checks on head, requiring A/B RSS re-measurement on
02990da, or blocking on #737 merge order / #455 provenance): Dropped from Blockers/Should Fix per review calibration; the change addresses a measured memory issue within Charter scope, discloses its evidence provenance and unrun checks honestly, and the sizing math is verified by unit tests on head.