Key findings
Fourth-pass conventions-and-duplication review of PR #540 at head 982a9ce3 ("Retain bounded timing-refresh credit across idle and exclude readiness wait"). The PR was reworked and is now much narrower than earlier heads: all SAM / history copy-drafting, wide copy-verify (COPY_DRAFT), speculative batch-padding pruning, draft_source cost-key and wire changes, and refresh_order tiering were removed. My earlier findings on those constructs are moot and are not repeated here.
No blocking issues. 3 should-fix, 4 nits — all duplication or doc-sync; none is a behavioural defect.
Should fix:
helios/README.md:432-437— the crate-level present-state spec still says "Idle discards positive credit and preserves debt", now false, and it omits the readiness-wait exclusion; the two docs the PR did update say the opposite.helios/src/scheduler/cost.rs:37-45— newobserved_compute_duration_nsis a fourth hand-written copy of "max positivegpu_ns, subtract readiness wait", forty lines fromActionCosts::observe, whose own doc comment says it "Mirrors" it.helios/src/scheduler/policy_tests.rs:5812-5878—large_prefill_engineis the third near-verbatim copy of the terminal-prefill test fixture.
Nits: income-rate literals instead of refresh::INCOME_RATE; four parallel PolicyConfig field lists in learning.py; the exploration bound re-derived with two different overrun terms.
Changed files read in context: helios/src/scheduler.rs (idle 1158-1168; complete 2655-2658), helios/src/scheduler/cost.rs (21-57 new helpers; 330-353 observe; 439-504 new test), helios/src/scheduler/refresh.rs (whole file, 101 lines), helios/src/scheduler/policy_tests.rs (fixtures 4364-4406, 5443-5508, 5812-5878; existing refresh tests 2380-2616; new tests 5880-6183), scripts/scheduling_sim/learning.py (40-145, 455-500), scripts/scheduling_sim/learning_policy.py (24-89), tests/test_scheduling_learning_policy.py (1500-1572), tests/test_scheduling_learning_experiments.py (470-540, 741-791), docs/scheduling-runtime-design.md (428-500), docs/scheduling-theory.md (540-760), plus the sibling spec helios/README.md (415-450) and the callers/precedents helios/src/scheduler/checkpoints.rs:754-764, helios/src/server/metrics/scheduler.rs:179-206.
Should fix
1. helios/README.md:432-437 — the crate-level present-state spec still contradicts the new idle behaviour
helios/README.md:432-437 states:
"Ordinary valid execution earns refresh credit at
0.002 / 0.998times its measured duration, capped at 5 ms. … Another refresh waits for full credit. Idle discards positive credit and preserves debt."
Both clauses are now wrong. This PR deletes RefreshState::idle and makes RequestScheduler::idle (helios/src/scheduler.rs:1158-1168) a pure validation that retains credit; refresh.rs:95-99 abort is the only thing that clamps to min(0.0). And credit is earned on compute duration excluding readiness wait (refresh.rs:74, cost.rs:37-45), not "measured duration".
Why it matters: helios/README.md is the crate-level present-state spec and an explicit sibling of docs/scheduling-runtime-design.md (it restates the same median-of-nine rule at lines 420-424 and links to #funded-timing-refresh at 439). The PR changed the sibling but not this file, so the repository now documents two opposite idle policies. This is the convention the repo follows: present-state prose is updated in every place that restates it — the PR itself edited docs/scheduling-runtime-design.md:436-444 and 489-496 and docs/scheduling-theory.md:576-583, 729-738 for exactly this change.
Fix: replace line 437 with "Idle retains bounded earned credit (<= 5 ms) and preserves debt; abort discards positive credit and preserves debt." and change "its measured duration" at 432-433 to "its measured compute duration (excluding measured readiness wait)", matching docs/scheduling-runtime-design.md:436-444.
2. helios/src/scheduler/cost.rs:37-45 — observed_compute_duration_ns duplicates ActionCosts::observe
The new helper:
let wait_ns = timing.readiness.map_or(0, |intervals| intervals.wait_ns());
let gpu_ns = timing.gpu_ns.into_iter().flatten().max().filter(|&ns| ns > 0)?;
if gpu_ns <= wait_ns { return None; }
ActionCosts::observe (cost.rs:330-337), in the same file forty lines below, independently writes the same two steps:
let Some(raw_sample) = timing.gpu_ns.into_iter().flatten().max().filter(|n| *n > 0) else { return; };
let sample = raw_sample.saturating_sub(timing.readiness.map_or(0, |intervals| intervals.wait_ns()));
if sample == 0 { return; }
The new helper's own doc comment (cost.rs:33) says "Mirrors ActionCosts::observe", i.e. the author documents the coupling instead of expressing it. The two copies already differ in expression (saturating_sub + == 0 vs <= + -), and the file already has three precedents for the same idiom with no shared helper: helios/src/scheduler/checkpoints.rs:754-764 (credit_checkpoint_decode), helios/src/server/metrics/scheduler.rs:179-180 and 201-206.
Why it matters: this is a correctness-critical predicate the PR had to keep in lockstep — observe must discard exactly the samples for which observed_compute_duration_ns returns None, or ordinary executions can earn credit for a zero compute sample. Any future refinement (per-interval exclusion, excluding wait only on queued samples) must be made in three places.
Fix: extract the two components once in cost.rs — fn measured_gpu_sample(timing) -> Option<u64> (max positive gpu_ns) and fn readiness_wait_ns(timing) -> u64 — and have both observed_compute_duration_ns and ActionCosts::observe call them, deriving observe's zero-discard from the same gpu_ns <= wait_ns predicate. Note observe deliberately does not fold in wall_ns when unqueued (cost.rs:334 vs the new helper's line 43), so only the extractors can be shared without changing behaviour; that asymmetry is currently silent and should be documented on both.
3. helios/src/scheduler/policy_tests.rs:5812-5878 — large_prefill_engine is the third copy of the same fixture
large_prefill_engine(prefill_capacities, terminal_capacities) duplicates two existing fixtures in the same file:
engine_with_terminal_prefill(policy_tests.rs:4364-4406): sameprefill_graphs(..)+terminal_prefill_graphs(..)+duration_graphs(1)+retain(|g| g.kind != GraphKind::Prefill)+ hand-builtGraphDescriptorpush loop for Prefill and TerminalPrefill.cold_deepseek_16k_engine(policy_tests.rs:5443-5508): the same shape again.
All three share the identical descriptor literal and the same handle: 100 + capacity / handle: 1000 + capacity convention; the new copy differs only in max_sequence_tokens: 131_072 / prefill_chunk_size: 8192, in taking the capacity lists as parameters (which engine_with_terminal_prefill already does), and in using flat 10 * MS / 12 * MS durations instead of the per-capacity formula.
Why it matters: GraphDescriptor is repeatedly extended (this PR's own new test had to restate all fifteen fields), so each addition now needs three edits in one file, and the three copies can drift in handle or duration conventions unnoticed.
Fix: extend the existing precedent helper — add limits/prefill_chunk_size and the duration closure as arguments to engine_with_terminal_prefill, or hoist a prefill_descriptors(kind, capacities, handle_base, duration) builder used by all three fixtures. That removes ~55 duplicated lines.
Nits
4. Income-rate literals re-typed in the new assertions — helios/src/scheduler/policy_tests.rs:5961, 6056, 6075, 6076, 6086
The new tests write 0.002 / 0.998 and 0.01 / 0.99 inline instead of using the constants that govern the behaviour: refresh::INCOME_RATE (helios/src/scheduler/refresh.rs:10) and refresh::ACCEPTANCE_INCOME_RATE (refresh.rs:11). The constants are already reachable — the same file uses refresh::CREDIT_CAP_NS at 5954, 6073-6097, 6130, 6157, 6178. Existing tests at 2493-2494, 2592, 2611, 2613 do hard-code the rates, so the new code follows local precedent, but it inherits the drift risk; the rate also appears three times in the docs (docs/scheduling-runtime-design.md:436, 467, 478). Fix: use the constants in the new asserts.
5. Four hand-written PolicyConfig field lists, one dataclass — scripts/scheduling_sim/learning.py:105-109, 132, 134-137, 478-483
build_configurations keeps four parallel hand-written lists of PolicyConfig field names: 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 (478-483). Adding retain_idle_credit required four separate edits (it appears at 109, 132 and 478).
The repository's established mechanism for this is the dataclass itself: PolicyConfig (scripts/scheduling_sim/learning_policy.py:24-88) already type-validates every field in __post_init__ (learning_policy.py:83-84 is the new retain_idle_credit check), and configuration_id (learning.py:48-56) already derives from fields(config) rather than a literal list. Also note the categorical set at 132 is incomplete-by-construction — it is an explicit list, so any future boolean/categorical field is silently sweepable — which is the failure mode this edit walked into. Fix: derive (1), (2) and (4) from dataclasses.fields(PolicyConfig) plus a small numeric/categorical table declared next to the dataclass; only (3) needs a real decision.
6. The same theorem re-derived with two different overrun terms — helios/src/scheduler/policy_tests.rs:5961, 6056 vs tests/test_scheduling_learning_policy.py:1561-1562
Both new simulator/Rust tests assert the funded budget bound E <= alpha/(1-alpha) * F + D (docs/scheduling-theory.md:569-574), but the Rust copies add last_refresh_ns (the most recent episode) while the Python copy adds max(145.0, 30.0) (the largest episode). These are different overrun terms for the same theorem. A third inline spelling already exists at tests/test_scheduling_learning_policy.py:1519-1520.
Independent re-derivation is a virtue for an oracle, so I would not require a shared helper — but one comment naming which term the theorem allows (the doc's "the charge of the most recent probe", docs/scheduling-runtime-design.md:463-468) would remove the ambiguity.
Verified-correct (no finding)
RefreshState::idledeletion leaves no stale caller:RequestScheduler::idle(scheduler.rs:1163) is the onlyidleentry point, andpolicy_tests.rs:3548was updated toabort.abort(refresh.rs:95-99) correctly keeps only non-positive balances, matchingdocs/scheduling-runtime-design.md:444, 492;RequestScheduler::idle's doc comment (scheduler.rs:1158-1162) accurately describes a validation gate rather than a state transition, which is the crate's idiom.timing_refresh_duration_ns(cost.rs:53-57) is a strictly-positive fallback chain (compute → unexcluded physical → wall) and is covered forgpu_ns < wait_ns,gpu_ns == wait_ns,wall_ns == 0andwall_ns > 0atcost.rs:468-503.- Acceptance ledgers stay on raw physical time (
refresh.rs:77-79, 83-85), matchingdocs/scheduling-runtime-design.md:498-499. ActionCosts::refresh_order(cost.rs:303-305) is unchanged frommain— the starvation concern raised ate5a69669is resolved by restoration, andpolicy_tests.rs:5964-6057exercisesD = 145 ms > ttl_ns / 499.--retain-idle-creditfollows the established--partial-blockssimulator idiom exactly:store_true, default=None(learning.py:439-440), boolean check in__post_init__(learning_policy.py:83-84), id suffix viaconfiguration_id(learning.py:48-56), same sweep/validate guards. The new test attests/test_scheduling_learning_experiments.py:746-791mirrorstest_partial_block_uncertainty_is_explicit_and_keeps_default_idsclosely (borderline duplication) but adds genuinely newmain()argv-rejection coverage.
Open questions / not verified
- Only a run can settle the PR body's evidence claims: the 64-seed
--preset validate --reference ttlgate results, the Rust/pytestcounts, and the TLA+ conformance run. I did not re-run any of them. - Live GPU readiness-stall behaviour (
tests/server/test_scheduler.py(not opened), power-cap recovery) was not exercised; the readiness-wait exclusion is verified here only by unit tests atcost.rs:468-503. - Whether
helios/README.mdis generated fromdocs/scheduling-runtime-design.mdor maintained by hand (nothing in the repo suggests generation); if a check exists, it should have caught finding 1.