Review of PR #540 (simplicity lens): helios cost-refresh recovery, prompt+output SAM copy-drafts, calibrated wide copy-verify
Key findings
RefreshState::idleis now an empty function (helios/src/scheduler/refresh.rs:95-99) that this PR left behind with a five-line doc comment explaining that it does nothing.RequestScheduler::idle(helios/src/scheduler.rs:1277-1283) still validates the queue and calls it, and the server still calls that (helios/src/server/runtime.rs:1184). Delete the method, collapse the wrapper. Should fix.helios/src/scheduler/sam.rsexports ~150 lines that no production path executes:propose_for_context(1070-1110) andpropose_conditional_continuations(1118-1189) are called only from the in-file oracle test;MatchSource/MatchProposal::source(64-82) is read only by tests;PromptSAM::build(283),push_slice(1023) and the accessor block (462-476, 970-984) are test/benchmark-only. All of it sits behindpub mod sam(scheduler.rs:23). Should fix.- Two duplicated mappings worth collapsing: the
0/1/2 -> Option<ProposalSource>ladder appears three times, andrequest_copy_match_statsduplicates the arbitration rule ofrequest_history_proposal_with_match_len. Nits. - No blocking issue in this lens. The rest of the diff (cost/refresh arithmetic, padding dominance, copy-only graph gating, packing) has real callers on every path I followed.
Standard applied: AGENTS.md:338 — "Keep Helios as simple as possible"; docs/design-review.md:16-21 — same principle as review principle 1. Both cut against shipping an empty method kept for shape, and against exporting a module surface that only tests consume.
Should fix
1. RefreshState::idle is an empty function — delete it instead of keeping 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) {}
The old body (which clamped/looked at credit) is gone: retention across idle is now the absence of any mutation, which is the default. abort (refresh.rs:101-105) kept the discard logic this PR inlined, so nothing about abort changed.
Callers:
helios/src/scheduler.rs:1277-1283—RequestScheduler::idlecheckssubmissions.is_empty()then callsself.refresh.idle().helios/src/server/runtime.rs:1184—self.scheduler.idle()?;in the server idle path.
So three layers of API exist to express "do nothing after asserting the queue is empty".
Why it matters: the doc comment states a behaviour guarantee that the code no longer implements at that site — the guarantee now lives entirely in the absence of the call's effect. A reader following the invariant from the comment will look for mutation here and, finding an empty body, has to reconstruct the argument from complete (refresh.rs:71-93) and abort. The PR's own docs make the same claim ("Idle retains earned credit and negative debt; abort discards positive credit and preserves debt", docs/scheduling-runtime-design.md:432), which after this change is true only because nothing happens.
Tests that lean on the no-op — they call s.idle().unwrap() and then assert credit is unchanged, which holds regardless of whether idle exists:
helios/src/scheduler/policy_tests.rs:2689, 2699, 2730, 2751— credit-retention assertions around idle.helios/src/scheduler/policy_tests.rs:5714, 5720, 5765— same pattern in the newer refresh tests.helios/src/scheduler/policy_tests.rs:3685callsstate.idle()directly on aRefreshState.helios/src/scheduler/policy_tests.rs:2610, 2626, 2638exerciseRequestScheduler::idleas a validator (2610/2638 unwrap, 2626 asserts an error while submissions are outstanding). These are the only meaningful ones, and they survive if the wrapper is kept as a validator.
Smaller version: delete RefreshState::idle. Either delete RequestScheduler::idle and move the empty-submissions assertion to its server call site, or keep the public scheduler method, rename it assert_idle and drop the self.refresh.idle() line. Then remove the .idle().unwrap() lines at 2689/2699/2730/2751/5714/5720/5765 and 3685 — the surrounding credit assertions still prove the invariant (positive credit and negative debt survive across the transition) because the scheduler simply runs another request in between. Update docs/scheduling-runtime-design.md:432 to say that no scheduler action mutates refresh credit between requests, and that abort is the only path that discards positive credit.
2. sam.rs ships a large API surface 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: PromptOutputSAM::new (scheduler.rs:1852), propose (scheduler.rs:1128 via request_history_proposal_with_match_len, and scheduler.rs:1179 via request_copy_match_stats), push_token (scheduler.rs:1234, 3016), and MatchProposal::into_padded_i64 (scheduler.rs:1151).
Everything below is called only from tests in the same file (verified by searching the whole tree):
| Item | Location | Only caller |
|---|---|---|
propose_for_context |
sam.rs:1070-1110 (41 lines) | sam.rs:1463, randomized oracle test |
propose_conditional_continuations |
sam.rs:1118-1189 (72 lines) | sam.rs:1505 |
MatchSource enum |
sam.rs:64-69 | nothing; constructors at 1217/1219/1263/1265 |
MatchProposal::source field |
sam.rs:80-81 | assertions at sam.rs:1301, 1309, 1321, 1336 |
PromptSAM::build |
sam.rs:283 | sam.rs:1519, 1569 (tests); production always uses build_capped via PromptOutputSAM::new at sam.rs:930 |
PromptSAM::{state_count, transition_count, memory_bytes} |
sam.rs:462-476 | sam.rs:1363, 1375, 1520-1521, 1540, 1573, 1597-1600 (incl. ignored microbenchmark) |
PromptOutputSAM::{state_count, dynamic_memory_bytes, memory_bytes, prompt_sam, config, prompt_len} |
sam.rs:949-984 | sam.rs:1526-1527, tests |
push_slice |
sam.rs:1023 | sam.rs:1319, 1332, 1351, 1366, 1495, 1529-1530 (tests) |
Why it matters: propose_conditional_continuations is the sharpest case. Its doc says it provides "a building block for conditional copy lookup tables in 2-deep pipelined execution" — there is no 2-deep pipelined execution in this tree, no caller, and nothing in the PR description mentions the feature. The code is dead on arrival, and its 72 lines plus the careful incremental-cursor logic (p_state = self.prompt_cursor_state at 1130 onward) must now be maintained and kept correct by the SAM oracle test for a consumer that does not exist. MatchSource is the same pattern one level down: it exists so a proposal can say whether the match came from prompt or output, and nothing in Helios branches on that, so source is a field every construction site must fill (four sites) to satisfy four test assertions. The accessor block is pure accounting (memory_bytes sums capacity() figures at 902/983) with no metric wired to it anywhere in the server.
Relevant rule: docs/design-review.md:16-21 and AGENTS.md:338. Also note this is Helios' externally visible API — pub mod sam — so the surface is not just internal noise.
Smaller version: keep PromptOutputSAM::{new, from_shared_prompt}, 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(1070-1110) and its oracle call site (1463) — usepropose(the query is always the request's own suffix in production).propose_conditional_continuations(1118-1189) and its test (1492-1514) — unless a follow-up PR is imminent, in which case say so in the description (see open questions).MatchSource,MatchProposal::source, the four constructor sites and the four assertions (1301-1336).PromptSAM::build(283) — tests can callbuild_capped(prompt, CAP)with the131,072constant, which is the production path.push_slice(1023) — tests can looppush_token, which is what production does.- The accessor block, except whatever one assertion needs to bound automaton size; if the size bound matters, keep
state_count/transition_countas#[cfg(test)].
Net: ~150 lines of code, ~6 tests that only exercise the removed surface, and a materially smaller public API for a module that is pub.
Nits
3. The draft_source wire 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:225-233— the same ladder withPyValueError::new_err("unsupported graph draft_source"), plus an absent-key default toMtpwhenkind == Speculativethat the others do not have.helios/src/runtime_core/selection.rs:144-148— the same1/2mapping for thespeculative_proposal_sourceconfig string ("mtp" => 1, "copy" => 2) producing a rawu64that is then compared againstgraph.draft_sourceat 149, 169, 197.- (
helios/src/execution/manifest.rs:845-846compares againstProposalSource::Copyfor validation and does not re-implement the ladder.)
Three error messages, three chances to drift when a third source is added. ProposalSource already owns a parser (helios/src/scheduler/speculation.rs:30-38, parse(&str)), so the pattern exists.
Fix: add ProposalSource::from_wire(u32) -> Result<Option<Self>> (and a to_wire/as u32 if selection.rs needs the number) next to parse; call it from serving.rs and python.rs, with python.rs alone handling the absent-key default. Have selection.rs parse the config string into the enum first and compare enums rather than u64/u32 (the source: u64 binding at 144 is why the comparison at 149/169/197 is numeric). One conversion, one error message, one default rule.
4. request_copy_match_stats duplicates request_history_proposal_with_match_len
Files: helios/src/scheduler.rs:1163-1205 (request_copy_match_stats, pub(crate)) vs helios/src/scheduler.rs:1112-1159 (request_history_proposal_with_match_len).
Both: clamp maximum with the identical three-way .min(...) chain (1117-1119 vs 1168-1170); return zeros when maximum == 0 || decoded_history.is_none() (1120-1122 vs 1171-1173); fetch the request; truncate the SAM proposal at the first out-of-vocabulary token (1130-1137 vs 1180-1185); query lookup_with_match_len; and arbitrate "shared ring wins only when shared_match > sam.match_len" (1145 vs 1197). The only difference is that one builds a padded Vec<i64> and the other returns (count, match_len).
Callers: request_copy_match_stats from helios/src/scheduler/rounds.rs:775; request_history_proposal_with_match_len from packing.rs:402 and server/runtime.rs:2146 (via request_history_proposal at 1102-1109).
Why it matters: the PR description states the arbitration rule as an invariant ("preferring per-request SAM on equal or longer match length"), and it now lives in two places with no test asserting the two agree. The packing path and the scheduling path can silently disagree about which source won, which would show up as a wide-copy shape being selected on stats that the uploaded tokens do not satisfy.
Fix: keep request_copy_match_stats as the primitive — it returns (count, match_len) and the winning tokens — and implement request_history_proposal_with_match_len on top of it, padding the returned tokens (the tokens are already materialised inside it, and propose is O(1) amortized). One copy of the clamp, the OOV truncation and the tie-break.
Open questions / could not confirm
- Is
propose_conditional_continuationsthe front half of an unmerged PR? Its doc names "2-deep pipelined execution" as the intended consumer; the description does not. If a follow-up exists, naming it in the description converts finding 2 from "delete" to "land with its consumer". Otherwise delete it. Nothing in this tree settles it. - Does anything intend to read SAM
memory_bytes? No scheduler metric, dashboard field or server endpoint references it (searched the tree; only sam.rs:902/983 and the benchmark at 1597-1600). If per-request SAM memory accounting is planned for the dashboard, it belongs with that change, not here.helios/src/server/dashboard/scheduler.rs(not opened) has no SAM row today. - Would the shrunken oracle test still cover the kept code? The 120 randomized brute-force trials at sam.rs:1463/1505 exercise
propose_for_context/propose_conditional_continuationsspecifically. Deleting those two functions removes most of the oracle's coverage of the underlyingwalk_context/resolve_matchmachinery. Before deleting, the oracle should be re-pointed atproposeso the surviving matching path keeps brute-force coverage — a test-only change, but it is the one cost of finding 2 and worth calling out in the PR rather than discovering after the delete.
What I did not find
No blocking simplicity problems: the padding-dominance rewrite (helios/src/scheduler/policy.rs), the copy-only graph gating in model/catalog.rs:89-111 and runtime_core/selection.rs:184, the draft_source enforcement in execution/manifest.rs:840-851, and the new cost arithmetic in scheduler/cost.rs:195-239 all have live callers on the scheduling path, and I found no parallel path left in place "for compatibility" that the PR description does not justify. No over-commented blocks beyond the idle doc in finding 1. No behaviourless tests beyond the idle calls listed in finding 1.