Code review summary report · NVIDIA/hyperflare-inference #582

Raw Markdown for agents: https://autobot.eidonix.com/p/80a85d28-62e0-4fe9-9ba3-264ff64c8c9c.md

Candidate Brief — PR #582 helios: avoid splitting prefill on zero-budget checkpoint anchors

Head a3c648351c9c364099c57479eba858a7fd33998a, base main, 7 files, +931/−16 (production ≈110 lines, tests ≈646, docs 19, check.py 19). Author FujitsuPolycom. Thread contains exactly two comments — voipmonitor CHANGES_REQUESTED (2026-11-28 22:13) and a flare-autobot case-file notice — and no author rebuttal; nothing is resolved. All quotes below were re-opened at the PR head by me, not taken from a lens report.


Key findings

  1. One decision, three pricing origins. "Is this request's anchor the interior message boundary or the prompt end?" is answered from consumed_tokens, from baseline_start, and from a literal 0 in three code paths, and the answer is latched into a mutable accounting field. This single root cause produces both of voipmonitor's duplicate-Anchor defects (B1, B3).
  2. The latch is destroyed on the one path documented to preserve accounting. clear_reservations() (new line 49) nulls the verdict at every readmission, which is exactly why the redundant re-pricing branch exists (B2). The proposed one-line simplifications in two lenses each fail unless B1 and B2 are fixed together.
  3. Evidence bar unmet for a scheduler/pricing change. docs/design-review.md:195-206, :234-240, :106-115 require the scripts/scheduling_sim sweep and served measurements; the PR supplies CPU unit tests, the simulator's own unit tests, and check.py --mutations, and states live serving is "unverified" (B4).
  4. Docs are half-updated. Three design docs were edited; helios/README.md:372-379 — the flag's front-door contract — was not, and is now false on both new rules. Two unchanged sentences a few lines below each edit now contradict the new rule (S1).
  5. ~44% of the diff (~410 of 931 added lines) is removable without losing any behaviour the PR exists for: one resolved_anchor() replaces four representations, and three of five new tests plus a duplicated 75-line test driver go.

Note for the adjudicator (two lens conflicts already resolved; do not re-litigate)


Candidate Blockers

B1. The anchor verdict is priced from different interval origins, so it can flip mid-request and emit a second Anchor

Sources: architecture #3, simplicity F1+F2, correctness #1, conventions #2, subtractive #1, reviewer blockers 1–2.

helios/src/scheduler/checkpoints.rs:467-507:

467  let anchor = if raw_anchor < request.prompt_tokens
468      && self.policy.checkpoint_extra_work_fraction == 0.0
469  {
470      if raw_anchor > start {
471          let known_whole = ((start, request.prompt_tokens) == (baseline_start, baseline_end))
472              .then_some(accounting.initial_prefill_ns)
473              .flatten();
474          if Self::anchor_split_is_zero_cost(
475              request, &catalog, terminal_window, start,
479              request.prompt_tokens, raw_anchor, known_whole,
482          ) {
483              accounting.anchor_fallback_from = None;
484              raw_anchor
485          } else {
486              accounting.anchor_fallback_from = Some(raw_anchor);
487              request.prompt_tokens
488          }
489      } else if accounting.anchor_fallback_from == Some(raw_anchor)
490          || (baseline_start < raw_anchor
491              && !Self::anchor_split_is_zero_cost(
495                  request, &catalog, terminal_window, baseline_start,
496                  request.prompt_tokens, raw_anchor,
498                  (baseline_end == request.prompt_tokens)
499                      .then_some(accounting.initial_prefill_ns)
500                      .flatten(),
501              ))
502      {
503          accounting.anchor_fallback_from = Some(raw_anchor);
504          request.prompt_tokens
505      } else {
506          raw_anchor
507      }

with start = request.consumed_tokens as usize (moves every chunk) and baseline_interval fixed at admission. Branch A prices [consumed_tokens, prompt); branch B prices [baseline_start, prompt); is_request_anchor_endpoint prices [0, prompt) (B3).

The helper mixes a cached whole against freshly priced halves — the mechanism of the EWMA-drift defect (checkpoints.rs:373-387):

373  let Some(whole) = known_whole
374      .or_else(|| Self::interval_prefill_ns(request, catalog, terminal_window, start, end))
375  else { return false; };
378  let Some(before) =
379      Self::interval_prefill_ns(request, catalog, terminal_window, start, anchor)
380  else { return false; };
383  let Some(after) = Self::interval_prefill_ns(request, catalog, terminal_window, anchor, end)
384  else { return false; };
387  before.saturating_add(after).saturating_sub(whole) == 0

Consequence: request commits and publishes an Anchor cut at raw_anchor (:512-519), then after prefill passes the boundary (or a re-admission shortens the window) branch B re-prices over the longer interval, decides the split is expensive, and pushes a second Anchor at prompt_tokens — the duplicate the PR description claims to rule out. voipmonitor reproduced both variants live at 4×SM120 (DeepSeek-V4.1-Flash TP4, fraction 0): upward EWMA drift (prompt=1024, boundary 512, cost 512_000 ns, jitter 515_000 → EWMA 512_300, then 600 ≠ 0) and a Mixed alignment shift (prefill_catalog=[128,512], mixed=[(2,1,256)], raw_anchor=768: anchor 1024 → 768 → 1024).

Why the suite passes: linear_costs = capacity * 1_000 ns (checkpoints.rs:1009-1019) and complete_test_step commits dur_ns = 1_000; checkpoint_lifecycle_tests.rs:281-285 sets every graph estimated_duration_ns = 1_000. EWMA stays far below the measured cost and saturating_sub clamps to 0. Nothing in the suite crosses start != baseline_start.

Fix: one stable decision priced once over the admission interval (baseline_start, prompt_tokens), stored as an explicit field, read by selection, plan_checkpoints, is_request_anchor_endpoint and promote_request_anchor (see X1). Regression tests need measured costs above the chunk interval and an explicit assertion on the number of Anchor-role captures.

B2. The latched decision is destroyed by clear_reservations() on a path documented to preserve the request's accounting

Sources: architecture #5, simplicity F3, reviewer Major 4.

helios/src/scheduler/checkpoints.rs:27-28, 48-52:

27      baseline_interval: Option<(usize, usize)>,
28      anchor_fallback_from: Option<usize>,
...
48      pub(super) fn clear_reservations(&mut self) {
49          self.anchor_fallback_from = None;
50          self.cuts.clear();
51          self.reserved_ns = 0;
52      }

helios/src/scheduler.rs:1722-1726:

1722  let mut checkpoints = match accounting {
1723      Some(accounting) => accounting,
1724      None => CheckpointAccounting::for_epoch(self.cache.new_use_epoch()?, consumed as usize, spec.prompt.len()),
1725  };
1726  checkpoints.clear_reservations();

The carried accounting deliberately survives preemption parks and inbound-restore retries (helios/src/server/runtime.rs:1424 (not opened)/1437/1449, 2078/2093, 2745/2771/2789/2800/2827), and docs/core-design.md:1456-1457 states: "Preemption preserves the logical request's earned and spent allowance." baseline_interval and initial_prefill_ns both survive; only the new anchor verdict does not, so a readmitted request re-derives its anchor from a fresh consumed_tokens — B1's instability applied to the request's most important checkpoint. A previously captured prompt-end anchor can be orphaned.

AGENTS.md:188-193 (not opened) rejects exactly this kind of hidden coupling. Fix: do not clear the decision here (or set it once at admission); clear_reservations goes back to clearing reservations.

B3. is_request_anchor_endpoint is a second, third-origin price model that can disagree with selection and promote an endpoint selection never chose

Sources: architecture nit, simplicity F4, correctness #2+#3, conventions #2, reviewer Major 3.

helios/src/scheduler/checkpoints.rs:390-419:

390  pub(super) fn is_request_anchor_endpoint(&self, request: &LiveRequest, endpoint: u64) -> bool {
391      let raw_anchor = request.checkpoint_anchor();
392      if endpoint == raw_anchor as u64 { return true; }
395      if self.limits.snapshots == 0
396          || self.policy.checkpoint_extra_work_fraction != 0.0
397          || raw_anchor >= request.prompt_tokens
398          || endpoint != request.prompt_tokens as u64
399      { return false; }
402      if request.checkpoints.anchor_fallback_from == Some(raw_anchor) { return true; }
405      let catalog = self.prefill_catalog_costs(request);
406      let terminal_window = if request.prompt_logprobs { 0 } else { self.terminal_prefill_window() };
411      !Self::anchor_split_is_zero_cost(
412          request, &catalog, terminal_window,
415          0, request.prompt_tokens, raw_anchor, None,
419      )

Pricing from literal 0 can differ from selection's [start, prompt) / [baseline_start, prompt) whenever a split is zero-cost from the frontier but not from token 0 (or reverse); no unknown price is needed for divergence (baseline_start=88, raw_anchor=600, prompt=1024, known catalog [128,512]).

Two observable consequences. (a) Promotion of an endpoint selection never picked — checkpoints.rs:758-767:

758  let id = request
759      .history.key_at(raw_anchor as u64)
760      .and_then(|key| self.cache.ready_by_prefix(&key))
761      .or_else(|| {
762          self.is_request_anchor_endpoint(request, prompt_tokens as u64)
763              .then(|| request.history.key_at(prompt_tokens as u64))
764              .flatten()
765              .and_then(|key| self.cache.ready_by_prefix(&key))
766      });

which leaves Endpoint→Anchor promotion (:768-773) able to stamp a checkpoint as the request's anchor that selection never chose. (b) Inbound ticket role assignment at helios/src/scheduler.rs:1794 inherits the same verdict.

Cost facet (merged here from correctness #2): prefill_catalog_costs allocates a Vec per call (:163-206) and interval_prefill_ns (:208-338) walks window_ends/prefill_spans/catalog; the expensive path runs on every inbound admit (latch guaranteed None at scheduler.rs:1726 → :1794) and on every commit after a genuinely zero-cost interior decision (:483 sets the latch back to None), reached per lane from scheduler.rs:2411:

2411  for lane in &step.lanes { self.promote_request_anchor(lane.request)?; }

This bypasses SelectionCache (checkpoints.rs:11-19) and checkpoint_planning_scope, defeating the module's own one-pricing-path design. Fix: let this function read the stored decision (X1); ~25 lines of pricing disappear and the two call sites cannot disagree.

B4. Evidence does not meet the documented bar for a scheduler/pricing change

Sources: architecture #1. (This is the main judgment call left for the adjudicator — see open questions.)

docs/design-review.md:234-240: "Never touch covered code without running and updating its simulator and formal checks. Modifying the Helios scheduler … without running—and updating when behavior, transitions, or supported bounds change—the applicable TLA+ models, Rust conformance fixtures, Kani harnesses, and scheduling simulator is a blocking design failure, regardless of whether CPU unit tests pass." :195-206 requires graph-selection/pricing changes to be "evaluated against the Python simulator and reference solvers in scripts/scheduling_sim/"; :106-115 (principle 12) requires actual Helios service measurements for a performance claim.

The PR's evidence is CPU unit/lifecycle tests, cargo lib tests, and a pytest run that includes tests/test_scheduling_sim.py (not opened) — the simulator's own unit tests, not a policy sweep — plus check.py --mutations. It states outright: "Live signed-core serving and isolated GPU latency measurements remain unverified." Yet its claimed benefit ("avoids extra padded prefill launches") is a serving-level claim, and the only live numbers in the thread (prefill_steps 2→1 short prompt, 3→2 multi-chunk) came from the reviewer, not the author. check.py --mutations proves model/code sync, not policy quality.

Fix: run the scripts/scheduling_sim screening + 64-seed catalog with the new anchor rule, attach a served before/after (single- and multi-chunk, prefix reuse), and update the simulator's qualified policy in the same PR if it disagrees.


Candidate Should Fix

S1. Documentation: helios/README.md never updated; two stale sentences contradict the new rule; the retention half undocumented; rule paraphrased three ways

Sources: conventions #1, prose #1–#3, simplicity F12+F13, subtractive #5. (Combines the mechanical prose/doc-format notes into one item, per the dedup rule — but the README contradiction is not cosmetic.)

The anchor rule is stated four times in the tree; this PR updates three (docs/cli-design.md:700-711, docs/core-design.md:1435-1445, docs/scheduling-runtime-design.md:551-561) and leaves helios/README.md:372-379 untouched. That paragraph still reads (verified):

372  tokens. Checkpoint selection prioritizes the last eligible message boundary,
373  using the prompt end when no message boundary is eligible. Earlier messages and
374  a distinct prompt end compete within a work allowance of
375  `scheduler_checkpoint_extra_work_fraction` times estimated uncached prefill work,
376  defaulting to 0.05. … Unknown costs exclude extras
379  while preserving best-effort anchor retention.

Both halves are now false: (a) snapshots == 0 emits no cuts (checkpoints.rs:460-462), so "using the prompt end when no message boundary is eligible" fails; (b) at fraction 0 an interior boundary is kept only if the split prices zero (:467-511), so "prioritizes the last eligible message boundary" unconditionally is false. The paragraph is the flag's front-door contract and cross-references ../docs/core-design.md#exact-endpoint-capture at line 383; docs/api.md:696 (not opened) is correctly cross-reference-only and is the model to follow. Precedent: neighbouring checkpoint PRs #568, #550, #426 updated the shared prose together.

Stale sentences left behind by the same edits — each doc now states two incompatible rules ~10 lines apart:

docs/core-design.md:1452-1453
  Unknown prefill costs or unknown or stale snapshot-copy
  costs exclude extras without excluding the anchor.

docs/scheduling-runtime-design.md:570-572
  Unknown prefill costs and
  unknown or stale snapshot-copy costs disable extras while preserving anchor
  eligibility.

Now false at fraction 0 because anchor_split_is_zero_cost returns false on any unknown price (checkpoints.rs:373-386) → interior anchor dropped for the prompt end (:485-488). Note the new text also omits (i) that unavailable pricing, not only positive predicted work, forces the fallback, and (ii) the whole second half of the fix — retention of the prompt-end replacement across multi-chunk progress/Restore/Speculative/promotion (anchor_fallback_from, plan_checkpoints:671-685, promote_request_anchor:753-776, scheduler.rs:1794). Term drift across the three edits: cli-design.md:703 "last eligible message endpoint" vs core-design.md:1436-1441 "last eligible complete-message boundary" vs scheduling-runtime-design.md:555-558 "last eligible completed message"; and cli-design.md:708 inserts "Zero snapshot capacity disables all checkpoint cuts." mid-paragraph, breaking the anchor → extras → accounting order that core-design.md gets right.

Fix: one full statement in docs/core-design.md (add the unknown-pricing condition and the retention sentence), cross-reference from the other two, and port both conditions into helios/README.md:372-379.

S2. Zero budget is a separate regime keyed on exact float equality, with an anchor cut that is never priced

Source: architecture #4.

helios/src/scheduler/policy.rs:208-211 validates a continuous range, while checkpoints.rs:467-468 (and :395-396) branch on exact equality:

208  if !policy.checkpoint_extra_work_fraction.is_finite()
209      || !(0.0..=1.0).contains(&policy.checkpoint_extra_work_fraction) {
210      return Err("checkpoint extra work fraction must be finite and within 0..=1".into());
211  }

Meanwhile the anchor cut is pushed with a zero price while optional cuts are charged (checkpoints.rs:512-519 vs :87-89, :528):

512  if anchor > start {
513      accounting.cuts.push(Cut {
514          endpoint: anchor,
515          role: RetentionRole::Anchor,
516          split_ns: 0,
517          copy_ns: 0,
518      });
519  }

 87  fn allowance(work: u64, fraction: f64) -> u64 {
 88      ((work as f64) * fraction).floor().min(u64::MAX as f64) as u64
 89  }

allowance is already 0 at fraction 0, so the general policy expresses the intent unaided; the == 0.0 branch is a magic-valued configuration switch the charter rules out, and the anchor's split_ns: 0 is why the pre-PR behaviour split prefill for free. Fix: delete the == 0.0 branch and charge the anchor cut through the same allowance as every other cut — at fraction 0 it is naturally unaffordable unless the split is genuinely free, which is the rule the PR wants with one code path.

S3. At zero budget the selector still walks every boundary and reports a skip that did not happen

Sources: architecture #6, reviewer Major 5 (live-observed).

528  let available = allowance(prefill, self.policy.checkpoint_extra_work_fraction);
529  let mut candidates: Vec<_> = request
530      .message_boundaries.iter().rev().copied()
534      .filter(|&end| start < end && end < anchor && request.checkpoint_endpoint_eligible(end))
535      .map(|end| (end, RetentionRole::Message))
536      .collect();
537  if start < request.prompt_tokens && request.prompt_tokens != anchor {
538      candidates.push((request.prompt_tokens, RetentionRole::Endpoint));
539  }

each candidate then priced (:542-605); with available == 0 any split_ns + copy_ns > 0 sets budget = true:

596  let charge = split_ns.saturating_add(copy_ns);
597  if accounting.extra_spent_ns
599      .saturating_add(accounting.reserved_ns)
600      .saturating_add(charge) > available
602  { budget = true; continue; }
...
782  self.stats.checkpoint_skip_unknown_cost += u64::from(plan.unknown);
783  self.stats.checkpoint_skip_work_budget += u64::from(plan.budget);

At the default-on zero-fraction configuration this is an O(N boundaries) interval_prefill_ns walk per selection step plus a permanently nonzero checkpoint_skips{reason="work_budget"} counter describing a policy working as intended. voipmonitor observed the counter incrementing 1–3 per request at fraction 0 live. Fix: when available == 0 and no candidate can be funded, return after pushing the anchor cut instead of enumerating and pricing.


Candidate Subtract / Simplify

Adopted per the "prefer subtraction" rule: every lens ask to expand tests or helpers is superseded here.

X1. One resolved_anchor() replaces anchor_fallback_from and its three re-derivations (~95 lines, removes the B1+B2 mechanism)

Sources: subtractive #1 (preferred over architecture's "add a request field" variant, which keeps four representations).

Sites to collapse: field checkpoints.rs:28; clear_reservations:49; is_request_anchor_endpoint:390-420; the 45-line fallback :467-511; the 15-line map_or_else in plan_checkpoints:671-685; the or_else in promote_request_anchor:758-767; the second caller at scheduler.rs:1794. Shape:

fn resolved_anchor(&self, request: &LiveRequest, catalog: &[PrefillCatalogCost],
                   terminal_window: usize, start: usize, whole: Option<u64>) -> usize {
    let raw = request.checkpoint_anchor();
    if self.limits.snapshots == 0 || raw >= request.prompt_tokens {
        return request.prompt_tokens.min(raw);
    }
    if self.policy.checkpoint_extra_work_fraction == 0.0
        && !Self::anchor_split_is_zero_cost(request, catalog, terminal_window,
                                            start, request.prompt_tokens, raw, whole)
    { request.prompt_tokens } else { raw }
}

Also delete the known_whole parameter (:371-377) and price whole/before/after from one catalog snapshot inside the helper — this both shrinks the code and removes the EWMA-drift discrepancy in B1. Nothing is lost: every site wants the same value, anchor_split_is_zero_cost and the snapshots == 0 early return stay, and prompt-end retention across chunks becomes free because the decision is a pure function of prompt position rather than of chunk history.

X2. Delete complete_test_step; reuse the completion helpers that already exist (~75 lines)

Sources: conventions #4, simplicity F6, subtractive #2.

checkpoints.rs:1942-2016 re-implements policy_tests.rs:162 completion_records + :219 complete_timed (which already takes ExecutionTiming and an accepted parameter) and boundary_tests.rs:93 run_step. It also hardcodes speculative acceptance, coupling the batching test to enable_speculation(&[1,2,4,8]) widths:

1959      GraphKind::Speculative => 3
1960          .min(lane.tokens)
1961          .min((r.max_new_tokens - r.generated_tokens) as usize),

The bespoke copy's slightly different record shape and dur_ns = 1_000 timing path are why the EWMA-drift defect survived the suite. Make the shared helpers pub(super) and parameterise accepted.

X3. Drop tests that prove nothing this PR adds (~195–213 lines)

Sources: subtractive #3, simplicity F8/F9/F10, conventions #5 (partly).

2554      assert!(
2555          all_prefills_done_ns <= 2_000_000_000,
2556          "16 single-launch short prefills should complete without anchor-tail starvation (took {:.1} ms)",
2557          all_prefills_done_ns as f64 / 1e6,
2558      );

Delete it (and the all_prefills_done_ns accumulators); general batch balancing is covered by policy_tests.rs:17, :1319.

X4. Shrink the verbatim-Rust mutation needle in check.py (~15 lines)

Sources: simplicity F7, subtractive #4, conventions #1 (mutation registration itself is clean).

verification/helios-lifecycle/check.py:325-343 uses a 14-line byte-for-byte copy of checkpoints.rs:489-502 and substitutes } else if false {:

326              ("dropped multi-chunk zero-budget fallback",
327               "            } else if accounting.anchor_fallback_from == Some(raw_anchor)\n"
328               "                || (baseline_start < raw_anchor\n"
...
341               "            } else if false {",
342               "multi-chunk prefill must retain zero-budget prompt-end anchor fallback"),

Every other mutation in that file is a 1–3 line needle (:293-294, :303, :319-320), and AGENTS.md:194-197 (not opened) states source-text checks cannot establish runtime correctness. After X1 the needle is one line (let anchor = self.resolved_anchor(...) → request.checkpoint_anchor()); or drop it, since checkpoint_lifecycle_tests.rs:334-340 already asserts the fallback survives into the model.


Candidate Nits

N1. PR description — four gaps, one bundle

AGENTS.md:74-112 (not opened) structure, Before/After tense and limitations disclosure are all met (including "Live signed-core serving … remain unverified" and two named pre-existing base failures). Remaining: (a) "Why" names the defect but not the causal mechanism — the anchor Cut is pushed with split_ns: 0 (checkpoints.rs:512-519) and never charged, while optional candidates are (:528, :596-605); AGENTS.md:82-87 (not opened); (b) promote_request_anchor is unexplained shorthand — say that it promotes a reused prefix checkpoint from Endpoint to Anchor rank (AGENTS.md:122-128 (not opened)); (c) the three docs files (+19/−9) are absent from "What changed" although they carry new user-facing flag text (AGENTS.md:88-94 (not opened)); (d) "Zero-budget serving avoids extra padded prefill launches" reads as a measured result while every listed check is CPU/TLA+, and live serving is listed as unverified — mark it an expectation or cite the reviewer's live prefill_steps 2→1 short / 3→2 multi-chunk (AGENTS.md:95-102 (not opened)).

N2. Two dead/leftover guards

(a) (baseline_end == request.prompt_tokens).then_some(...) at checkpoints.rs:498-500 is always Some, because baseline_end is always prompt_tokens (for_epoch:35-41 sets (consumed, prompt); get_or_insert at :441-444). Delete the guard. (b) allocate_terminal_capture (checkpoints.rs:917-963) still prices a snapshot copy with limits.snapshots == 0 and learns there is no row only at quote time (:949-961), costing a checkpoint_skip_storage counter — behaviourally harmless, but the same "check capacity where it is already known" inconsistency the PR fixes elsewhere.


Dropped as noise (pre-filter record)

What the change gets right (do not subtract)

Open questions left for the adjudicator

  1. B4 vs the reviewer's own evidence. Does the docs/design-review.md:234-240 simulator-and-service bar block, given the reviewer independently produced live 4×SM120 numbers proving the benefit while finding both duplicate-Anchor defects? Author supplied no served measurement and no simulator sweep.
  2. B1/B3 on cited-verbatim rather than re-run evidence. No cargo/pytest was available here — nothing was executed. The defect reproductions are quoted from voipmonitor's live run and are consistent with the code at head, but are not independently re-executed. Whether that suffices to block is a judgment call.
  3. Unknown-price intent. Is flattening unknown prefill prices to "not zero cost" (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; the code cannot.
  4. Prefix-reuse regression. Whether zero-fraction serving actually loses prefix reuse by moving the anchor to the prompt end is measurable only from a served run or a reuse-weighted simulator sweep.
  5. tests/test_design_review_hook.py (not opened) (cited as passing in the PR body) was not inspected; if it imposes structural requirements on helios/src changes, X1's consolidation should be checked against it.