Review of PR #540 at head 982a9ce3 — correctness lens
Key findings
Verdict: should-fix issues only (one documentation defect); no blocking correctness defect found in the code.
- Should fix —
helios/README.md:432-437still documents the two behaviours this PR changes in the runtime: refresh credit as0.002 / 0.998of measured duration and "Idle discards positive credit and preserves debt." Both are now false, and the README links to a design section that says the opposite; this violates AGENTS.md:52-58 (prose must state present behaviour; designed-but-unimplemented behaviour must be marked as such). - Nit —
helios/src/scheduler/cost.rs:303-305:refresh_order's0"never observed" sentinel is indistinguishable from a genuine observation atnow_ns == 0, which would sort first. Harmless with current monotonicnow_nsandstale_keys'nanos != 0filter; behaviour identical tomain. - Everything else I followed through the lens checked out: the single production caller of
idle, positive-charge guarantee for refresh probes, the compute-vs-physical ledger split, agreement between the newobserved_compute_duration_nsguard andActionCosts::observe, and the simulator flag's default/validation/exclusions.
The PR was rewritten at 982a9ce and no longer contains the SAM/copy-draft/draft_source code that earlier review rounds of this PR discussed; those earlier findings are obsolete and not repeated here.
Should fix
1. helios/README.md:432-437 states the pre-PR behaviour and contradicts the design docs it links to
Current text:
Ordinary valid execution earns refresh credit at
0.002 / 0.998times 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.
Both highlighted clauses are now wrong for the shipped runtime:
- Income basis.
helios/src/scheduler/refresh.rs:71-93:PlanOrigin::Ordinarycreditsself.credit_nsfromcost::observed_compute_duration_ns(timing)(line 74-76) — readiness wait excluded — and creditsacceptance_credit_nsfromobserved_duration_ns(line 77-79) — raw physical duration.observed_compute_duration_nsis the new helper athelios/src/scheduler/cost.rs:37-45, which subtractsreadiness.wait_ns()and returnsNonewhengpu_ns <= wait_ns. - Idle behaviour.
RefreshState::idleis deleted;refresh.rsnow exposes onlyabort(lines 95-99).RequestScheduler::idle(helios/src/scheduler.rs:1158-1168) validates only that no submission is outstanding, and its doc comment (lines 1160-1162) states that both ledgers retain bounded earned credit<= CREDIT_CAP_NSand negative debt across idle.
Why it matters: helios/README.md:439 links to ../docs/scheduling-runtime-design.md#funded-timing-refresh, which now states the opposite rule (docs/scheduling-runtime-design.md:436-444: compute duration excluding readiness wait; "Idle retains bounded earned credit (<= 5 ms) and negative debt; abort discards positive credit and preserves debt"). The same rule is restated at docs/scheduling-runtime-design.md:492-499 for acceptance learning. A reader of the runtime README is told that a 1-second-burst workload can never fund a refresh, which is exactly the defect this PR fixes. AGENTS.md:52-58 requires repository documents to "State support as present qualification: what is implemented" and to mark anything not implemented as "designed, not implemented"; this passage is neither — it is stale. The PR updates the two design docs and the simulator docs but leaves the runtime README untouched.
Fix: rewrite those two sentences to match the design doc — credit is earned from measured compute execution duration excluding measured readiness wait (with samples whose device interval does not exceed readiness wait earning nothing, matching ActionCosts::observe), and idle retains bounded earned positive credit (<= 5 ms) plus negative debt, while abort discards positive credit and preserves debt. Optionally add one sentence that a wait_ns >= gpu_ns refresh completion charges unexcluded physical/wall time.
Nit
1. helios/src/scheduler/cost.rs:303-305 — refresh_order sentinel collides with a genuine observed_at_ns == 0
refresh_order returns observed_at_ns.max(last_attempt_ns) (line 304) and map_or(0, …) for a missing entry; 0 therefore means both "no observation" and "observed when now_ns was 0". The refresh selection sorts ascending by this key, so such a key would get top priority. In practice ActionCosts::prepared starts observed_at_ns = 0 and advance_to moves now_ns forward past the first completion, and stale_keys (cost.rs:298-301) already excludes entries with nanos == 0 that are not fresh, so a stale entry can only carry 0 if it also has nanos != 0 — i.e. it was observed in the same instant the clock started. Behaviour matches main; the note is only because the PR body argues about this ordering as the starvation guard. No change required; if desired, use Option<u64> keyed to (nanos != 0).then_some(observed_at_ns) as observation() already does at cost.rs:314-318.
Verified non-defects (traced in code)
RequestScheduler::idlecallers. The only production caller ishelios/src/server/runtime.rs:1184, reached when no submissions are outstanding; the precondition is re-checked insideidle(scheduler.rs:1164). No other code depended on idle clearing credit. Tests that asserted the old clearing behaviour were updated (policy_tests.rs:2470-2508,:2545-2615,:3548), and the retained-credit statement is asserted directly atpolicy_tests.rs:2497-2499(idle keepsearned/acceptance_earned), with abort clearing positive (:2500-2507) and preserving negative debt.- No zero-charge refresh loop.
timing_refresh_duration_ns(cost.rs:53-57) can yield0only when there is no usable GPU sample andwall_ns == 0;RefreshState::validate_completion(refresh.rs:63-69) rejects exactly that for probes (observed_duration_ns(timing).is_none() && timing.wall_ns == 0, plustiming.queued), socompletenever applies a 0 charge to a probe. Probes are also gated onready()(refresh.rs:43-45,51-57), andcomplete's probe arm subtracts the charged duration and clearsactive(refresh.rs:82-91). - Ledger split is intact. Ordinary completions credit timing refresh from compute duration and acceptance learning from raw physical duration (
refresh.rs:73-79), matchingdocs/scheduling-runtime-design.md:489-499. Probe charges: acceptance usesobserved_duration_ns(timing).unwrap_or(timing.wall_ns)(raw,refresh.rs:84), timing refresh usestiming_refresh_duration_ns(refresh.rs:87). - Guard matches
ActionCosts::observe.cost.rs:330-337usessaturating_sub(wait_ns)and discards a 0 sample;observed_compute_duration_nsreturnsNoneforgpu_ns <= wait_ns(cost.rs:40-42), so refresh income cannot be earned on a sample the cost model refuses. Ordinary executions withgpu_ns <= wait_nsearn no credit but are not charged (they are ordinary completions), which is consistent. - Starvation ordering.
refresh_orderis restored toobserved_at_ns.max(last_attempt_ns)(cost.rs:303-305), sorecord_attempt(cost.rs:307-312) advances the key even when the estimate itself was never refreshed.D = 145 ms > ttl_ns / 499 = 60.12 msregression coverage is asserted atpolicy_tests.rs:6075and the aggregate bound at:5961/:6056. - Readiness-wait edge cases covered by test.
policy_tests.rs:6140(positive fallback whenwait_ns >= gpu_ns,<and==,wall_ns == 0and> 0) andcost.rs:444(compute_refresh_duration_excludes_readiness_wait_and_charges_positive_on_zero_compute) cover the two paths the PR body calls out.policy_tests.rs:5881covers idle-separated short-request recovery. - Simulator flag.
retain_idle_creditdefaults toFalse(preservingmainsimulator behaviour, so the existingretain_idle_credit=Falseparity gate is meaningful), is type-checked as a real bool (scripts/scheduling_sim/learning_policy.py:83-84), affects onlycredit_msand notharm_credit_ms(consistent withdocs/scheduling-theory.md:682's statement that idle clears harm credit), is rejected from--sweep(learning.py:132-133) and from--preset validateCLI overrides (learning.py:477-484), and enters the configuration id only when non-default. Added Python tests cover the CLI flag, sweep rejection, thePolicyConfigtype check, and the validate-preset exit code. - Docs consistency elsewhere.
docs/scheduling-runtime-design.md:436-444and:492-499, plusdocs/scheduling-theory.md:576-583and:729-738, describe the new rule and correctly scope the simulator default (discard) versus Helios (retain).
Open questions / what could not be confirmed
- Runtime README vs design docs is the only prose conflict I found; I did not search the entire repo for further statements of the idle-clears-credit rule beyond
helios/README.md, the two changed design docs, anddocs/scheduling-theory.md(grep overdiscards positive credit|0.002 / 0.998returned only those, result cited above). - Not run: any Rust or Python suite, the 64-seed simulator validation, TLA+ conformance, or GPU/HTTP paths (including disk-readiness stalls, the case the readiness-wait exclusion targets). All statements here come from reading the code at 982a9ce3. A GPU run with a disk-backed cold start (
tests/server/test_scheduler.py, power-cap recovery) would be the only way to confirm thegpu_ns > wait_nsexclusion empirically; thewait_ns >= gpu_nsfallback is only covered by unit tests. - Compatibility/persisted state: the PR touches no format, Protobuf metadata, or
DecodedHistorysurface, andRefreshStateis in-memory scheduler state (refresh.rs:30-38), so there is no migration or replay concern for stored artifacts.checkpoints.rs:1207(not opened) (which seedscredit_ns = CREDIT_CAP_NS) is untouched and unaffected by the removedidlemethod.
Link: https://github.com/NVIDIA/hyperflare-inference/pull/540