Recommendation: Ready To Merge
Commit f26d8a8 resolves the sole remaining Should Fix from Rounds 1–2: helios/src/runtime_core/memory.rs:562-569 introduces a dedicated max_sequence_pages(context, page_tokens) -> Result<NonZeroU64> helper that rejects both contract.cache.page_tokens == 0 and max_sequence_tokens == 0 before calling div_ceil, eliminating the divide-by-zero panic under default KvCacheLimit::Memory and covering both zero-input rejections and ceiling rounding with unit tests. Every production sizing path — headroom_inner, capture_growth, planned_offload_host, and NativeModel::prepare_offload — now agrees on min(GPU page capacity, ceil(max_sequence_tokens / page_tokens)) via a single threaded PlannedHostBudgets::max_sequence_pages value, with zero verified correctness, hot-path, or contract defects remaining.
Merge Risk
Level: Low
- Small, localized startup-only change (+105/−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. - Already sits on current
main(f46a9922); shares adjacent host-budget files (helios/src/runtime_core/memory.rs,model.rs,selene/src/offload.rs) with open PR #737, requiring only routine rebase coordination if #737 lands 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 forwardinginputsintact toheadroom_inner(:706).helios/src/runtime_core/memory.rs: Addsmax_sequence_pages: std::num::NonZeroU64toPlannedHostBudgets(:34, :1602), guards bothpage_tokens == 0andcontext == 0insidefn max_sequence_pages(:562-569, called at :1007 after the> 0filter at :1004), passesSome(max_sequence_pages)to initialheadroom_with_inputs_for_budgetwithout double-clampingminimum_pages(:1141-1143), and clampspages.min(max_sequence_pages.get())incapture_growth(:1497) andplanned_offload_host(:1563-1566).helios/src/runtime_core/model.rs: ThreadsSome(planned.max_sequence_pages)fromallocate_cachesintoprepare_offload(:1047-1053, :1125) and directly intoPrepareInputs(:1172), removing duplicateserver_config["max_sequence_tokens"]parsing.docs/prefix-cache-offload.md: Updates the pool-only capture buffer section (:1593-1609) to document themin(GPU page capacity, ceil(max_sequence_tokens / page_tokens))chain cap and capped minimum-capacity startup failure behavior.- Tests (
selene/src/offload/tests.rs,helios/src/runtime_core/memory.rs, and existing fixtures): Folds(512, NonZeroU64::new(64))intopool_only_sizes_registered_capture_and_headroom_for_local_ranks(selene/src/offload/tests.rs:531-574), addspool_capture_growth_caps_at_max_sequence_pages_without_throttling_gpu_pagescovering zero-input errors, ceiling division, andpages == uncapped_pagesparity (memory.rs:2452-2476), and setsmax_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. Sits cleanly on
main(f46a9922); only minor adjacent overlap with open PR #737. - [WARN] Tests & verification evidence: Author reports all six workspace crates passing in
--locked --releaseunderRUSTFLAGS="-D warnings"onf26d8a8; live RSS telemetry (18.74–19.06 GiBvs7.83–8.04 GiB) comes from av0.6.0(f705086) build running the same sizing rule, and CUDA/integration/Windows/formal suites were not run on head (all transparently disclosed).
Blockers
None.
Should Fix
None.
Subtract / Simplify
- Optional follow-up — accept
NonZeroU64directly in privateNativeModel::prepare_offload(helios/src/runtime_core/model.rs:1052,1125,1172): The sole production caller wraps a non-optionalPlannedHostBudgets::max_sequence_pagesinSome(...), while only two early-returning unit tests (model.rs:1562,1574) passNone. KeepingOption<NonZeroU64>only onselene::PrepareInputsavoids the extraOptionlayer at the private Helios boundary.
Nits
helios/src/runtime_core/memory.rs:34,562-567andhelios/src/runtime_core/model.rs:1125: Ause std::num::NonZeroU64;import matches crate convention and avoids repeating the full path.
Dropped on verification
- Upstream Code Correctness Minor 2 ("
chain.max(intake_slots(...)).min(budget)atselene/src/offload.rs:178-180can return fewer slots thanchainwhenchain <= budget < intake_slots"): Verified mathematically false. Line175enforceschain <= budget, so whenchain <= budget < intake_slots,chain.max(intake_slots) == intake_slotsandintake_slots.min(budget) == budget >= chain. The expression can never fall belowchainand is algebraically identical to the audit's proposed rewritechain.max(intake_slots.min(budget))for allchain <= budget. - Upstream Code Correctness Minor 1 ("evaluating
max_sequence_pages()unconditionally atmemory.rs:1007adds new hard load failures whenmax_sequence_tokens == 0orcontract.cache.page_tokens == 0"): Dropped.PreparedContract::validate(helios/src/model/contract.rs:536),catalog::validate(helios/src/model/catalog.rs:46,51), andScheduler::new(helios/src/scheduler.rs:739(not opened)) already unconditionally reject bothmax_sequence_tokens == 0andpage_tokens == 0on every served model (describe.rs:151is only the offline inspector's optional vision summary). Enforcing both invariants beforediv_ceilinallocate_cachesis strictly safer defense-in-depth and directly satisfies Rounds 1–2 feedback. - Upstream Code Correctness Residual Risk ("two workers on the same
--prefix-cache-poolwith differentmax_sequence_tokenscould fail to receive records into the smaller capture buffer"): Verified non-applicable.server_config["max_sequence_tokens"]is baked into the signed core protobuf alongside theoffload_identitydigest (helios/src/runtime_core/model.rs:1353-1374), and in pool-only mode restores copy from the shared pool mapping to the GPU viapool.start_copies(selene/src/offload.rs:855-857) rather than allocating in the local outbound capture buffer. - Upstream Subtraction S1–S7 (dropping
page_tokens == 0guard, mergingmax_sequence_pagesintopage_ceiling, extractingcapture_chain_bytes, makingPrepareInputs::max_sequence_pagesnon-optional, re-parsing inmodel.rs, claimingselene/src/offload/tests.rs:556is tautological, and editing pre-existing doc wording at:1605-1606): Dropped. S1 repeats the false premise thatPreparedContract::validateruns beforeallocate_caches; S5 contradicts Round 1's acceptedPlannedHostBudgetsthreading; S6 is factually false becausebuffer.slot_count()atselene/src/offload/tests.rs:563comes from productionprepare_with_inputs(removing the production clamp fails theassert_eq!immediately); and S2/S3/S4/S7 are non-blocking style/refactor preferences out of scope for Round 3 convergence. - Upstream process/evidence escalations (unobservable CI check runs, non-head RSS telemetry provenance,
#737merge-order overlap, PR body phrasing): Non-blocking per review calibration; provenance and unrun checks are transparently disclosed and all six workspace crates were re-verified onf26d8a8.