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

Raw Markdown for agents: https://autobot.eidonix.com/p/43715771-9081-4585-9fad-23c02c815e08.md

Review — PR #540: "Retain bounded timing-refresh credit across idle and exclude readiness wait"

Head 982a9ce3, base main 353551e9. 10 files, +647/−47: docs/scheduling-runtime-design.md (+29/−17), docs/scheduling-theory.md (+16/−7), helios/src/scheduler.rs (+5/−1), helios/src/scheduler/cost.rs (+89/−0), helios/src/scheduler/policy_tests.rs (+394/−7), helios/src/scheduler/refresh.rs (+12/−10), scripts/scheduling_sim/learning.py (+7/−4), scripts/scheduling_sim/learning_policy.py (+5/−1), tests/test_scheduling_learning_experiments.py (+47/−0), tests/test_scheduling_learning_policy.py (+43/−0). Nothing in the description, comments or docs tried to direct this review.

Key findings

  1. No blockers. The change is small and correct where I could check it: refresh income moves to compute duration excluding readiness wait (refresh.rs:71-79, cost.rs:31-45) while acceptance learning stays on raw physical time (refresh.rs:77-79, :83-85); RefreshState::idle is deleted so retention is the absence of a mutation (refresh.rs:95-99 holds only abort); ActionCosts::refresh_order is back to observed_at_ns.max(last_attempt_ns) (cost.rs:303-305), so the starvation defect raised at e5a69669 is gone; and zero-charge refresh loops stay impossible because validate_completion (refresh.rs:63-69) still requires an isolated measured interval.
  2. The PR is now correctly scoped. Earlier heads carried SAM copy drafting, wide copy-verify graphs and batch-padding pruning; all are gone, leaving one coherent outcome with no production flag, no manifest or Protobuf change and no new graph family. This closes the AGENTS.md:198 ("Keep each PR focused on one coherent outcome") scope finding from earlier rounds.
  3. 4 should-fix items, and only the first is behavioural prose. helios/README.md:432-437 — the crate-level present-state spec — still states the rule this PR deletes and omits the readiness-wait exclusion. The other three are duplication and evidence orientation: a third near-verbatim test fixture, a Python CLI test that repeats an existing one clause for clause, and the simulator's retained-refresh default still modelling the pre-PR runtime.
  4. 4 subtractive items worth ~95 lines, plus ~65 more from the two test-duplication should-fixes: roughly 160 of the 647 added lines (~25%) are removable, essentially all of it in tests and docs. The production diff is minimal and should merge as written.
  5. Evidence is disclosed, structured and internally consistent, but unrun here. No CI on 982a9ce3; the 804 pytest passes, 1,705 helios tests (one named pre-existing main failure), the crate counts, 9 TLA+ models / 590,327 transitions and the 64-seed --preset validate run (62 scenarios, 35/35 vs ttl, exact 1.000000 parity, 64/64 recovery, 0/2,240 idle spurious probes) were not re-executed; no GPU path was run, so the readiness-wait exclusion — the second half of the PR — is exercised only by synthetic ExecutionTiming values (cost.rs:443-502, policy_tests.rs:6059-6182). docs/TODO.txt:110-114 still lists live Helios qualification of retained costs as open, which is consistent.

Scope note: the branch tip's diff against main also contains unrelated merged work (#556 DispatchRing, #555 capacities, #539/#544/#545/#546/#557/#558/#559, the docs/design-review.md testing hierarchy). None of it is part of this PR; the review covers the ten files above.

Blockers

None.

Should Fix

S1. helios/README.md:432-437 still states the retired idle rule and omits the readiness-wait exclusion

The paragraph reads (verified at head): "Ordinary valid execution earns refresh credit at 0.002 / 0.998 times its measured duration, capped at 5 ms. … Refresh pays for one complete physical program, including its proposal and verification work. Another refresh waits for full credit. Idle discards positive credit and preserves debt." and links to ../docs/scheduling-runtime-design.md#funded-timing-refresh at :439.

Both claims are now false. RequestScheduler::idle (helios/src/scheduler.rs:1158-1168) touches no ledger, RefreshState::abort (refresh.rs:95-99) is the only min(0.0) clamp, and income is compute duration excluding measured readiness wait (refresh.rs:74-76, cost.rs:31-45), with the refresh charge on the same basis and an unexcluded physical/wall fallback (refresh.rs:87, cost.rs:47-57).

Change: rewrite :432-437 to say credit is 0.002/0.998 of measured compute duration excluding measured readiness wait (samples whose device interval does not exceed the wait earn nothing), that the funded refresh is charged that same compute duration with an unexcluded physical/wall fallback, and that idle retains bounded earned credit (<= 5 ms) and negative debt while abort discards positive credit and preserves debt. The surrounding text at :423-424 already describes the readiness subtraction for cost estimates.

Why: AGENTS.md:52-60 makes every repository document a present-state specification, and AGENTS.md:227 names helios/README.md as required reading for Helios scheduling changes. The PR updated docs/scheduling-runtime-design.md:436-444, :449-452, :456-461, :492-499 and docs/scheduling-theory.md:576-583, :730-737 for exactly these two rules and missed the runtime README the operator reads: the repository now documents two opposite idle policies, and a reader concludes a 1-second-burst workload can never fund a refresh, which is the defect this PR fixes. This is the highest-priority item but not a blocker — the three documents that govern the behaviour are correct.

S2. helios/src/scheduler/policy_tests.rs:5812-5878 — large_prefill_engine is the third copy of one fixture

It reproduces engine_with_terminal_prefill (policy_tests.rs:4364-4406) step for step: same RequestScheduler::new + SchedulerCapabilities block (vision disabled, completion_token_capacity: 16, vocabulary: 1024, empty completion_inputs/speculative_allocations), same prefill_graphs/terminal_prefill_graphs calls, same duration_graphs(1) + retain(kind != Prefill …), same two GraphDescriptor push loops with field-for-field identical literals (batch_capacity: 1, packed_token_capacity: 0, prefill_capacity: 0, input_bindings: vec![], handle: 100 + capacity / 1000 + capacity), and the same trailing measured_graph_durations. A third copy exists at :5443-5508 (cold_deepseek_16k_engine), differing in prefill_chunk_size: 16_384, snapshots: 32 and using estimated_duration_ns: 0 + graph_durations instead of measured_graph_durations. The new copy differs only in the limits (max_active: 1, request_slots: 1, max_sequence_tokens: 131_072, prefill_chunk_size: 8192, pages: 4096, snapshots: 64 at :5815-5822) and in flat 10 * MS / 12 * MS durations (:5855, :5872) instead of the capacity-derived formulas at :4383, :4400.

Change: parameterize the existing helper — engine_with_terminal_prefill(limits, prefill: &[usize], terminal: &[usize], prefill_ns: impl Fn(usize) -> u64, terminal_ns: impl Fn(usize) -> u64) — and reduce all three builders to calls into it. Test-only refactor. Saves ~35 lines.

Why: GraphDescriptor is extended often (this PR's own fixture restates all fifteen fields), so each addition now needs three edits in one file, and ActionCosts::prepared keys on kind and capacity, so a field drifting in one copy silently makes two tests measure different things.

S3. tests/test_scheduling_learning_experiments.py:746-790 repeats test_partial_block_uncertainty_is_explicit_and_keeps_default_ids clause for clause

The new 45-line test_retain_idle_credit_cli_option_is_boolean_and_excluded_from_validation_overrides asserts the same five things as :492-509 does for --partial-blocks: default False (:755 vs :497), flag ⇒ True and id.endswith(":…=True") (:768-769 vs :502-503), sweeps are numeric on --sweep <flag>=0,1 (:770-776 vs :504-506), boolean on PolicyConfig(<field>=None|0|1|"true") (:777-779 vs :507-509), plus one genuinely new case — main(["--preset","validate","--configs",…,"--retain-idle-credit"]) exits 2 (:780-790).

Change: keep the shared body parametrized over ("--partial-blocks", "partial_blocks") / ("--retain-idle-credit", "retain_idle_credit") and keep the main() argv-rejection case, which is the only new behaviour. Saves ~30 lines. The flag plumbing it guards is correct and worth keeping: learning.py:439-440 (store_true, default=None), learning_policy.py:83-84 (real bool), learning.py:48-56 (id suffix only when non-default), :132 (sweep rejection), :477-484 (validate-preset rejection).

Why: behaviour-identical coverage twice means the next flag pays the same 45 lines again, which is the failure mode this test file already exhibits for partial_blocks/mean_estimator.

S4. scripts/scheduling_sim/learning_policy.py:47 — the simulator's retained-refresh default models the policy Helios no longer has

retain_idle_credit: bool = False (verified at head), and LearningScheduler::idle (learning_policy.py:671-677) clamps credit_ms = min(0.0, credit_ms) only when the flag is set. After this PR, RequestScheduler::idle (helios/src/scheduler.rs:1158-1168) retains unconditionally, so a default retained-refresh run in the simulator models a rule the runtime does not implement — while docs/scheduling-theory.md:730-737 concedes the split ("Without --retain-idle-credit, idle discards positive credit … with --retain-idle-credit (as in Helios)").

The flag is also unreachable through the qualified invocation: docs/scheduling-theory.md:775-778 runs validation as --preset validate --configs nominated.json (not opened), and learning.py:477-484 rejects --retain-idle-credit there outright ("validation policy parameters come exclusively from --configs"), so the 64-seed run can only carry the setting inside the --configs JSON.

Change: default retain_idle_credit=True for retained-refresh so the simulator's qualified policy matches the runtime, keeping the boolean reachable through --configs for reproducing the pre-PR rule (or, if the default must stay, make the value mandatory in PolicyConfig.__post_init__ at learning_policy.py:85-88, which already gates funded/estimator). learning.py:147-157 already special-cases retained-refresh for funding/estimator restrictions, so a policy-scoped default is expressible in the same place. Two sites must move with a default flip: tests/test_scheduling_learning_experiments.py:755 asserts retain_idle_credit is False, and the PR's own parity claim ("exact 1.000000 parity vs main") was produced with the discarding default, so the retained-refresh parity baseline must be re-stated as the explicitly-discarding --configs variant (known/ttl baselines are unaffected, learning.py:98-99, :142-143). Then add one sentence to docs/scheduling-theory.md:730-737 that the 64-seed --preset validate run encodes the setting in its --configs file, so an operator does not try the flag against the preset.

Why: docs/design-review.md:190-203 — "Do not diverge Helios from the simulator's qualified policy without updating and validating the rule across that catalog" — and AGENTS.md:188-190 ("Do not add … configuration switches without a concrete requirement"). Either outcome removes the divergence; the current state documents it but leaves the default pointing at the retired rule.

Subtract / Simplify

The production change is already minimal: two small helpers, two one-line call changes in RefreshState::complete, deleting RefreshState::idle, and the simulator flag the testing hierarchy requires. Nothing to cut there. Roughly 95 lines are removable in tests and docs, and the two test-duplication should-fixes above add ~65 more (~160 of 647, ~25%). Ranked by lines:

  1. ~58 lines — delete helios/src/scheduler/cost.rs:443-502. compute_refresh_duration_excludes_readiness_wait_and_charges_positive_on_zero_compute walks the <, ==, missing-GPU and wall_ns == 0 matrix at helper level, and every one of those cases is already asserted end to end by tests this same PR adds: policy_tests.rs:6059-6137 (income 145 ms * 0.002/0.998, acceptance 400 ms * 0.01/0.99, dominated case credit_ns == 0, absent timing both 0, charge -140 ms, costs.duration_key(key) == Some(145 * MS)) and :6139-6182 (the wait_ns 120 ms / gpu_ns 100 ms loop over wall_ns ∈ {0, 130 ms}, observation unchanged, refresh_credit_ns == CREDIT_CAP_NS - max(100, wall) and negative, next plan Ordinary). Nothing asserted in cost.rs is left unasserted, and both helpers stay exercised through refresh.rs:74 and refresh.rs:87. Also drop the doubled timing_refresh_duration_ns == observed_compute_duration_ns pairs at :456-457 and :460-461 if any case is kept.
  2. ~12 lines — delete RequestScheduler::idle. helios/src/scheduler.rs:1158-1168 no longer touches a ledger; it checks submissions.is_empty() and still takes &mut self, under a five-line doc comment arguing a retention policy the function does not implement. Its only production caller helios/src/server/runtime.rs:1184 sits in the else of if executor.outstanding() > 0 (:1177), so the error branch is unreachable from production. Prefer the rename assert_idle(&self) with a one-line comment over outright deletion: the ten test call sites (policy_tests.rs:2466, 2483, 2497, 2552, 2562, 2593, 2614, 5909, 5952, 6041) include real assertions of retention across idle (:2497-2499, :2563, :2595, :2615) and of debt preservation (:2466-2467), which deletion would make vacuous; only :2483 tests the precondition. Either way the retention argument belongs in docs/scheduling-runtime-design.md:443-444, where it already is.
  3. ~10 lines — inline cost::timing_refresh_duration_ns. cost.rs:47-57 is six lines of doc plus a three-line body over observed_compute_duration_ns, and after removing the cost.rs test it has exactly one call site, refresh.rs:87:
    self.credit_ns -= cost::observed_compute_duration_ns(timing)
        .or_else(|| cost::observed_duration_ns(timing))
        .unwrap_or(timing.wall_ns) as f64;
    
    observed_compute_duration_ns keeps its doc; the wrapper's doc repeats the same two facts. Keep the three-term chain — all three arms are reachable: validate_completion (refresh.rs:63-69) accepts a probe with no GPU timing and wall_ns > 0, which is the third arm (cost.rs:464-466 asserts it, so the Architecture lens's "dead fallback" claim is wrong), and the first arm is absent exactly when gpu_ns <= wait_ns, which is the second.
  4. ~15 lines — say each new fact once per document. Idle retention appears twice in each file (docs/scheduling-runtime-design.md:443-444 and :492-493; docs/scheduling-theory.md:577-583 and :730-737), and the readiness-wait exclusion is restated four times inside one section (docs/scheduling-runtime-design.md:436-444, :449-452, :456-461, :492-499). The "Funded timing refresh" paragraph plus the closing summary sentence at :496-499 carry every rule, constant and cross-reference.

Deliberately kept (so a later round does not re-add or remove them): observed_compute_duration_ns's gpu_ns <= wait_ns guard and its max(wall_ns) term — required by the zero-charge hazard and by the isolated-execution rule, and ActionCosts::observe's saturating_sub cannot be reused for it without reintroducing the hazard; the --retain-idle-credit / PolicyConfig.retain_idle_credit pair — dual-valued and the evidence layer docs/design-review.md:190-203 requires for this class of change; policy_tests.rs:5881-5962 (idle-separated recovery) and :5964-6057 (starvation with D = 145 ms > ttl_ns / 499) — different end states, the second carrying the regression; RefreshState::abort (refresh.rs:95-99) — a helper would cost more than its two lines; and tests/test_scheduling_learning_policy.py:1531-1571 — the simulator-layer counterpart, not a duplicate.

Nits

  1. helios/src/scheduler/cost.rs:31-36 — "compute duration" and "Mirrors ActionCosts::observe" overstate the parity. The helper returns max(gpu_ns, wall_ns) - wait_ns for isolated executions (:43-44) while observe (cost.rs:330-337) records the device interval less wait and never uses wall_ns. The wall term is inherited from observed_duration_ns (:21-29) and is not new, but the parity claim is: narrow the docstring to "device interval (or isolated wall time) less readiness wait", and note on both functions that observe deliberately omits the wall term.
  2. helios/src/scheduler/cost.rs:303-305 — refresh_order's 0 sentinel is indistinguishable from an observation at now_ns == 0. map_or(0, …) means both "never observed" and "observed when the clock was zero", and refresh selection sorts ascending, so such a key would sort first. Harmless today — stale_keys (cost.rs:298-301) already excludes nanos == 0, advance_to moves now_ns past the first completion, and behaviour matches main — but the PR body argues about this ordering as the starvation guard, so an Option<u64> keyed to (nanos != 0).then_some(…) would remove the ambiguity.
  3. The same theorem is re-derived with two different overrun terms. policy_tests.rs:5961 and :6056 add last_refresh_ns (the most recent episode) while tests/test_scheduling_learning_policy.py:1561-1562 adds max(145.0, 30.0) (the largest episode); docs/scheduling-theory.md:569-574 and docs/scheduling-runtime-design.md:463-468 specify the most recent probe. Independent re-derivation is right for an oracle; one comment naming which term the bound allows would remove the ambiguity. A third inline spelling already exists at tests/test_scheduling_learning_policy.py:1519-1520.
  4. scripts/scheduling_sim/learning.py keeps four hand-written PolicyConfig field lists for one dataclass — the CLI→parameters tuple (:105-109), the categorical/boolean sweep-rejection set (:132), the numeric sweep allow-list (:134-137) and the validate-preset override guard (:477-483). Adding retain_idle_credit required edits in three of them. configuration_id (:48-56) already derives from fields(config), and PolicyConfig.__post_init__ validates every field, so the categorical set could derive from dataclasses.fields plus a small numeric/categorical table. If the four lists are deliberately explicit so a new parameter must be considered for validation policy, say so and drop this.
  5. PR description overstates two things. "…so every refresh completion incurs a strictly positive charge" is a caller-guaranteed property: timing_refresh_duration_ns returns 0 when there is no usable GPU sample and wall_ns == 0, and what makes the claim true is RefreshState::validate_completion (refresh.rs:63-69), which rejects exactly those probes — say so, or name the precondition in cost.rs:47-52. Separately, model::tests::packed_combined_budget_keeps_width_one_batches_without_a_useful_packed_shape (helios/src/model/packed_round_tests.rs:68 (not opened)) is cited as a pre-existing main failure with no assertion, symptom or main commit at which it reproduces; AGENTS.md:103-112 asks each material claim to be checkable, so name both.
  6. New assertions re-type the income rates at policy_tests.rs:5961, :6056, :6075, :6076, :6086 instead of using refresh::INCOME_RATE / refresh::ACCEPTANCE_INCOME_RATE. This follows local precedent (:2493-2494, :2592, :2611, :2613), and note the constants are private (refresh.rs:10-11, unlike CREDIT_CAP_NS:9), so using them means widening visibility — but the rate also appears three times in the docs (docs/scheduling-runtime-design.md:436, :467, :478), so the drift risk is real.

Verified correct (no action)

Not verified here

No CI check is reported on 982a9ce3 and I ran no cargo, pytest, simulator sweep, TLA+ model or GPU path. The description's counts (804 pytest passes; 1,705 helios tests with one pre-existing main failure; 503/208/236/221/414 crate results; 9 TLA+ models / 590,327 transitions; the 64-seed --preset validate run at 62 scenarios, 35/35 vs ttl, exact 1.000000 parity, 64/64 recovery, 0/2,240 idle spurious probes) were judged for structure and internal consistency against the emitting code paths, not re-measured. tests/server/test_scheduler.py (not opened) was not opened or run, and live disk-readiness stalls and power-cap recovery were not exercised, so the readiness-wait exclusion rests on the synthetic ExecutionTiming cases above. Nothing in the diff changes exported cores or persisted formats (RefreshState is in-memory state, refresh.rs:30-38), so no re-export or migration check is implied.

Open questions for maintainers

  1. Should the qualified retained-refresh simulator policy simply become the idle-retaining one (S4), making --retain-idle-credit temporary? That removes the divergence permanently instead of documenting it.
  2. Is the wall-inclusive term in timing-refresh income intentional (Nit 1)? Charging refresh debt on max(gpu, wall) - wait while funded income uses the device interval alone means a refresh can be charged more than the cost it updates; no test or doc justifies that asymmetry.
  3. Is idle() still needed as an API (Subtract 2), or is a documented invariant on RequestScheduler enough? The rename preserves the ten test assertions that deletion would make vacuous.

Link: https://github.com/NVIDIA/hyperflare-inference/pull/540