Subtractive scratchpad · NVIDIA/hyperflare-inference #540

Raw Markdown for agents: https://autobot.eidonix.com/p/bb4cd93c-463b-4ee5-9f67-fbbe7028170a.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.

#12 [high] Additions verified this turn: history_proposal/lookup left production-dead, sam accessors, unreachable wide-copy curve fallback, stale docs

Re-verified at head 14019718. Report #11 stands; these are additions/corrections found by following callers of the code the PR rewired.

  1. RequestScheduler::history_proposal (helios/src/scheduler.rs:1094-1097) is now production-dead. Both production callers were switched by this PR to the per-request SAM path: helios/src/model/packing.rs:402 now calls request_history_proposal, and helios/src/server/runtime.rs:2146 likewise (grep for history_proposal\( returns only tests: helios/src/scheduler/tests.rs:1956,1970-1991,2069, helios/src/server/runtime/phase_tests.rs:583,1835). Its only remaining consumer is DecodedHistory::lookup (helios/src/scheduler/decoded_history.rs:180-183), a 4-line wrapper over lookup_with_match_len that also has no production caller. Delete both and re-point the ~11 test assertions at request_history_proposal/lookup_with_match_len: ~10-18 lines, and one fewer public entry point on the scheduler. (Nit: the ring behaviour itself is still reachable as the SAM fallback, so no coverage is lost.)

  2. LiveRequest::sam() (helios/src/scheduler.rs:383-385), PromptOutputSAM::output_len() (helios/src/scheduler/sam.rs:961-963) and the other unread accessors (config() :953-955, prompt_len() :957-959, PromptSAM::is_empty() :454-456, PromptSAM::tokens() :458-460, PromptSAM::build :282-285, push_slice :1023-1027) have no production caller — verified by grep over helios/src: only sam.rs tests, scheduler/tests.rs:2102,2125. Fold into note #5; this raises that group from ~80 to ~95 lines. SamConfig + with_config/from_shared_prompt (~25 lines, sam.rs:39-62, 928-947) are also production-unused because PromptOutputSAM::new (scheduler.rs:1852) is the only constructor, so the four DEFAULT_*/config knobs can collapse to constants.

  3. rounds.rs:541-553 wide_copy_curve's else branch is unreachable: wide_copy_curve is called only at rounds.rs:795, inside the copy-shape branch guarded by self.decoded_history.is_none() → continue (rounds.rs:759), and request.copy_calibration is Some exactly when decoded_history was Some at admission (scheduler.rs:1853-1856, and enable_history_drafts refuses to run after any admission, scheduler.rs:1086-1092). The body becomes calibration.curve(...).map(|p| p.powf(alpha)).collect(): ~8 lines.

  4. Docs the change leaves behind (should be edited in this PR, not appended to): docs/cli-design.md:200-201 still says --history-drafts "does not change the graphs" — false now, selection.rs:275-298,375-396 retains/prunes copy-only graphs, drops kernels and rewrites speculative_widths; docs/mtp-design.md:22-29 says "Both settings use the same captured MTP graphs and buffers" — the wide copy graphs are new; docs/mtp-design.md:31-40 describes the shared ring only, with no mention of the per-request SAM that now takes precedence, and docs/scheduling-theory.md:726-727 still asserts "Idle discards positive credit", contradicting the new RefreshState behaviour (refresh.rs:95-105) and the edited docs/scheduling-runtime-design.md. Each is a one-sentence replacement; the subtraction is the stale claim.

Revised total: ~710 removable of +3965/-119 (items 1-3 add ~25-30 to report #11's ~685; item 4 is doc correction, not line count).

Nothing in the PR body, comments or code attempted to instruct me; the only instruction-shaped text was the PR's own claims about its behaviour, which I checked against the code.

#13 [high] Report of 2026-11-26 (rev 2), run 1232 — revised to ~710 removable lines

Verdict: make it smaller first. The four behaviours are argued and measured; the volume is not. The change: 25 files, +3965 / −119. Could remove: about 710 lines, in 9 places (all verified at head 14019718; supersedes entry #11).

Ranked by lines saved:

  1. Should fix — ~250 test lines. helios/src/model/tests.rs:846-953 and :1861-2075 are the same SAM→plan→pack→upload walk twice; the wide one also re-proves legacy-load retention already owned by helios/src/runtime_core/selection.rs:1876-1940 and W=24 selection already owned by helios/src/scheduler/tests.rs:4107-4340. helios/src/scheduler/tests.rs:1994-2126 re-proves sam.rs's own prompt-match/recency/isolation tests; only its admission wiring and the status==3 path are scheduler-specific. Keep the wide test plus three folded assertions, keep selection.rs, trim 1994-2126 to admission. Every fibre stays covered once.

  2. Should fix — ~100 lines. helios/src/scheduler/rounds.rs:755-903 re-implements the ordinary packed-round search at :905-1060: same 3-ordering loop (:818-829 vs :981-992), same rank closure, same select_nth_unstable_by+truncate+sort, same frontier.clear(), mask/host_lengths/lane_terms/best-tracking (:840-876 vs :993-1046). The ranks_by_slot/slots_by_rank build at :801-806 re-implements host_prefix_ranking (rounds.rs:492-513). One loop parameterised on a per-slot curve provider (+ the :769-790 availability gate) collapses the curves/copy_curves caches at :747-748 into one; the copy branch's third ordering is already the main loop's.

  3. Should fix — ~100 lines. helios/src/scheduler/sam.rs:1112-1189 propose_conditional_continuations has no production caller; grep finds only its own test sam.rs:1491-1514. Its doc justifies it with "2-deep pipelined execution", which exists nowhere in this PR or the repo (rounds.rs plans one round at a time). Delete both.

  4. Should fix — ~95 lines. Test-only SAM surface, all with zero production callers: propose_for_context (sam.rs:1068-1110 + the 8-line block at :1459-1466), MatchSource + MatchProposal.source + the computation in both build_proposal (:1216-1220) and the oracle (:1262-1266) + 4 assertions, PromptSAM::build (:282-285), is_empty (:454-456), tokens (:458-460), PromptOutputSAM::config (:953-955), prompt_len (:957-959), push_slice (:1023-1027), LiveRequest::sam() (scheduler.rs:383-385) and output_len (sam.rs:961-963) which exist only for scheduler/tests.rs:2102,2125. SamConfig/with_config/from_shared_prompt (sam.rs:39-62,928-947) are production-unused too — PromptOutputSAM::new (scheduler.rs:1852) is the only constructor — so the four knobs can collapse to the DEFAULT_* constants (~25 more). Keep the #[ignore] microbenchmark accessors.

  5. Should fix — ~40 lines. helios/src/scheduler.rs:1112-1159 vs :1163-1205 are the same algorithm twice: clamp by completion_token_capacity-1 and COPY_DRAFT_CAPACITY, early-return, fetch request, propose and clip at first out-of-vocabulary id, ring lookup via lookup_with_match_len, pick shared iff shared_match > sam_match. One private helper returning (tokens, count, match_len); request_copy_match_stats becomes (count, match_len) and request_history_proposal_with_match_len the padded form. request_history_proposal (:1102-1109) is a 6-line pass-through whose callers use only (tokens, count).

  6. Should fix — ~35 lines. Candidate.expected (policy.rs:89) is recomputable from duration_ns + ValueRate (utility.rs:122-132: with duration_ns == 0 the score is the expected value), yet it drags in base_zero (rounds.rs:966), pending_value_zero (:997-998,1002,1013,1038), the extra value_zero/expected plumbing (:1040-1054), refresh_expected (policy.rs:1224-1245), :1471-1479, and the compare_by/compare_refresh split (policy.rs:1313-1338). Keep either rate or expected, not both.

  7. Should fix — ~20 lines. RefreshState::idle (refresh.rs:95-99) is now {} and its only caller (scheduler.rs:1281) is a no-op; delete both (keep RequestScheduler::idle's submissions guard that server/runtime.rs:1184 uses), plus the idle-does-nothing assertions at policy_tests.rs:2610-2611,2638-2639,2689-2700,2730,2751,3685-3687. abort() keeps the clamp logic.

  8. Should fix — ~18 lines. This PR switched both production callers to the per-request SAM path (model/packing.rs:402, server/runtime.rs:2146), leaving RequestScheduler::history_proposal (scheduler.rs:1094-1097) with test-only callers and DecodedHistory::lookup (decoded_history.rs:180-183, a 4-line wrapper over lookup_with_match_len) with none. Delete both; re-point the ~11 assertions (scheduler/tests.rs:1956-1991,2069, server/runtime/phase_tests.rs:583,1835) at request_history_proposal/lookup_with_match_len.

  9. Nit — ~55 lines. manifest.rs:844-846's copy-graph clause is subsumed by catalog.rs:123-131 (superset, runs on load) and restated at ignition/preparation/execution.py:102-108. rounds.rs:541-553's wide_copy_curve else-branch is unreachable (:759 skips shapes when decoded_history.is_none(), and copy_calibration is Some exactly then — scheduler.rs:1853-1856,1086-1092), so the body is one map: 8 lines. policy.rs:158,166,175 are the identical physical-dimension early-out, and short()/long() are built twice; hoist once (~10). prune_padding's new second pass (policy.rs:225-254) re-tests the predicate of dominates_padding_with's new first branch (:143-165). WIDE_COPY_MIN_MATCH_LEN (speculation.rs:17-18) duplicates sam::DEFAULT_MIN_MATCH_LEN and the two must stay equal, else the wide-copy gate silently stops matching the proposal threshold. Doc sentence "idle retains earned credit" appears twice.

Left stale by the change (should be edited here, not appended to): docs/cli-design.md:200-201 still says --history-drafts "does not change the graphs" (it now retains/prunes copy-only graphs, drops kernels and rewrites speculative_widths — selection.rs:275-298,375-396); docs/mtp-design.md:22-29 "Both settings use the same captured MTP graphs and buffers"; docs/mtp-design.md:31-40 describes only the shared ring, never the SAM that now takes precedence; docs/scheduling-theory.md:726-727 still asserts "Idle discards positive credit", contradicting the new refresh.rs:95-105 and the edited docs/scheduling-runtime-design.md.

Not a finding: the four behaviours (each maps to a stated gap with a measurement); the MutableEdges/RootedLct machinery (~600 lines) is the price of O(log M) recency and has no equivalent here. Nothing in the PR, comments or code tried to direct the review.

#14 [high] Research summary

Reviewed PR #540 at head 14019718 under the subtraction lens: all 25 changed files, every changed function in surrounding code, and the callers of the paths it rewires. Nine confirmed subtractions, ~710 removable lines of +3965/−119, ranked by lines saved and recorded in the scratchpad (entry #13 supersedes my earlier #11).

Largest: rounds.rs:755-903 re-implements the ordinary packed-round search at :905-1060 (~100); sam.rs:1112-1189 propose_conditional_continuations and the test-only SAM surface (propose_for_context, MatchSource, SamConfig knobs, unread accessors) have no production caller (~195 together); three new end-to-end tests re-prove the same SAM→plan→pack→upload walk already owned by selection.rs and sam.rs (~250); scheduler.rs:1112-1205 is the same match algorithm twice (~40); Candidate.expected duplicates ValueRate and drags in base_zero/pending_value_zero/refresh_expected (~35); empty RefreshState::idle plus no-op assertions (~20); and this PR left RequestScheduler::history_proposal + DecodedHistory::lookup production-dead by switching both callers to the SAM path (~18). Nits cover the duplicated manifest/catalog copy-graph clause, an unreachable wide_copy_curve fallback, triplicated dimension checks and the duplicated min-match constant (~55).

I also recorded four docs the change contradicts (docs/cli-design.md:200-201, docs/mtp-design.md:22-29 and :31-40, docs/scheduling-theory.md:726-727) as places to edit rather than extend. The behaviours themselves are measured and tie to stated gaps, so nothing is flagged on necessity — the finding is volume. No text in the PR or its comments tried to direct my review.

#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:

#15 [medium] Index note: entry #13 is the authoritative final report; #11 is superseded

Use entry #13 as the report. It consolidates and supersedes #11 (the earlier revision of the same report) and re-states, with current line numbers at head 14019718, every finding below.

Mapping of supporting notes:

Also worth carrying into the report: the repository's own automated review (flare-autobot comment, 2026-11-26 17:56) independently reached a matching subtract list — copy-loop duplication ~100, dead SAM API ~150, RefreshState::idle, one ProposalSource::from_wire ladder instead of three (serving.rs:58-63, python.rs:225-233, selection.rs:144-148), and 150-250 test lines — and estimated 550-685 removable. My ~710 is consistent with that and adds the history_proposal/lookup pair, the SamConfig knob collapse and the unreachable wide_copy_curve fallback (three ProposalSource wire ladders are a legitimate ~15-line nit I had not recorded separately; it belongs under #13 finding 9 if the report wants it).

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

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