Review: PR #582 (helios: avoid splitting prefill on zero-budget checkpoint anchors) — conventions and duplication lens
Key findings
No blocking issue. The change is conventional where it matters: the new mutation registration in verification/helios-lifecycle/check.py copies the existing entries exactly, the new CheckpointAccounting field follows the existing reset path, and the new early return preserves the "always carry a prefill price" contract of the function's other early returns (details in "Checked and clean" below).
The real problems are both duplication of the same rule in multiple places:
- One specification, four copies, three updated. The anchor-selection paragraph lives in
helios/README.md,docs/cli-design.md,docs/core-design.mdanddocs/scheduling-runtime-design.md. This PR updates three and leaveshelios/README.md:372-379contradicting the code on both new rules. - One definition became three derivations.
LiveRequest::checkpoint_anchor()used to be the anchor. The PR adds a memoized re-derivation incheckpoint_selection_uncached, a second re-derivation inline inplan_checkpoints, and a third inis_request_anchor_endpointthat prices a different interval. anchor_split_is_zero_costduplicates the split-price expression already inline in the candidate loop, minus its interval cache, and with a different unknown-cost policy.- A fourth completion-record test driver was added rather than reusing one of the three that exist.
Severity ordering below is: the README contradiction first (a one-file docs fix any reviewer can confirm from the diff), then the anchor-triplication, then the split-price and test-driver duplicates, then three nits.
Should fix
1. helios/README.md:372-379 states the anchor rule and was not updated — it now contradicts the code on both new rules
The rule is stated four times in the tree. This PR updates three:
docs/cli-design.md:700-711(+7/−4)docs/core-design.md:1435-1445(+6/−4)docs/scheduling-runtime-design.md:551-561(+5/−3)
and leaves the fourth unchanged. helios/README.md:372-379 still reads:
"Checkpoint selection prioritizes the last eligible message boundary, using the prompt end when no message boundary is eligible. Earlier messages and a distinct prompt end compete within a work allowance of
scheduler_checkpoint_extra_work_fractiontimes estimated uncached prefill work, defaulting to 0.05. …Unknown costs exclude extras while preserving best-effort anchor retention."
Both halves of that are now false:
- Zero capacity emits no cuts at all —
checkpoints.rs:460-462returns before anyCutis pushed, so "using the prompt end when no message boundary is eligible" no longer holds whenlimits.snapshots == 0. - Zero fraction changes which endpoint is the anchor — at
checkpoints.rs:467-511, whenraw_anchor < prompt_tokens && checkpoint_extra_work_fraction == 0.0, an interior boundary is kept only ifanchor_split_is_zero_cost; otherwise the anchor becomesrequest.prompt_tokens. The README says nothing about this and instead says "last eligible message boundary" unconditionally.
Why it matters: helios/README.md is the runtime's own front-door description, and this paragraph is the described contract for --scheduler-checkpoint-extra-work-fraction (its sibling text immediately cross-references ../docs/core-design.md#exact-endpoint-capture at line 383). A reader who trusts the README will expect a padded interior cut at fraction 0 — precisely the bug this PR removes.
Precedent for keeping these copies in lock-step: the neighbouring checkpoint PRs update the shared prose together — #568 ("Bound optional Endpoint checkpoint eviction…", 5 shared files), #550 ("Restore prefix checkpoints on prefill catalogs without terminal prefill"), #426. docs/api.md:696 is fine as is: it only cross-references core-design for anchor priority.
Fix: port the two conditions into helios/README.md:372-379 with the wording used in docs/cli-design.md:703-709, or replace the paragraph with a cross-reference to docs/core-design.md#exact-endpoint-capture.
2. checkpoints.rs:390-420, :467-511, :671-685 — the effective anchor is derived three times, from three different intervals
Before the PR there was one definition of the anchor for a live request — LiveRequest::checkpoint_anchor() — consumed by selection, by plan_checkpoints, by promote_request_anchor, and by the inbound role classification. The PR adds two competing derivations:
checkpoint_selection_uncached(checkpoints.rs:467-511) computes the effective anchor and records it inaccounting.anchor_fallback_from.plan_checkpoints's closure (checkpoints.rs:671-685) re-derives it from that memo: take theAnchorcut's endpoint, elseaccounting.anchor_fallback_from == Some(raw_anchor) ? request.prompt_tokens : raw_anchor.is_request_anchor_endpoint(checkpoints.rs:390-420) re-derives it a third time, for the inbound ticket role (scheduler.rs:1794) and forpromote_request_anchor(checkpoints.rs:763), with a different pricing interval: it prices0..prompt_tokens(line 415), whereas selection pricesstart..prompt_tokens(line 478) orbaseline_start..prompt_tokens(line 495). It also consumes the memo only as theSome(raw_anchor)early accept at line 402, so on the inbound path — which runs during admit, before any planning — it must recompute from the catalog.
Consequences visible in the code:
- The path is observable enough that the new test has to assert it separately:
zero_fraction_aligned_interior_anchor_and_mixed_prefill_preserve_exact_contracts(checkpoints.rs:2726) drives Part A throughcomplete_test_stepto exercise promotion/Snapshotreuse while Part B checks selection directly. - Two verdicts for the same request/endpoint pair can disagree whenever selection's interval (
start..promptorbaseline_start..prompt) prices differently from the whole-prompt interval0..prompt— i.e. for requests whoseconsumed_tokens != 0or whose baseline starts past 0 (restored, re-admitted, or prefix-reused requests), which are exactly theRestore/Speculativecases this PR claims to preserve.
Fix: one fn effective_anchor(&self, request, start, baseline) -> usize that selection, the plan_checkpoints closure, the inbound classification and promote_request_anchor all call, reusing anchor_fallback_from rather than re-pricing. That also deletes the closure at checkpoints.rs:675-683.
Caveat stated honestly: I did not construct a runnable case where the three derivations disagree with observable effect. What would settle it is a test that admits an inbound ticket (scheduler.rs:1794) for a zero-fraction request with consumed_tokens > 0 whose interior boundary prices zero over consumed..prompt but not over 0..prompt (or the reverse), and asserts the ticket role matches the eventual capture.
3. checkpoints.rs:364-388 — anchor_split_is_zero_cost duplicates the candidate-loop split price with different caching and unknown-cost handling
The new helper is a near-copy of the expression already inline in the selection loop at checkpoints.rs:557-591:
let split = if endpoint == right { Some(0) } else {
let whole = match between { Some((interval, nanos)) if interval == (left, right) => nanos, _ => … };
whole.and_then(|whole| {
let before = interval_prefill_ns(request, &catalog, terminal_window, left, endpoint)?;
let after = interval_prefill_ns(request, &catalog, terminal_window, endpoint, right)?;
Some(before.saturating_add(after).saturating_sub(whole))
})
};
anchor_split_is_zero_cost computes the same before + after - whole and compares to zero. Three differences matter:
- No interval cache. The inline version caches
betweenso a run of candidates inside one interval priceswholeonce (:560-573). The helper has none, and it is called up to twice per selection (:474and:491) on intervals selection is about to price again immediately afterwards;is_request_anchor_endpoint(:411) prices0..prompta third time on the inbound path. Since the whole point ofprefill_catalog_costs(doc commentcheckpoints.rs:160-162: "Selection reads the costs once instead of once per chunk of every interval") and ofreference_interval_prefill_ns(:1023, introduced to cross-check the pricing walk) is one pricing path, adding a second uncached walk works against both. - Different unknown-cost policy. The inline version propagates
Option: unknown ⇒unknown = true, candidate skipped, andstats.checkpoint_skip_unknown_costincremented (:592-595,:782). The helper flattens every unknown intofalse— "not zero cost" — at:375,:381,:386, so an unmeasured catalog now silently changes which endpoint becomes the anchor instead of merely skipping extras, and nothing is counted incheckpoint_skip_unknown_cost. That may be the intended conservative choice, but it is an unstated semantic difference between two copies of the same arithmetic, and it is invisible in stats. - Precomputed
known_whole. The helper takes it as a parameter; selection already threadsaccounting.initial_prefill_nsin (:471-473,:498-500). Fine in itself, but it means each call site re-implements the "when isinitial_prefill_nsthe rightwhole" test ((start, prompt) == (baseline_start, baseline_end),baseline_end == prompt_tokens).
Fix: one fn split_prefill_ns(request, catalog, terminal_window, left, endpoint, right, known_whole) -> Option<u64> used by both the candidate loop and the zero-cost test, with == 0 compared at the call site, and unknown handled in one place.
4. checkpoints.rs:1942-2018 — complete_test_step is a fourth completion-record test driver
Three helpers already build CompletionRecords from a ScheduledPlan:
helios/src/scheduler/policy_tests.rs:162 completion_records+:219 complete_timed(takesacceptedandpublish, finishes completed requests);helios/src/scheduler/boundary_tests.rs:93 run_step(derivesFence(s.submitted.0 + 1)itself);helios/src/scheduler/checkpoint_lifecycle_tests.rs:94 complete_records(projection-oriented).
The new checkpoints.rs:1942 complete_test_step re-implements the same emitted/consumed/status logic, adds output publication, and takes dur_ns for ExecutionTiming.gpu_ns[0]. It is closest to complete_timed. Two conventions depart:
- It hardcodes speculative acceptance at 3 (
GraphKind::Speculative => 3.min(lane.tokens).min((r.max_new_tokens - r.generated_tokens) as usize),:1959-1961) wherepolicy_teststakesacceptedas a parameter. That couples the balanced-batch test (balanced_c16_short_prompts_skip_interior_anchor_tails_and_reach_full_batch,:2450) toenable_speculation(&[1, 2, 4, 8])widths. - It duplicates
consumedbookkeeping thatpolicy_tests.rs:182-186already encodes (one branch forSpeculative, one for the rest), exceptcheckpoints.rs:1969-1973adds a third branch forInit|Restore|Snapshot|Vision.
Fix: hoist one shared driver (a natural home is helios/src/scheduler/tests.rs, which already shares duration_graphs at :157 and scheduler() across all four modules) and parameterise accepted; or at minimum take accepted as a parameter here.
Nits
5. New tests hand-build GraphDescriptors that extra_graphs() already builds
zero_fraction_falls_back_to_prompt_end_when_interior_anchor_splits_prefill (checkpoints.rs:2382-2398) rebuilds a scheduler with RequestScheduler::new(…, SchedulerLimits{..template.limits}, template.capabilities.clone()) and pushes hand-written descriptors for the two larger prefill capacities. The graph closure in extra_graphs() (checkpoints.rs:1094-1116) builds exactly that shape (tuned_bindings, confidence_width, draft_tokens, packed_token_capacity, sampling_mode, prefill_capacity), 1,250 lines above in the same file. Likewise Part C of zero_fraction_aligned_interior_anchor_and_mixed_prefill_preserve_exact_contracts (:2793+) hand-builds a GraphKind::Mixed descriptor that extra_graphs() already provides (:1114 graphs.push(graph(GraphKind::Mixed, 2, 1, 512))), and walk_scheduler (:1118-1138) already registers it via mixed_graphs(&[(2, 1, 512)]). Consequence: adding a field to GraphDescriptor now requires edits in four places in this file.
6. Duplicated catalog + terminal_window derivation
checkpoints.rs:405-410 (is_request_anchor_endpoint) and :445-450 (checkpoint_selection_uncached) are character-identical:
let terminal_window = if request.prompt_logprobs { 0 } else { self.terminal_prefill_window() };
The sibling catalog choice (request.prompt_logprobs ? scored_prefill_catalog : prefill_catalog) is likewise duplicated between prefill_catalog_costs (:163-168) and the new function's call. A single fn pricing_inputs(&self, request) -> (Vec<PrefillCatalogCost>, usize) would state once the invariant "scored-prefill requests price with no terminal window" and remove the risk of the two drifting — the same motivation that the prefill_catalog_costs doc comment gives for its own existence.
7. The three updated docs name one object three ways; cli-design.md inserts the sentence mid-paragraph
docs/cli-design.md:703: "the last eligible message endpoint"docs/core-design.md:1436-1441: "the last eligible complete-message boundary" / "interior message boundary"docs/scheduling-runtime-design.md:555-558: "the last eligible completed message" / "interior message boundary"
The code calls these message_boundaries / checkpoint_endpoint_eligible. Pick one term. Separately, docs/cli-design.md:700-711 puts "Zero snapshot capacity disables all checkpoint cuts." between the anchor rule and "Earlier messages and a distinct prompt end consume the fraction…", breaking the paragraph's anchor → extras → accounting order; core-design.md gets the ordering right (anchor rule, then zero capacity, then earlier boundaries). Move the sentence to the end of the paragraph in cli-design.
Checked and clean (no finding)
- Mutation registration.
verification/helios-lifecycle/check.py:325-343registers the new mutation underCHECKS[7][1](CheckpointReservation) viacheck_mutations, matching the pattern of the existing entries at:296and:318; the staleness guard atcheck.py:95covers the new needle. - Early return shape.
checkpoint_selection_uncached's newif self.limits.snapshots == 0 { return (accounting, false, false) }(checkpoints.rs:460-462) sits afterinitial_prefill_nsis computed, so the returned accounting still carries a prefill price like the other early returns (:520-525), and the(accounting, bool, bool)tuple shape is unchanged. - Accounting field lifecycle.
anchor_fallback_from(checkpoints.rs:28) is cleared inclear_reservations(:49), the single reset point used by admission (scheduler.rs:1726) — consistent withbaseline_interval/cuts. - Type conversions.
is_request_anchor_endpointtakesendpoint: u64whilecheckpoint_anchor()/prompt_tokensareusize; call sites convert (scheduler.rs:1794,checkpoints.rs:763), matching the pre-existingconsumed_tokens as u64idiom in the same file. docs/api.mdonly cross-references core-design for anchor priority (:696), so it correctly needs no edit — this is the model the README finding (#1) should follow or match.
Open questions
- For finding #2: is there a reachable request state where
is_request_anchor_endpoint's0..promptpricing and selection'sstart..prompt/baseline_start..promptpricing disagree about the same endpoint? A test admitting an inbound ticket for a zero-fraction request with nonzeroconsumed_tokenswould settle it; nothing in the diff does. - For finding #3: is flattening unknown costs to "not zero" (thus flipping the anchor to the prompt end) intended policy, and should it be counted in
stats.checkpoint_skip_unknown_cost? Only the author can confirm intent; the code cannot.
What I could not verify
Live signed-core serving and GPU latency numbers are, as the description itself notes, unmeasured — out of scope for this lens and unchanged by these findings. Everything above is derived from the code at head a3c6483; no runtime behaviour claims are made.