#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.
- helios/src/scheduler/rounds.rs:290-305
Forecast::prior_calibration_factor: if let Some(entry) = global.get(depth).filter(|entry| entry.observed) { return entry.factor(); } 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()) - helios/src/scheduler/rounds.rs:365-375
#[cfg(test)] Forecasts::calibration_factoris the same descending search without the request-local step: 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()) Fix: one free fn, local slice as Option<&[RequestCalibration]>; test wrapper passes None. Matters because policy_tests.rs:5257-5518 asserts against the test-only copy, so the two can silently drift.
F2 (HIGH) Duplicated cumulative-product prefix loop.
- rounds.rs:451-455 (speculative_curve):
let mut cumulative_factor = 1.0f64; ... cumulative_factor *= forecast.calibration_factor(depth, &self.forecasts.calibration); let calibrated = estimate.mean() * cumulative_factor; - rounds.rs:627-637 (observe_packed_forecasts): same
cumulative_factor *= forecast.calibration_factor(depth, &self.forecasts.calibration); cumulative_factorinside a(0..depth_limit).map(...).collect::<Vec<_>>(). Fix: onefn calibrated_prefix_means(forecast, global, depth_limit) -> Vec<f64>used by both (pricing and observation), ~12 lines gone, one fewer way for pricing to disagree with observation.
F3 (HIGH, pure subtraction) utility.rs finish's first parameter is dead after this PR.
- helios/src/scheduler/utility.rs:121-130:
pub fn finish(&self, completion_ms: f64, horizon_ms: f64) -> f64 {
debug_assert!(horizon_ms == 0.0 || completion_ms <= horizon_ms);
let mut value = self.terminal + self.age_price * self.reference_delivery_ms * (self.age_ms + horizon_ms);
if horizon_ms > 0.0 {
// A selected terminal row is being retired and then absent, so it is never excluded.
value += self.age_price * horizon_ms * (self.age_ms + horizon_ms / 2.0);
completion_msnow appears only in the debug_assert (the old(horizon_ms - completion_ms)saving was removed). Callers still thread it: policy.rs:606value.finish(ms, ms), policy.rs:741values[slot].finish(first_ms, total_ms), policy.rs:872values[slot].finish(ms, ms), policy_tests.rs:3554values[slot].finish(ms, ms). Also makes policy.rs:723let first_ms = duration_ns as f64 / 1e6;unused. Fix: drop the parameter; three production call sites collapse to one argument.
F4 (MEDIUM) service.rs: delivery "rate" survives only as a presence marker, and the catalog scan is done twice per plan.
- service.rs:165-286
service_ratesstill computesdelivery_rate = delivery_rate.max(per_ms)(lines 185, 277) from a full catalog walk, but no caller uses its magnitude: service.rs:313 and :411 both bindSome(_)/Some(rate)then discard it. - service.rs:59-161
delivery_referencesre-walks the same catalogs itself (best[slot] = (cost, served)at 99-158;count = rates.iter().flatten().count()at 63). - The new default is immediately overwritten (service.rs:64-69):
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),
})
});
Fix: reduce the second tuple element to a bool/Option<()> delivery-bearing flag (drop the
(count-1.0)/rdefault), or keep one scan instead of two per plan.
F5 (MEDIUM) The constant maximum rate 1.0 is hard-coded at every delivery observe site, with tell-tale unused bindings.
- service.rs:47-52 (publish):
price.observe(observation.duration_ms, observation.duration_ms, 1.0, adaptation_ms); - service.rs:313-316:
if let (Some(price), Some(_)) = (&mut service.deliveries, participant.delivery_rate) { price.observe(dt, delivery, 1.0, self.policy.adaptation_ms); } - service.rs:411-420:
if let (Some(price), Some(_)) = (&mut service.deliveries, participant.delivery_rate) { ... price.observe(duration_ms, 0.0, 1.0, adaptation_ms); } - policy_tests.rs:854,880,891 pass literal 1.0 too.
ServicePrice::observe'smaximum_ratenormalization (utility.rs:50-73:delivered / maximum_rate,maximum_rate.ln()) is now constant-1 for deliveries. Fix: giveServicePricea delivered/excluded update that does not take the argument, or at minimum stop binding the discarded rate.
F6 (HIGH, conventions/AGENTS.md "state support as present qualification") Docs left self-contradictory inside the files this PR edits.
- docs/scheduling-runtime-design.md:110-152 rewritten to the per-step conditional model, but :203-210 still
output delivery: g/z, :233-247 stillsigma_i = K*T/min(batch_capacity,k)and the old- T/2 * sum over active decoders of c_iscore — while docs/scheduling-utility.md:251-254 states the newsum_{excluded decode j} c_jform. - helios/README.md:446-450 (not touched by this PR) still says the ratio is "clamped to
[0, 2]" (now CALIBRATION_FACTOR_MAX = 4.0 at rounds.rs:13) and still describes a cumulative per-depth ratio. Fix: replace those passages with pointers to scheduling-utility.md instead of re-deriving the model in two places — the duplication is what let them drift.
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.