Simplicity report · NVIDIA/hyperflare-inference #540

Raw Markdown for agents: https://autobot.eidonix.com/p/7a4428b0-7122-4023-9b1e-6a3730fc0d74.md

PR #540 simplicity review — head 982a9ce (10 files, +647/−47)

Key findings

Verdict: should-fix issues only — two small ones, four nits. No blocking issues.

The PR has been narrowed since earlier passes (33 files → 10): SAM copy-drafting, wide copy-verify, padding pruning and the history_proposal rewiring are gone, and the Rust diff introduces no new feature flags, env switches, #[allow(dead_code)] or dead fallbacks. What remains that this lens would delete is one stale abstraction (an idle() method whose only action the PR removed, now carrying a doc comment about retention it does not implement) and one near-verbatim duplicated test fixture (~66 lines). The rest are consolidation/documentation nits.

Rules applied: docs/design-review.md:16 and AGENTS.md:338 ("Keep Helios as simple as possible"); AGENTS.md:188-193 ("Reject unsupported abstractions and churn … Refactoring must directly support the requested behavior or remove a demonstrated source of defects or cost"); AGENTS.md:43-65 and .agents/skills/repo-prose/SKILL.md (not opened) (documentation is a present-state specification; comments explain invariants; state evidence as conditions); charter line 12 (keep the runtime small).

Should fix

1. helios/src/scheduler.rs:1158-1168 — idle() is a pure validator wearing the name of the mutation it no longer performs

/// Validates that no execution is in flight across an idle gap.
///
/// Timing-refresh and acceptance-learning ledgers retain bounded earned credit
/// (`<= CREDIT_CAP_NS`) and negative debt across idle intervals because idle adds
/// neither credit nor ordinary duration.
pub fn idle(&mut self) -> Result<()> {
    if !self.submissions.is_empty() {
        return Err("idle requires no submitted execution".into());
    }
    Ok(())
}

This PR deleted the method's entire action (self.refresh.idle()); retention is now simply the absence of a mutation, and RefreshState::abort (refresh.rs:95-99) is the only remaining discard path. What is left is a precondition check that still takes &mut self and whose five-line comment argues a policy the function does not implement — a reader looking for "where does idle zero credit?" is sent here and finds nothing. Why it matters: two sources of truth for one invariant (the code and a comment describing the deleted code), exactly the churn AGENTS.md:188-193 rejects.

Fix: rename to assert_idle(&self) (or inline the submissions.is_empty() check into the single production caller, helios/src/server/runtime.rs:1184) and cut the comment to one line; the retention argument already lives where it belongs, in docs/scheduling-runtime-design.md:443-444 ("Idle retains bounded earned credit (<= 5 ms) and negative debt; abort discards positive credit and preserves debt"). The nine s.idle().unwrap() call sites in policy_tests.rs (2466, 2497, 2552, 2562, 2593, 2614, 5909, 5952, 6041) are a search-and-replace; only policy_tests.rs:2483 exercises the error path.

2. helios/src/scheduler/policy_tests.rs:5812-5878 — new large_prefill_engine duplicates engine_with_terminal_prefill (4364-4406)

Both builders run the same sequence — duration_graphs(1) → drop old prefill kinds → push one GraphDescriptor per prefill capacity, one per terminal capacity → measured_graph_durations — and the inner descriptor literals are field-for-field identical apart from the handle, the name and the two duration constants (estimated_duration_ns: 10 * MS / 12 * MS at 5855/5872 vs the capacity-derived (capacity as u64 / 64 + 1) * MS / (capacity as u64 / 64 + 4) * MS at 4383/4400). Roughly 66 duplicated lines, differing only in scheduler limits (max_active: 1, request_slots: 1, max_sequence_tokens: 131_072, prefill_chunk_size: 8192, pages: 4096, snapshots: 64 vs engine's 8192/512/1024/256), the capacity lists and the duration constants. The duplicated part is exactly the part that must stay in sync with the descriptor layout and with what ActionCosts measures — ActionCosts::prepared keys on kind/capacity, so a field drifting in one copy silently makes the two tests measure different things.

Fix: one builder, e.g. prefill_engine(limits, prefill: &[usize], terminal: &[usize], prefill_ns: impl Fn(usize) -> u64, terminal_ns: impl Fn(usize) -> u64) -> RequestScheduler, with the two existing builders reduced to calls into it (engine_with_terminal_prefill passes engine's limits and the /64 + k closures). Test-only refactor, still within this PR's behaviour (AGENTS.md:188-193 permits churn that supports the change).

Nits

3. helios/src/scheduler/cost.rs:37-45 vs cost.rs:330-337 — one rule, two hand-mirrored implementations

observed_compute_duration_ns (gpu max > 0, None when gpu_ns <= wait_ns, else observed - wait_ns) and ActionCosts::observe (saturating_sub, return when the sample is 0) each restate "device interval minus readiness wait, discard zeros". The doc at cost.rs:31-36 asserts the mirror ("Mirrors ActionCosts::observe") — an invariant kept by hand across two functions that must not drift. Extract the shared sample, fn compute_sample(timing: ExecutionTiming) -> Option<u64> implementing lines 38-42, and let observe call it; observed_compute_duration_ns then only adds the isolated-execution max(wall_ns) from line 43.

4. helios/src/scheduler/cost.rs:47-52 — the doc claims positivity the function does not guarantee

"…ensuring every validated refresh completion incurs a strictly positive charge": the last fallback is timing.wall_ns (line 56), which is 0 when GPU timing is absent and the completion was non-isolated. Positivity actually comes from RefreshState::validate_completion (refresh.rs:63-69), which rejects exactly those probes (observed_duration_ns(timing).is_none() && timing.wall_ns == 0). Fix per repo-prose: state what the function does ("falls back to unexcluded physical, then wall, duration") and put the guarantee where it is enforced ("positivity is enforced by validate_completion on the probe path").

5. helios/src/scheduler/cost.rs:443-502 vs policy_tests.rs:6059-6137 / 6139-6182 — the same boundary matrix proven twice

The new compute_refresh_duration_excludes_readiness_wait_and_charges_positive_on_zero_compute walks <, == and missing-GPU cases at helper level, while timing_refresh_excludes_readiness_wait_from_episode_debt and readiness_wait_exceeding_gpu_duration_does_not_cause_zero_charge_refresh_loop prove the same rule end-to-end through RefreshState::complete/plan (including wall_ns 0 and 130 * MS at 6149). Keep the </==/wall_ns-0/>0 matrix in one place — the policy tests are the ones that establish behaviour, so the helper test can shrink to the two unit-level facts the policy path cannot show (queued vs isolated max(wall_ns), and observed_compute_duration_ns == None when GPU timing is absent). Also, lines 456-457 and 460-461 assert timing_refresh_duration_ns == observed_compute_duration_ns twice per case; one derived check (for t in [isolated, queued] { … }) covers both.

6. scripts/scheduling_sim/learning.py:105-109, :132, :439-440, :477-483 — one boolean added to four parallel hand-maintained tuples

retain_idle_credit had to be appended by hand to the defaults filter (105-109), the categorical/non-sweepable set (132), the parser (--retain-idle-credit, 439-440) and the validation-override list (477-483). Those lists already drift in pairs for partial_blocks / mean_estimator. Fix: derive the boolean/categorical set once from dataclasses.fields(PolicyConfig) (frozen, hashable field types), so the next boolean costs one line and cannot be forgotten in one of the four places. PolicyConfig.retain_idle_credit (learning_policy.py:47) defaults to False, which is the right modelling choice for parity with main, and Policy.idle() (learning_policy.py:671-677) reads it as a config-validated bool (:83-84).

Verified clean — do not re-flag

Open questions / limits