Subtraction and simplicity report · NVIDIA/hyperflare-inference #655

Raw Markdown for agents: https://autobot.eidonix.com/p/e7693c5a-cdf4-4cd2-87d3-1aa581ec8555.md

Subtracting / Simplicity / Conventions review — PR #655 (helios: probe unmeasured or stale snapshot cost once per TTL on terminal capture)

Key findings

The diff is already lean; this review has no blockers. The PR adds ~20 net production lines across two scheduler files, introduces no new config key, flag, env var, metric, Protobuf field, or fallback layer, and reuses the existing scheduler_checkpoint_extra_work_fraction gate (helios/src/scheduler/policy.rs:40). Two candidate subtractions that a reviewer might reach for are in fact load-bearing and should be left alone (see "Checked and rejected").

Four simplifications stand, in priority order:

  1. Medium — three copies of the same unknown_cost skip in allocate_terminal_capture. helios/src/scheduler/checkpoints.rs:1032-1049. Collapsing to one let ... else removes 7 lines and one duplicated stats path.
  2. Medium (convention) — the checkpoint extra-work rule now exists in four documents and the PR updated one. docs/core-design.md:1452-1453 and helios/README.md:378-379 now contradict the new behaviour documented at docs/scheduling-runtime-design.md:622-626; AGENTS.md:52-60 requires documents to state designed behaviour, and merged precedent #285 updated the copies together.
  3. Low-medium — the new unit test re-types two fixtures verbatim from the adjacent test. helios/src/scheduler/cost.rs:1016-1030 and 1046-1055 duplicate cost.rs:983-997 and 999-1008; ~40 lines removable.
  4. Low — probe_duration re-checks freshness that its only production caller already established. helios/src/scheduler/cost.rs:797-799; unreachable except from the unit test at cost.rs:1058.

S1 (Medium) — Collapse the triplicated unknown_cost skip in allocate_terminal_capture

Where: helios/src/scheduler/checkpoints.rs:1032-1049

The PR replaces a single fresh_duration gate with a 3-arm match, and the identical skip is now written out twice inside it and a third time immediately after:

let (cost, probed) = match self.costs.fresh_duration(GraphKind::Snapshot, 1) {
    Some(cost) => (cost, false),
    None if self.policy.checkpoint_extra_work_fraction > 0.0 => {
        let Some(cost) = self.costs.probe_duration(GraphKind::Snapshot, 1) else {
            self.stats.checkpoint_skip_unknown_cost += 1;
            return Ok(None);
        };
        (cost, true)
    }
    None => {
        self.stats.checkpoint_skip_unknown_cost += 1;
        return Ok(None);
    }
};
let Some(prefill) = accounting.initial_prefill_ns else {
    self.stats.checkpoint_skip_unknown_cost += 1;
    return Ok(None);
};

Three sites increment checkpoint_skip_unknown_cost and return None (lines 1036-1037, 1042-1043, 1047-1048), differing only in position. They must stay in lockstep for flare_checkpoint_skips_total{reason="unknown_cost"} to keep meaning one thing.

Replace lines 1032-1049 with a single ordered match plus one let ... else (evaluation order is preserved exactly: cost resolution first, then the prefill check):

let fresh = self.costs.fresh_duration(GraphKind::Snapshot, 1);
let probed = fresh.is_none() && self.policy.checkpoint_extra_work_fraction > 0.0;
let cost = match fresh {
    Some(cost) => Some(cost),
    None if probed => self.costs.probe_duration(GraphKind::Snapshot, 1),
    None => None,
};
let (Some(cost), Some(prefill)) = (cost, accounting.initial_prefill_ns) else {
    self.stats.checkpoint_skip_unknown_cost += 1;
    return Ok(None);
};

18 lines become 11, with one skip site instead of three and no double fresh_duration lookup (the probed bool is computed once, before the move). Everything downstream — the work-budget check at 1050-1054, the storage quote at 1065-1070, and the if snapshot.is_some() / record_probe block at 1071-1074 — is untouched.


S2 (Medium, convention) — One documented rule, four copies, one updated

Where: docs/core-design.md:1452-1453, helios/README.md:378-379, docs/cli-design.md:699-704 vs the new docs/scheduling-runtime-design.md:622-626

The PR documents the probe only in docs/scheduling-runtime-design.md, adding:

When the fraction is
positive and the snapshot-copy cost is unmeasured or stale, terminal capture
still allows at most one probe per `estimate_ttl_ns` (priced against the
retained snapshot duration when stale) so requests whose anchor is already
cached or whose decode outlives the TTL can refresh the estimate.

The same rule is stated elsewhere and those copies still assert the strict behaviour, so the repository now describes one mechanism two contradictory ways:

AGENTS.md:52-60 requires documents to state designed behaviour (and, conversely, forbids leaving prose that describes behaviour the code no longer has). Merged precedent #285, whose doc paragraph this PR edits, updated the copies in lockstep.

Concrete fix: one clause each, no new paragraph — e.g. docs/core-design.md: "…exclude prefill extras without excluding the selected anchor; a terminal capture may still probe an unmeasured or stale snapshot cost once per estimate_ttl_ns." Same clause in helios/README.md:378 and one sentence in docs/cli-design.md:701.

Note the doc already states the asymmetry (prefill extras stay disabled) at scheduling-runtime-design.md:619-622; it just isn't propagated.


S3 (Low-medium) — The new unit test re-types two existing fixtures verbatim

Where: helios/src/scheduler/cost.rs:1016-1030 and 1046-1055, duplicating cost.rs:983-997 and 999-1008

The new probe_duration_uses_smallest_declared_batch_and_bounds_by_ttl opens with a 15-line GraphDescriptor literal:

let graphs = vec![GraphDescriptor {
    name: "snapshot-b2".into(),
    kind: GraphKind::Snapshot,
    sampling_mode: SamplingMode::General,
    confidence_width: 0,
    draft_tokens: 0,
    handle: 1,
    batch_capacity: 2,
    token_capacity: 1,
    packed_token_capacity: 0,
    prefill_capacity: 0,
    estimated_duration_ns: 0,
    input_bindings: vec![],
    tuned_bindings: vec![],
}];

byte-identical to cost.rs:983-997 in the test directly above it, and later re-types the 10-line ScheduledStep literal (1016-1030, 1046-1055) that cost.rs:999-1008 already contains. The existing test already asserts the transition the new one needs to set up (fresh_duration … None → set_measured(&step, 750_000) → Some(750_000)).

Concrete fix: delete cost.rs:1016-1030 and 1046-1055 and either (a) extend fresh_duration_uses_smallest_declared_batch_when_batch_one_is_absent with the four probe_duration/record_probe assertions, or (b) hoist one shared fn snapshot_b2_batch() -> (ActionCosts, ScheduledStep) used by both tests. Either removes ~40 duplicated lines while keeping every assertion the PR added.


S4 (Low) — probe_duration re-checks freshness no production caller needs

Where: helios/src/scheduler/cost.rs:794-804

pub fn probe_duration(&self, kind: GraphKind, tokens: usize) -> Option<u64> {
    let key = self.smallest_batch_key(kind, tokens)?;
    let estimate = self.entry(key)?;
    if estimate.fresh(self.now_ns, self.ttl_ns) {
        return None;
    }
    let ready = estimate
        .last_probe_ns
        .is_none_or(|at| self.now_ns.saturating_sub(at) >= self.ttl_ns);
    ready.then_some(estimate.nanos)
}

The only production caller is checkpoints.rs:1035, reached exclusively from the None if arm at 1033 — i.e. only after fresh_duration on the same key (cost.rs:788-792, same smallest_batch_key) already returned None, which happens when the entry is absent (caught by self.entry(key)?) or not fresh. The if estimate.fresh(...) arm is therefore unreachable in production; the only exerciser is assert_eq!(costs.probe_duration(GraphKind::Snapshot, 1), None); at cost.rs:1058.

This is not a defect — it is defensive code with no production exerciser, and it hides the real precondition ("call only when fresh_duration returned None"). Either drop the 3-line guard and state the precondition in the doc comment, or keep the guard and drop the assertion at cost.rs:1058. Not both.


Checked and explicitly rejected as subtractions

Scope note

Production footprint: Estimate.last_probe_ns + three small ActionCosts methods + one gate rewrite. Nothing speculative, no dead flags, no abandoned branches, no duplicated repo helper. Apart from S1-S4 above, I found nothing to delete. The test coverage is well-pitched (drives the real entry point allocate_terminal_capture, checks the skip counter and the fraction == 0.0 no-op).

Open questions

  1. Why relax only the terminal path? checkpoint_selection_uncached (checkpoints.rs:624-626) and checkpoint_copy_allowed (checkpoints.rs:965-967) keep the strict unknown/stale rule, so the prefill half of scenario 2 in the description stays unfixed. If both paths should share one predicate, a single shared helper (e.g. snapshot_cost_or_probe()) that returns (cost, probed) would remove the asymmetry and S1's duplication in one move — worth deciding before landing either.
  2. Is the zero-priced first probe worth a doc sentence? probe_duration returns Some(0) for a never-measured entry, so the first probed capture is recorded at zero in request.checkpoint_copy_ns (checkpoints.rs:1077) → stats.checkpoint_extra_work_ns (1095-1096), and flare_checkpoint_extra_work_nanoseconds_total under-reports one copy per TTL. Not a simplification, but if it is intentional it belongs next to the probe sentence at scheduling-runtime-design.md:622-626.
  3. docs/cli-design.md:696-709 — is the flag paragraph required to mention the probe, or is the design doc sufficient? I could not find a stated rule for which documents mirror flag behaviour, only AGENTS.md:52-60.