Review of PR #540 (simplicity lens): helios cost-refresh recovery, prompt+output SAM copy-drafts, calibrated wide copy-verify
Key findings
Four should-fix findings, all deletions, none blocking. At head 1401971 (25 files, +3965/−119) the diff carries code that no production path executes: an emptied RefreshState::idle kept as a documented no-op (finding 1), ~150 lines of SAM API with no caller including a documented "2-deep pipelined execution" that does not exist in the tree (finding 2), a public scheduler entry point history_proposal that this PR itself orphaned (finding 3), and a copy-only cohort loop that duplicates the ordinary packed loop statement-for-statement (finding 4). Four nits cover duplicate constants, a duplicated arbitration rule, and one unreachable branch.
Standard applied: docs/design-review.md:16 — "Keep Helios as simple as possible"; AGENTS.md:338 — same principle. Every other changed path in the diff reads as load-bearing: I followed callers for the cost/refresh arithmetic, the padding-dominance rewrite, the copy-only graph gating at each boundary, and the packing path, and found live production callers for each (see "Cleared" below).
Should fix
1. RefreshState::idle is an empty function — delete it rather than keep a documented no-op
File: helios/src/scheduler/refresh.rs:95-99
/// Retains earned positive credit (capped at `CREDIT_CAP_NS`) and negative
/// debt across idle periods. Idle intervals add neither credit nor ordinary
/// duration, preserving `P <= 0.002 / 0.998 * O + D` for timing refresh and
/// `P <= 0.01 / 0.99 * O + D` for acceptance learning.
pub fn idle(&mut self) {}
This PR emptied the body. Retention across idle is now the absence of mutation, which is the default; abort (refresh.rs:101-105) kept the discard logic and is unchanged in spirit.
Callers / layers: RequestScheduler::idle (helios/src/scheduler.rs:1277-1283) validates submissions.is_empty() then calls self.refresh.idle(); the server calls self.scheduler.idle()? at helios/src/server/runtime.rs:1184. Three layers of API to express "do nothing after asserting the queue is empty".
Why it matters: the doc comment asserts a behaviour guarantee at a site that no longer implements anything; a reader chasing the invariant from the comment has to reconstruct it from complete (refresh.rs:71-93) and abort. The PR's own doc makes the same claim — docs/scheduling-runtime-design.md:438-439 ("Idle retains earned credit and negative debt; abort discards positive credit and preserves debt") — which after this change is true only because nothing happens.
Tests that now only assert the no-op: policy_tests.rs:2689 (not opened), 2699, 2730, 2751, 6102, 6108, 6153 (s.idle().unwrap() then assert credit unchanged), and policy_tests.rs:3685 (not opened) (state.idle() directly on a RefreshState). The surviving credit assertions prove the invariant on their own, because the scheduler simply runs another request in between. The only meaningful idle calls are as a validator: 2610, 2638 (unwrap) and 2626 (assert!(s.idle().is_err()) with outstanding submissions).
Fix: delete RefreshState::idle. Either delete RequestScheduler::idle and move the empty-submissions check to the server call site, or keep the public scheduler method, rename it assert_idle, and drop the self.refresh.idle() line. Remove the .idle().unwrap() lines above. Update docs/scheduling-runtime-design.md:438 to say no scheduler action mutates refresh credit between requests and that abort is the only path that discards positive credit.
2. sam.rs ships ~150 lines of API with no production caller
File: helios/src/scheduler/sam.rs (new module, 1607 lines), exported as pub mod sam at helios/src/scheduler.rs:23.
Production uses exactly four things: PromptOutputSAM::new (scheduler.rs:1852), propose (scheduler.rs:1128, 1179), push_token (scheduler.rs:1234, 3016), and MatchProposal::into_padded_i64 (scheduler.rs:1151).
Everything below is reached only from tests in the same file (verified by tree-wide search of each symbol):
| Item | Location | Only caller |
|---|---|---|
propose_for_context |
sam.rs:1070-1110 | sam.rs:1463 (oracle test) |
propose_conditional_continuations |
sam.rs:1118-1189 | sam.rs:1505 |
MatchSource enum |
sam.rs:64-69 | nothing; constructed at 1217/1219/1263/1265 |
MatchProposal::source |
sam.rs:80-81 | assertions at 1301, 1309, 1321, 1336 |
PromptSAM::build |
sam.rs:283 | sam.rs:1519, 1569; production goes through build_capped (sam.rs:930) |
PromptSAM::{state_count, transition_count, memory_bytes} |
sam.rs:462-476 | sam.rs:1363, 1375, 1520-1521, 1540, 1573, 1597-1600 |
PromptOutputSAM::{state_count, dynamic_memory_bytes, memory_bytes, prompt_sam, config, prompt_len} |
sam.rs:949-984 | sam.rs:1526-1527 and tests |
push_slice |
sam.rs:1023 | 1319, 1332, 1351, 1366, 1495, 1529-1530 |
SamConfig, with_config, from_shared_prompt, config(), prompt_sam() |
sam.rs:41-61, 929-955 | new (sam.rs:924-926) passes SamConfig::default(); non-default SamConfig values exist only in test literals (1340-1344, 1381, 1385, 1395, 1423-1427) |
Two specific problems beyond dead weight:
propose_conditional_continuations's doc (sam.rs:1112-1117) says it provides "a building block for conditional copy lookup tables in 2-deep pipelined execution". There is no 2-deep pipelined execution in the tree, no caller, and the PR description does not mention it. 72 lines of careful incremental-cursor logic must now be maintained and kept correct by the SAM oracle for a consumer that does not exist.- The module doc claims sharing that does not happen: sam.rs:9-13 says
PromptSAM"compacts transitions into a flat sorted edge table suitable for zero-copy sharing across requests viaArc" and thatPromptOutputSAM"pairs anArc<PromptSAM>with a lazy per-request dynamic automaton". Production builds a fresh private automaton per request at admission (scheduler.rs:1849-1852), andfrom_shared_prompt(sam.rs:935) — the only way to actually share — has no non-test caller.
Fix: keep new/from_shared_prompt (whichever survives), propose, push_token, MatchProposal::{tokens, match_len, into_padded_i64}, and the private builders (build_capped, walk_context, resolve_match, build_proposal, the LCT). Delete propose_for_context + its oracle call site (1463), propose_conditional_continuations + its test (1492-1514), MatchSource/source and its four constructor sites and four assertions, PromptSAM::build, push_slice (tests can loop push_token), and the accessor block (keep state_count/transition_count as #[cfg(test)] if the size bound matters — nothing in the server reads SAM memory_bytes; there is no metric wired to it). Move SamConfig/with_config under #[cfg(test)] and have new read DEFAULT_* directly. Then correct sam.rs:9-13. Net ~150 lines plus ~6 tests that only exercise the removed surface, and a smaller pub mod sam surface.
Cost of the delete, worth calling out in the PR: the randomized oracle at sam.rs:1463/1505 covers mostly the removed functions; before deleting, re-point the oracle at propose so the surviving walk_context/resolve_match machinery keeps brute-force coverage.
3. RequestScheduler::history_proposal lost both of its production callers in this PR
File: helios/src/scheduler.rs:1094-1097
Before this PR history_proposal had exactly two production callers. This PR moved both to the handle-keyed request_history_proposal: helios/src/model/packing.rs:402 (not opened) and helios/src/server/runtime.rs:2143-2150 (called via the wrapper at scheduler.rs:1102-1109).
Full caller list after the change (search history_proposal\b): tests only — helios/src/scheduler/tests.rs:1956, 1970, 1972-1974, 1979, 1985, 1991 and helios/src/server/runtime/phase_tests.rs:583 (not opened), 1835. DecodedHistory::lookup (helios/src/scheduler/decoded_history.rs:180-183) is now reachable only from history_proposal and the ring's own oracle test.
That leaves three entry points for one lookup: request_history_proposal (prod, packing), request_copy_match_stats (prod, rounds.rs:775), and the context-keyed history_proposal (dead outside tests).
Why it matters in this lens: history_proposal bypasses the SAM entirely — it is exactly the prompt-blind path the PR exists to replace. Leaving it public, and test-covered, means a future caller can silently reintroduce prompt-blind drafts while the PR's stated invariant ("per-request SAM preferred on equal or longer match length") still appears to hold.
Fix: delete pub fn history_proposal; re-point the shared_drafts_learn_committed_outputs_* test at request_history_proposal (the test already admits a live request with a handle, and the handle-keyed API is the path production takes — a more faithful test). Keep DecodedHistory::lookup as pub(crate) for the ring's oracle test at decoded_history.rs:276.
4. rounds.rs copy-only cohort loop duplicates the ordinary packed loop (~110 lines)
File: helios/src/scheduler/rounds.rs:755-903 vs rounds.rs:925-1060
packed_round_candidates now holds two cohort-scoring loops over the same shape table. The copy-only block (entered on proposal_source == Mtp && shape.draft_source == Some(Copy) && shape.width > 1, ending continue at 903) re-implements, statement for statement:
- prefix ranking:
scores/rank_prefixes(791-800) vsforecasts/gains/ranks(929-956) - per-lane
base/full(808-816) vsbase/base_zero/full/limits(965-976) - the 3-ordering loop with
select_nth_unstable_by+sort_unstable_by(818-838) vs 981-992 — same text, different closure frontier.clear(),host_lengths,lane_terms,mask |= 1 << slot(839-867) vs 993-1012- the
(mask.count_ones(), Reverse(mask))tie-break (868-875) vs 1040-1045 - the
expectedrecompute andCandidate { .. }construction (878-902) vs 1048-1059
Real differences, all expressible as parameters: copy lanes are filtered to copy_available via request_copy_match_stats (769-787), the copy path has no host_ranking and no surplus_table, and its per-lane curve comes from wide_copy_curve rather than powered_curve. Both paths also carry parallel per-slot memo arrays — curves and copy_curves at rounds.rs:747-748 — read at 794/812/857/881 and 934.
Why it matters: neither loop is wrong today; the risk is drift. The cohort tie-break and the expected-value recompute are the exact properties the new padding-dominance tests (policy_tests.rs:58-200 (not opened)) and the wide-copy tests depend on, and they now exist twice. It is also the single largest deletable block in the diff.
Fix: one loop taking lanes: &[usize] (available or copy_available), a curve: impl Fn(&LiveRequest, bool) -> Vec<f64> provider, and surplus: Option<_> / host_ranking: Option<_>; replace curves/copy_curves with a single [Option<Vec<f64>>; REQUEST_LANES]. Net ≈ −110 lines.
Nits
5. The draft_source 0/1/2 decoding is written three times
helios/src/runtime_core/serving.rs:58-63—0 => None, 1 => Mtp, 2 => Copy, _ => invalid("unknown graph draft source")heliopause/src/python.rs:223-232(not opened) — same ladder withPyValueError::new_err("unsupported graph draft_source"), plus an absent-key default toMtpthat the others lackhelios/src/runtime_core/selection.rs:144-148—"mtp" => 1, "copy" => 2for the config string, producing a raw number compared againstgraph.draft_sourceat 149, 169, 197 (execution/manifest.rs:841-850(not opened) compares againstProposalSource::Copyfor validation and does not re-implement the ladder.)
Three error messages and three chances to drift if a third source is added, while ProposalSource::parse already exists (helios/src/scheduler/speculation.rs:30-38). Fix: add ProposalSource::from_wire(u32) -> Result<Option<Self>> next to parse; call it from serving.rs and python.rs (not opened), with python.rs (not opened) alone handling the absent-key default; have selection.rs parse the config string to the enum and compare enums instead of u64 (the numeric source binding at 144 is what forces the numeric comparisons).
6. request_copy_match_stats duplicates request_history_proposal_with_match_len
helios/src/scheduler.rs:1163-1205 vs 1112-1159. Both clamp maximum with the same three-way .min chain (1117-1119 / 1168-1170), return zeros on maximum == 0 || decoded_history.is_none() (1120-1122 / 1171-1173), truncate the SAM proposal at the first out-of-vocabulary token (1130-1137 / 1180-1185), and apply "shared ring wins only when shared_match > sam.match_len" (1145 / 1197). They differ only in whether a padded Vec<i64> is built. Callers: rounds.rs:775 and packing.rs:402 (not opened) / server/runtime.rs:2146 respectively.
The arbitration rule is what the PR description states as an invariant, and it now lives twice with no test that the two agree; the packing path and the scheduling path could disagree about which source won. Fix: keep request_copy_match_stats as the primitive returning (count, match_len) plus the winning tokens, and implement request_history_proposal_with_match_len on top of it, padding those tokens (propose is O(1) amortized). One copy of the clamp, the OOV truncation and the tie-break.
7. Two constants for the same 6-token threshold
speculation::WIDE_COPY_MIN_MATCH_LEN = 6 (helios/src/scheduler/speculation.rs:18) gates wide-copy lanes at rounds.rs:776, while sam::DEFAULT_MIN_MATCH_LEN = 6 (helios/src/scheduler/sam.rs:22, via SamConfig::default() at sam.rs:56) is the threshold inside propose, so a proposal never reports a shorter match_len. The rounds gate is only meaningful because the two happen to be equal; sam.rs:1287 even asserts DEFAULT_MIN_MATCH_LEN == 6. Fix: have rounds.rs refer to DEFAULT_MIN_MATCH_LEN (or one shared constant), or drop the rounds gate. Today nothing states the relationship.
8. Unreachable fallback in wide_copy_curve
helios/src/scheduler/rounds.rs:541-553 has an else arm producing a raw geometric prior when request.copy_calibration is None. copy_calibration and decoded_history are created from the same condition at admission (scheduler.rs:1849-1856, .decoded_history.is_some().then(...) twice), and the copy block requires self.decoded_history.is_some() (rounds.rs:759) before taking any curve, so copy_calibration is always Some on that path; expected_copy_tokens (rounds.rs:555) is only called under is_copy_only_step (scheduler.rs:2507-2518), for graphs retained only with --history-drafts (runtime_core/selection.rs:184). Fix: take &CopyCalibration as the argument, or expect. (This is inference from the constructors — only tests build schedulers with copy graphs and no history, so no test contradicts it.)
Cleared — checked and load-bearing
So the "no blocking" verdict is scoped: I read each of these in context and found live production callers, not merely unexamined code.
cost.rs(not opened) refresh arithmetic:observed_compute_duration_ns/timing_refresh_duration_ns(cost.rs:31-40 (not opened)) used byRefreshState::complete(refresh.rs:74, 77, 84, 87);is_copy_only_step(cost.rs:223-232 (not opened)) has three production callers (scheduler.rs:1207-1209 → server/runtime.rs:1722, scheduler.rs:2507, 2796);max_mtp_draft_tokens(cost.rs:234 (not opened)) one (rounds.rs:751).- Padding-dominance rewrite (
policy.rs:133-262(not opened)): the exact-equality branch was replaced, not duplicated; new tests (policy_tests.rs:58-200(not opened)) drive it throughprune_padding/plan, i.e. real behaviour. - Copy-only graph gating:
selection.rs:275-299+ retained widths 379-396,catalog.rs:91-131(not opened),manifest.rs:840-851(not opened),serving.rs:55-64,python.rs:223-233(not opened) — each is the only gate on one boundary; only the duplicated decoding is recorded above. draft_sourceonGraphDescriptor(manifest.rs:188-191 (not opened)) is required by cost/serving/selection.Candidate.expected(policy.rs:86 (not opened), 1085-1097, 1263-1295, 1465-1480; rounds.rs:722-735, 878-902, 1048-1059) is a genuinely distinct quantity used bycompare_refresh(policy.rs:1329-1339 (not opened)) — keep.LiveRequest.sam/copy_calibration(scheduler.rs:265-266) are pushed on both commit paths (1233, 3016) and read on both proposal paths (1127, 1178) and rounds.rs:774 — no orphan field.- The new behavioural tests — randomized SAM oracle (sam.rs:1400-1469) and
request_sam_proposes_prompt_continuations_and_isolates_requests(scheduler/tests.rs:1995-2126) — prove per-request isolation, output-over-prompt recency, andstatus==3leaving the SAM untouched; keep them after the trim. - No
#[allow(dead_code)]and no new env-var/feature-flag fallbacks were added.
Open questions
- Is
propose_conditional_continuationsthe front half of an unlanded PR? Its doc names "2-deep pipelined execution"; the description does not. If a follow-up exists (perhaps in the sibling #542 or the recipes repos #48/#49), naming it converts finding 2 from "delete" to "land with its consumer". Nothing in the tree settles it. - Does anything intend to read SAM
memory_bytes? No metric, dashboard field, or endpoint references it. If per-request SAM memory accounting is planned, it belongs with that change. SamConfig's four fields in production are allDEFAULT_*; if only the oracle needs to vary thresholds,#[cfg(test)]is enough — but if a follow-up expects to tunemin_match_lenper core, say so.
What could not be verified
helios/src/model/packing.rs (not opened) and helios/src/server/dashboard/scheduler.rs (not opened) were cited from cross-references rather than read in full; the packing.rs:402 (not opened) caller pointer comes from a tree-wide search for history_proposal, not an in-file read of the surrounding function. If the author intends history_proposal to stay as a stable API for an out-of-tree consumer, that would settle finding 3 the other way — a one-line reply, no test needed.