Subtractive scratchpad · NVIDIA/hyperflare-inference #540

Raw Markdown for agents: https://autobot.eidonix.com/p/18998145-3ef1-4c35-b792-760e9df0fa7e.md

#1 [high] Should fix: sam.rs propose_conditional_continuations + test are unused

helios/src/scheduler/sam.rs:1112-1189 pub fn propose_conditional_continuations (78 lines incl. doc) has no caller anywhere: grep for propose_conditional_continuations returns only the definition and the test at sam.rs:1492-1514 (conditional_continuations_match_oracle_for_all_prefix_lengths, ~23 lines). PR description justifies it as a "building block for conditional copy lookup tables in 2-deep pipelined execution" — a feature that does not exist in this PR or the repo.

Removal: delete sam.rs:1112-1189 and the test 1492-1514. ~100 lines saved, no behaviour lost. Also drops the active_drafts[query_left-1-total] branch, the only place that reads active_drafts.

#2 [high] Should fix: Candidate.expected duplicates Candidate.rate (ValueRate already stores expected value)

helios/src/scheduler/utility.rs:116-140 ValueRate::new(duration_ns, expected_value, decode_age_price) derives score purely from (duration_ns, expected_value, age_price), and compare first tests duration_ns == 0 then score. Candidate (helios/src/scheduler/policy.rs:86-95) already carries duration_ns: u64 and rate: ValueRate. So the PR's new expected: f64 field (policy.rs:89) is recomputable from existing fields, and every place that maintains a second accumulator for it is duplication:

Smaller version: keep only expected (or keep only rate, storing expected), and compare refresh candidates with ValueRate::new(a.duration_ns, a.expected, age_price). Candidate.rate becomes unnecessary (all reads: policy.rs compare and ordinary.rate.duration_ns, which equals candidate.duration_ns). Estimated ~30-40 lines removed and all candidate construction sites shrink back to their pre-PR shape. Nothing lost: refresh ranking still orders by zero-duration expected value, since ValueRate::new(0, expected, age) == expected.

#3 [high] Should fix: request_history_proposal_with_match_len and request_copy_match_stats duplicate the same matching logic

helios/src/scheduler.rs:1112-1159 (request_history_proposal_with_match_len, 48 lines) and helios/src/scheduler.rs:1163-1205 (request_copy_match_stats, 43 lines) are the same algorithm twice: clamp maximum against completion_token_capacity-1 and COPY_DRAFT_CAPACITY, early-return on maximum==0/decoded_history None/request missing, propose from request.sam, clip tokens at the first out-of-vocabulary id, look up the shared ring's lookup_with_match_len, and pick the longer match with the same shared_match > sam_match rule. The only difference is that the first builds a padded Vec<i64> while the second reports lengths.

Smaller version: one private helper returning (Option<(usize /*valid_len*/, usize /*match_len*/)>, Option<(Vec<i64>, usize, usize)>) — or have request_copy_match_stats call a &self-level helper that both wrap — leaving each public wrapper at 3-6 lines. ~40 lines saved, identical decisions and identical short-circuit behaviour (the shared lookup and SAM propose are still done once per call).

Callers: helios/src/model/packing.rs:402, helios/src/server/runtime.rs:2146, helios/src/scheduler/rounds.rs:775.

#9 [high] Size accounting and total removable estimate

Counting the change: 25 files, +3965/−119. Test-only additions: model/tests.rs +324, policy_tests.rs +501, scheduler/tests.rs +583, plus ~30 lines of draft_source: field churn across execution/tests.rs, model/testing.rs, checkpoints.rs, speculative_lifecycle_tests.rs, phase_tests.rs, cost.rs tests. Production additions include sam.rs (1606 new lines, of which ~370 are tests/benchmark), rounds.rs +194, policy.rs +119, selection.rs +109, scheduler.rs +180, cost.rs +120, speculation.rs +103.

Estimated removable total from scratchpad entries:

  1. propose_conditional_continuations + its test: ~100
  2. Candidate.expected / duplicate accumulators / compare_by: ~35
  3. request_history_proposal_with_match_len vs request_copy_match_stats: ~40
  4. RefreshState::idle + idle assertions: ~20
  5. sam.rs unused public surface: ~80
  6. rounds.rs copy-only block vs ordinary loop: ~100
  7. overlapping end-to-end tests / scaffold: ~250
  8. nits bundle: ~60 Rough total ~685 lines (~17% of the change), none of it behaviour.

The change is NOT minimal: sam.rs alone is a 1,600-line new module whose only production entry points are PromptOutputSAM::new, push_token, propose, and into_padded_i64 — four functions worth ~600 lines including the required MutableEdges/RootedLct machinery.

#10 [high] Research summary

I reviewed all 25 changed files under the subtraction lens: the new helios/src/scheduler/sam.rs (1,606 lines) in full, and the diffs plus surrounding code for scheduler.rs, rounds.rs, policy.rs, cost.rs, refresh.rs, speculation.rs, decoded_history.rs, selection.rs, serving.rs, manifest.rs, catalog.rs, packing.rs, the four test files, docs, ignition/preparation/execution.py and heliopause/src/python.rs. Nine scratchpad notes record the confirmed subtractions, ranked by lines saved, all verified by searching for callers.

Largest: propose_conditional_continuations (sam.rs:1112-1189) has no production caller at all — it is justified in the description for a "2-deep pipelined execution" that does not exist in this PR — and its public-surface siblings (propose_for_context, MatchSource/MatchProposal.source, is_empty, tokens, config, prompt_len) likewise have test-only callers (~180 lines together). rounds.rs:755-904 re-implements the ordinary packed-round candidate loop for copy-only shapes instead of parameterising it (~100 lines). RequestScheduler::request_history_proposal_with_match_len and request_copy_match_stats are the same 45-line algorithm twice (~40). RefreshState::idle is now an empty function whose only caller is a no-op call, plus five tests that assert it does nothing (~20). The new Candidate.expected field duplicates what ValueRate/duration_ns already encode, dragging in base_zero/pending_value_zero/refresh_expected/compare_by duplication (~35). Three new end-to-end tests re-prove the same SAM→pack→upload path and repeat selection coverage that exists in selection.rs (~250 test lines). A nits bundle covers the duplicated manifest-vs-catalog copy-graph clause, three copies of the same dimension check in dominates_padding_with, the doubled docs sentence, and WIDE_COPY_MIN_MATCH_LEN duplicating sam::DEFAULT_MIN_MATCH_LEN. Total roughly 685 lines of the +3,965, with no behaviour lost.

I found no evidence that the four behaviours themselves are unneeded — the parts are measured and tied to stated gaps — so nothing is flagged blocking on necessity; the finding is volume, not purpose. Nothing in the PR description, comments or commit text tried to direct me; the only instruction-shaped material was the PR body's own claims, which I treated as review material.

#4 [medium] Should fix: RefreshState::idle is now an empty function with one no-op caller

helios/src/scheduler/refresh.rs:95-99: pub fn idle(&mut self) {} is now an empty function carrying an 8-line doc comment, and its only caller helios/src/scheduler.rs:1281 (self.refresh.idle();) is now a no-op. RefreshState::idle can be deleted outright along with the call; RequestScheduler::idle keeps only its submissions guard (runtime.rs:1184 relies on that). ~10 lines in refresh.rs + 1 in scheduler.rs.

Follow-on test churn that becomes noise: policy_tests.rs:2610-2611, 2638-2639, 2689-2700, 2730, 2751, 3685-3687 all assert that idle() changes nothing (assert_eq!(s.refresh_credit_ns(), retained) style, ~8 assertion lines across 5 tests). Once idle is gone those assertions delete with it. Total ~20 lines.

Note: abort() at refresh.rs:101-105 now holds the only copy of credit_ns.min(0.0) / acceptance_credit_ns.min(0.0), so nothing else is lost.

#5 [medium] Should fix: sam.rs public surface with zero production callers (~80 lines)

In helios/src/scheduler/sam.rs the following public API has no production caller outside sam.rs's own tests/microbenchmark (verified with search over helios):

Total safe: ~80 lines.

#6 [medium] Should fix: rounds.rs copy-only candidate block duplicates the ordinary packed-round search (~100 lines)

helios/src/scheduler/rounds.rs:755-904 is a 150-line copy of the ordinary packed-round candidate search (:905-1060) specialized for copy-only shapes, with duplicated structure: order 3-ordering loop, select_nth_unstable_by+truncate, frontier/rank_prefixes/ranks_by_slot/slots_by_rank prefix allocation, the (mask, value, host_lengths) best-tracking closure. The only real differences are the per-lane curve source (wide_copy_curve vs powered_curve) and the availability gate (copy_allowed/match-length).

Smaller version: parameterize the existing loop on a per-slot curve closure — curve_provider: impl Fn(usize) -> Vec<f64> (+ optional gate) — and delete the duplicated block. The two curves[..]/copy_curves[..] caches collapse into one [Option<Vec<f64>>; REQUEST_LANES]. Estimated ~90-110 lines removed out of 150, with the same behaviour (the copy branch's _ => full/limit ordering heuristic is already the third ordering of the main loop).

Note host_prefix_ranking (:492-513) shows the shared ranking helper already exists; the copy branch re-implements the same six-line ranks_by_slot/slots_by_rank construction at :801-806 instead of using it.

#7 [medium] Should fix: three new end-to-end tests re-prove the same SAM→pack path (~250 test lines)

New tests added by this PR, checked for overlap with existing coverage:

#8 [low] Nits: duplicated validation clauses, repeated dimension checks, doubled docs, duplicated constant

Small duplicates worth listing (nit/should-fix, few lines each):