Subtraction and simplicity scratchpad · NVIDIA/hyperflare-inference #644

Raw Markdown for agents: https://autobot.eidonix.com/p/a8f56ef7-ff8a-4fe5-9408-e5423746cb12.md

#1 [high] Research summary

Reviewed the diff at pr/644 for subtraction/simplicity/conventions. Six findings; the arithmetic itself is lean, but the calibration half ships three copies of one inheritance rule and two copies of one accumulation loop, and the age half leaves a parameter dead at every call site.

1. helios/src/scheduler/rounds.rs — the "inherit the deepest observed shallower depth" walk exists twice (high). Forecast::prior_calibration_factor (290-305) and the #[cfg(test)] Forecasts::calibration_factor (365-375) are the same descending search, differing only in whether a request-local slot is consulted:

for prev in (0..depth).rev() {
    if let Some(factor) = self.calibration.get(prev).and_then(|entry| entry.local_factor()) {
        return factor;
    }
    if let Some(entry) = global.get(prev).filter(|entry| entry.observed) {
        return entry.factor();
    }
}
global.get(depth).map_or(1.0, |entry| entry.factor())

vs

for prev in (0..depth).rev() {
    if let Some(entry) = self.calibration.get(prev).filter(|entry| entry.observed) {
        return entry.factor();
    }
}
self.calibration.get(depth).map_or(1.0, |entry| entry.factor())

Extract one free function taking the local slice as Option<&[RequestCalibration]> and let the test wrapper call it with None; the two variants then cannot drift, which matters because policy_tests.rs:5257-5518 asserts against the test-only copy.

2. Same file — the cumulative-product prefix loop also exists twice (high). speculative_curve (451-455) and observe_packed_forecasts (627-637) both do cumulative_factor *= forecast.calibration_factor(depth, &self.forecasts.calibration) and emit the running product. One fn calibrated_prefix_means(forecast, global, depth_limit) -> Vec<f64> would serve both, deleting ~12 lines and one chance for the pricing path to disagree with the observation path.

3. helios/src/scheduler/utility.rs:121-130 — finish's first parameter is dead after this PR (high, pure subtraction).

pub fn finish(&self, completion_ms: f64, horizon_ms: f64) -> f64 {
    debug_assert!(horizon_ms == 0.0 || completion_ms <= horizon_ms);
    ...
        value += self.age_price * horizon_ms * (self.age_ms + horizon_ms / 2.0);

completion_ms is now used only in the debug_assert, yet every caller still threads it: policy.rs:606 value.finish(ms, ms), policy.rs:741 values[slot].finish(first_ms, total_ms), policy.rs:872 values[slot].finish(ms, ms), policy_tests.rs:3554. Delete the parameter (keeping or dropping the assert) and the three production call sites collapse to one argument — first_ms at 723 becomes unused too.

4. helios/src/scheduler/service.rs — delivery "rate" is now only a presence marker, and the catalog scan it comes from is repeated (medium). service_rates still computes delivery_rate = delivery_rate.max(per_ms) (185, 277) from a full catalog walk, but after this PR no code uses its magnitude: delivery_references re-walks the same catalogs itself (best[slot] at 99-158) and uses the array only as Option presence (rates.iter().flatten().count() at 63, r.map(...) at 64). The one survivor is a default that is immediately overwritten:

let mut references = rates.map(|r| {
    r.map(|r| DeliveryReference {
        excluded_wait_ms: (count - 1.0).max(0.0) / r,
        served_share: (1.0 / count).min(1.0),
    })
});

Consider reducing the second tuple element to a bool/Option<()> delivery-bearing flag (dropping (count-1.0)/r), or keeping one scan instead of two per plan.

5. Same file — the literal 1.0 maximum rate is now hard-coded at four delivery observe sites (medium). service.rs:47-52, :315 price.observe(dt, delivery, 1.0, ...), :420 price.observe(duration_ms, 0.0, 1.0, ...), plus policy_tests.rs:854,880,891, together with the tell-tale if let (Some(price), Some(_)) = (&mut service.deliveries, participant.delivery_rate) at 313 and 411 (rate bound then discarded). ServicePrice::observe's maximum_rate division/normalization (utility.rs:54,63,68) is now constant-1 for deliveries — either give ServicePrice a delivered/excluded update without the argument, or at minimum stop binding the unused rate.

6. Docs left self-contradictory inside the files the PR edits (high, AGENTS.md "state support as present qualification"). docs/scheduling-runtime-design.md fixes the calibration section (110-152) but 30 lines later still carries the superseded model: :203-210 (gradient output delivery: g/z), :233-247 (sigma_i = K*T/min(batch_capacity,k) and the old - T/2 * sum over active decoders of c_i score), while docs/scheduling-utility.md:251-254 states the new sum_{excluded decode j} form. helios/README.md:446-450 still says the ratio is "clamped to [0, 2]" (now 4.0) and describes a cumulative per-depth ratio. Replace those passages with pointers to scheduling-utility.md rather than re-deriving them; the duplication is what let them drift.

Minor, listed not argued: utility.py:136-140 encodes the reference as (duration/capacity, -capacity) and then served = -neg_served (158-162) just to get a min-with-tie-break — a two-line loop or min over a small dataclass reads directly and matches the Rust best array.

The rest is lean: no new flags, config knobs, or feature gates; DepthCalibration was already simplified (vec![DepthCalibration::new(0.5); …] replaces the geometric seeding), the observed flag replaces a predicted <= 1e-6 heuristic rather than adding to it, and LaneValue::decode remains a genuine two-line wrapper over decode_within.

#2 [high] PR #644 subtraction/simplicity review — final findings (all 6 + minor)

PR #644 (lukealonso) "fix(helios): per-step speculative calibration and excluded-only waiting/delivery fairness", base main 4ed5d875, head 2b15114. Lens: Subtraction / Simplicity & Conventions. Verdict: arithmetic is lean (no new flags, knobs, feature gates, fallback layers, version gate). Six high-value items follow; the wrong-but-existing behaviour is NOT re-litigated (correctness lens).

F1 (HIGH) Duplicated inheritance walk in rounds.rs.

F2 (HIGH) Duplicated cumulative-product prefix loop.

F3 (HIGH, pure subtraction) utility.rs finish's first parameter is dead after this PR.

F4 (MEDIUM) service.rs: delivery "rate" survives only as a presence marker, and the catalog scan is done twice per plan.

F5 (MEDIUM) The constant maximum rate 1.0 is hard-coded at every delivery observe site, with tell-tale unused bindings.

F6 (HIGH, conventions/AGENTS.md "state support as present qualification") Docs left self-contradictory inside the files this PR edits.

MINOR (listed, not argued) scripts/scheduling_sim/utility.py:136-140 encodes the reference as a (duration/capacity, -capacity) pair only to get a min-with-tie-break, then unpacks per_delivery_ms, neg_served = reference; served = -neg_served at :159-160. A two-line loop or a small dataclass min reads directly and matches the Rust best array (service.rs:99-111).

WHAT IS ALREADY LEAN (say plainly): no new flags, config knobs, feature gates, fallback branches or compatibility layers; no Protobuf/core-format/CUDA-graph files touched; DepthCalibration seeding was simplified (vec![DepthCalibration::new(0.5); token_capacity - 1] at rounds.rs:337 replaces the geometric per-depth seeding); the new observed flag replaces a predicted <= 1e-6 heuristic rather than adding to it; LaneValue::decode (utility.rs:95-97) is a genuine two-line wrapper over decode_within; DeliveryReference (service.rs:27-33) replaces a bare f64 with a documented two-field struct rather than adding a parallel map.