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
- 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::idleis deleted so retention is the absence of a mutation (refresh.rs:95-99holds onlyabort);ActionCosts::refresh_orderis back toobserved_at_ns.max(last_attempt_ns)(cost.rs:303-305), so the starvation defect raised ate5a69669is gone; and zero-charge refresh loops stay impossible becausevalidate_completion(refresh.rs:63-69) still requires an isolated measured interval. - 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. - 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'sretained-refreshdefault still modelling the pre-PR runtime. - 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.
- 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-existingmainfailure), the crate counts, 9 TLA+ models / 590,327 transitions and the 64-seed--preset validaterun (62 scenarios, 35/35 vsttl, exact1.000000parity, 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 syntheticExecutionTimingvalues (cost.rs:443-502,policy_tests.rs:6059-6182).docs/TODO.txt:110-114still 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:
- ~58 lines — delete
helios/src/scheduler/cost.rs:443-502.compute_refresh_duration_excludes_readiness_wait_and_charges_positive_on_zero_computewalks the<,==, missing-GPU andwall_ns == 0matrix 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(income145 ms * 0.002/0.998, acceptance400 ms * 0.01/0.99, dominated casecredit_ns == 0, absent timing both 0, charge-140 ms,costs.duration_key(key) == Some(145 * MS)) and:6139-6182(thewait_ns120 ms /gpu_ns100 ms loop overwall_ns ∈ {0, 130 ms}, observation unchanged,refresh_credit_ns == CREDIT_CAP_NS - max(100, wall)and negative, next planOrdinary). Nothing asserted incost.rsis left unasserted, and both helpers stay exercised throughrefresh.rs:74andrefresh.rs:87. Also drop the doubledtiming_refresh_duration_ns == observed_compute_duration_nspairs at:456-457and:460-461if any case is kept. - ~12 lines — delete
RequestScheduler::idle.helios/src/scheduler.rs:1158-1168no longer touches a ledger; it checkssubmissions.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 callerhelios/src/server/runtime.rs:1184sits in theelseofif executor.outstanding() > 0(:1177), so the error branch is unreachable from production. Prefer the renameassert_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:2483tests the precondition. Either way the retention argument belongs indocs/scheduling-runtime-design.md:443-444, where it already is. - ~10 lines — inline
cost::timing_refresh_duration_ns.cost.rs:47-57is six lines of doc plus a three-line body overobserved_compute_duration_ns, and after removing thecost.rstest 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_nskeeps 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 andwall_ns > 0, which is the third arm (cost.rs:464-466asserts it, so the Architecture lens's "dead fallback" claim is wrong), and the first arm is absent exactly whengpu_ns <= wait_ns, which is the second. - ~15 lines — say each new fact once per document. Idle retention appears twice in each file (
docs/scheduling-runtime-design.md:443-444and:492-493;docs/scheduling-theory.md:577-583and: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-499carry 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
helios/src/scheduler/cost.rs:31-36— "compute duration" and "MirrorsActionCosts::observe" overstate the parity. The helper returnsmax(gpu_ns, wall_ns) - wait_nsfor isolated executions (:43-44) whileobserve(cost.rs:330-337) records the device interval less wait and never useswall_ns. The wall term is inherited fromobserved_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 thatobservedeliberately omits the wall term.helios/src/scheduler/cost.rs:303-305—refresh_order's0sentinel is indistinguishable from an observation atnow_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 excludesnanos == 0,advance_tomovesnow_nspast the first completion, and behaviour matchesmain— but the PR body argues about this ordering as the starvation guard, so anOption<u64>keyed to(nanos != 0).then_some(…)would remove the ambiguity.- The same theorem is re-derived with two different overrun terms.
policy_tests.rs:5961and:6056addlast_refresh_ns(the most recent episode) whiletests/test_scheduling_learning_policy.py:1561-1562addsmax(145.0, 30.0)(the largest episode);docs/scheduling-theory.md:569-574anddocs/scheduling-runtime-design.md:463-468specify 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 attests/test_scheduling_learning_policy.py:1519-1520. scripts/scheduling_sim/learning.pykeeps four hand-writtenPolicyConfigfield lists for one dataclass — the CLI→parameterstuple (:105-109), the categorical/boolean sweep-rejection set (:132), the numeric sweep allow-list (:134-137) and the validate-preset override guard (:477-483). Addingretain_idle_creditrequired edits in three of them.configuration_id(:48-56) already derives fromfields(config), andPolicyConfig.__post_init__validates every field, so the categorical set could derive fromdataclasses.fieldsplus 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.- PR description overstates two things. "…so every refresh completion incurs a strictly positive charge" is a caller-guaranteed property:
timing_refresh_duration_nsreturns0when there is no usable GPU sample andwall_ns == 0, and what makes the claim true isRefreshState::validate_completion(refresh.rs:63-69), which rejects exactly those probes — say so, or name the precondition incost.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-existingmainfailure with no assertion, symptom ormaincommit at which it reproduces;AGENTS.md:103-112asks each material claim to be checkable, so name both. - New assertions re-type the income rates at
policy_tests.rs:5961,:6056,:6075,:6076,:6086instead of usingrefresh::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, unlikeCREDIT_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)
- Ledger split is intact and layer-appropriate.
RefreshState::complete(refresh.rs:71-93) credits timing refresh fromobserved_compute_duration_ns(:74-76) but keeps acceptance learning on raw physicalobserved_duration_ns(:77-79,:83-85), matchingdocs/scheduling-runtime-design.md:488-499. abortsemantics are exactly as documented:refresh.rs:95-99drops positive credit and preserves negative debt (docs/scheduling-runtime-design.md:443-444,:492).- No zero-charge refresh loop.
validate_completion(refresh.rs:63-69) still requires an isolated measured interval, andtiming_refresh_duration_nsis strictly positive on every reachable completion, covered forwait < gpu,wait == gpu,wall == 0andwall > 0atcost.rs:443-501andpolicy_tests.rs:6139-6182. - The retention bound survives. Since idle adds neither credit nor ordinary duration,
P <= (0.002/0.998) * O + DandP <= (0.01/0.99) * O + Dstill hold (docs/scheduling-runtime-design.md:463-474,:492-495); retention is asserted atpolicy_tests.rs:2497-2499,:2563,:2595,:2615and the abort distinction at:2500-2507. - Starvation ordering is restored:
refresh_order=observed_at_ns.max(last_attempt_ns)(cost.rs:303-305), sorecord_attempt(:307-312) advances the key even when the estimate was never refreshed; regression-tested withD = 145 ms > ttl_ns / 499atpolicy_tests.rs:5964-6057. - The simulator flag is fully plumbed and validated:
learning.py:105-109pass-through,:132-133sweep rejection,learning_policy.py:83-84boolean check,:85-88retained-refreshconstraint,learning.py:477-484validate-preset rejection, and CLI/experiment coverage in the Python tests above. It affects onlycredit_ms, notharm_credit_ms, consistent withdocs/scheduling-theory.md:682. - The docs that were updated match the code:
docs/scheduling-runtime-design.md:434-474,:488-499;docs/scheduling-theory.md:576-583,:727-738.docs/scheduling-theory.md:682("Idle clears positive balances and retains debt") is the simulator-onlyharm_alphaledger (:669-686), not a conflict. - No new production flag, environment switch,
#[allow(dead_code)]or manifest/Protobuf change, so the core-compatibility obligation inAGENTS.md:431-444does not apply.
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
- Should the qualified
retained-refreshsimulator policy simply become the idle-retaining one (S4), making--retain-idle-credittemporary? That removes the divergence permanently instead of documenting it. - Is the wall-inclusive term in timing-refresh income intentional (Nit 1)? Charging refresh debt on
max(gpu, wall) - waitwhile 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. - Is
idle()still needed as an API (Subtract 2), or is a documented invariant onRequestSchedulerenough? The rename preserves the ten test assertions that deletion would make vacuous.
Link: https://github.com/NVIDIA/hyperflare-inference/pull/540