Subtraction, Simplicity & Conventions review — PR #697
Scope read at head bfae28a: full diff of helios/src/scheduler/checkpoints.rs, helios/src/scheduler.rs, helios/src/server/request.rs, helios/src/server/runtime.rs, helios/src/server/runtime/phase_tests.rs, the four docs; surrounding code request_anchor_endpoint (:473–554), checkpoint_selection_uncached (:561–794), promote_request_anchor (:898–928), existing test helpers (:1151 measure, :1167 linear_costs, :1276 walk_scheduler, :861 prepared_budget_request), AGENTS.md, docs/design-review.md, read_charter.
Key findings
The production diff is genuinely lean: net +29 lines across 4 Rust files, and it reuses the existing anchor-pricing machinery rather than adding a parallel path. Five subtractions exist; two are worth doing before merge.
- F1 (high) — the new preserved branch duplicates the pre-existing
elsearm verbatim.checkpoints.rs:620–624and:662–665both executeaccounting.budgeted_anchor = None; (raw_anchor, 0). Folding the condition into oneifdeletes the branch, one of three call sites of the new predicate, and a duplicatedbudgeted_anchor = Noneimmediately above the TLA+ mutation needle. - F2 (high) — the test helper added at
phase_tests.rs:8358–8377is an 18-line verbatim copy of the front half of the existingprepared_budget_request(:861–888). Extract oneprepare()and call it from both. - F3 (medium) —
budget_interior_anchoris a double-negative re-read: the call site reads|| !self.budget_interior_anchor(request), and the predicate re-readsself.policy.checkpoint_extra_work_fractionalthoughcheckpoint_selection_uncachedalready bindsfractionat:609and re-testsfraction == 0.0at:675. - F4 (low) — the same
OutputStart::Reasoningtest is written twice 13 lines apart inrequest.rs(:413–414 and :427–429). - F5 (low) — the 10-line scheduler-cost setup is repeated three times in the two new tests (
checkpoints.rs:4791–4802,:4843–4854,:4869–4880).
Convention flag (not a deletion): preserve_message_anchor is structurally a default-false boolean opt-in threaded Prompt → RequestSpec → LiveRequest, which docs/design-review.md:58–61 names as rejectable and AGENTS.md:180–181 forbids as a bypass — but it is model-independent, and I verified the scheduler has no existing channel that already carries it, so the field itself should stay; the description owes the argument for it.
F1 (high) — delete the duplicate fallback arm in checkpoint_selection_uncached
helios/src/scheduler/checkpoints.rs:620–624 (new):
let (anchor, anchor_split_ns) = if raw_anchor < request.prompt_tokens {
if !self.budget_interior_anchor(request) {
accounting.budgeted_anchor = None;
(raw_anchor, 0)
} else if raw_anchor > start {
helios/src/scheduler/checkpoints.rs:662–665 (pre-existing):
} else {
accounting.budgeted_anchor = None;
(raw_anchor, 0)
};
Both arms produce exactly (budgeted_anchor = None, raw_anchor, 0) and then fall through to the same if anchor > start { cuts.push(Anchor) } at :666–674. I enumerated all four reachable cases — raw_anchor >= prompt_tokens (else arm), raw_anchor < prompt_tokens && raw_anchor <= start && budgeted (else arm), raw_anchor < prompt_tokens && !budget_interior_anchor (new arm), raw_anchor < prompt_tokens && budgeted && raw_anchor > start (priced arm) — so the fold is behaviour-preserving on every path, not only the tested one.
Concrete replacement (deletes 4 lines, the :622 assignment, and one of the three budget_interior_anchor call sites):
let (anchor, anchor_split_ns) = if raw_anchor < request.prompt_tokens
&& self.budget_interior_anchor(request)
{
if raw_anchor > start {
with the trailing } else { accounting.budgeted_anchor = None; (raw_anchor, 0) }; unchanged. The doc comment at :610–619 should be rewritten to match, since it currently describes the preserved case as a separate branch ("retain raw_anchor without charging its split") rather than as the fallback it is. Side benefit: the second budgeted_anchor = None at :622 sits immediately above the TLA+ mutation needle (the full Some(...) line, now :649), and removing it keeps that guard region unambiguous.
Merge-order note: #655 rewrites the snapshot-cost gate at :681 (fresh_duration → measured_duration) in this same function. Folding this branch first makes #655's rebase trivial; landing #655 first makes the fold a conflict in the same hunk either way.
F2 (high) — share the prepare_inference boilerplate with prepared_budget_request
New closure, helios/src/server/runtime/phase_tests.rs:8358–8377:
let prepare = |fixture: &Fixture, protocol: Protocol, body: serde_json::Value| {
let decoded = decode(protocol, body, false).unwrap();
let compiler = crate::grammar::GrammarCompiler::new(
fixture.frontend.tokenizer(),
fixture.config.contract.vocabulary,
&fixture.config.eos_token_ids,
&[],
)
.unwrap();
crate::server::request::prepare_inference(
&fixture.frontend,
None,
&compiler,
&fixture.config,
&decoded.request,
0,
false,
)
.unwrap()
};
Existing helper, helios/src/server/runtime/phase_tests.rs:871–888:
let decoded = crate::server::protocol::decode(protocol, body, false).unwrap();
let compiler = crate::grammar::GrammarCompiler::new(
fixture.frontend.tokenizer(),
fixture.config.contract.vocabulary,
&fixture.config.eos_token_ids,
&[],
)
.unwrap();
let prepared = crate::server::request::prepare_inference(
&fixture.frontend,
None,
&compiler,
&fixture.config,
&decoded.request,
0,
false,
)
.unwrap();
These are the same 18 lines modulo what they return (PreparedInference vs the 4-tuple). Concrete replacement: add a module-level
fn prepare(fixture: &Fixture, protocol: Protocol, body: serde_json::Value) -> PreparedInference
containing the block above, delete the closure at :8358–8377 (call prepare(...) instead), and have prepared_budget_request (:861) start with let prepared = prepare(fixture, protocol, body); before its existing prompt_tokens / Decoder::new / incoming tail at :889–897. Net ~−18 lines and one fewer copy of the prepare_inference argument list that will otherwise drift again — this is the fourth distinct prepare_inference call site in the crate.
F3 (medium) — make the predicate positive and stop re-reading fraction
helios/src/scheduler/checkpoints.rs:469–471:
fn budget_interior_anchor(&self, request: &LiveRequest) -> bool {
self.policy.checkpoint_extra_work_fraction == 0.0 || !request.preserve_message_anchor
}
Call site, helios/src/scheduler/checkpoints.rs:478–483:
if raw_anchor >= request.prompt_tokens
|| request.prefix_tokens == raw_anchor as u64
|| !self.budget_interior_anchor(request)
{
return Some(raw_anchor);
}
Three problems, all removable without changing behaviour: (a) !self.budget_interior_anchor(...) is a triple negative — of the two new call sites, one reads !budget_interior_anchor (:480) and the other reads budget_interior_anchor (:621), so the name is used both ways; (b) the fraction == 0.0 disjunct re-reads self.policy although checkpoint_selection_uncached already binds let fraction = self.policy.checkpoint_extra_work_fraction; at :609 and tests if fraction == 0.0 { at :675; (c) the self-method form forces promote_request_anchor (:908) to reach through self as well.
Concrete replacement — a positive, fraction-taking associated fn:
fn preserved_interior_anchor(fraction: f64, request: &LiveRequest) -> bool {
fraction > 0.0 && request.preserve_message_anchor
}
then :480 becomes || Self::preserved_interior_anchor(self.policy.checkpoint_extra_work_fraction, request), :621 becomes if Self::preserved_interior_anchor(fraction, request), and :908 becomes let latch = (!Self::preserved_interior_anchor(self.policy.checkpoint_extra_work_fraction, request) && ...). (Or, if F1 is taken, :621 disappears entirely and there are only two call sites.) The predicate is the one new abstraction this PR adds; making it read in the same direction at every site is worth the small edit.
F4 (low) — hoist the repeated OutputStart::Reasoning test
helios/src/server/request.rs:413–414 (inside the grammar_reasoning filter):
.filter(|out| {
out.content.start == crate::output::tagged::OutputStart::Reasoning
|| envelope.as_ref().is_some_and(|env| {
helios/src/server/request.rs:427–429 (new):
let preserve_message_anchor = output
.as_ref()
.is_some_and(|o| o.content.start == crate::output::tagged::OutputStart::Reasoning);
Same expression twice, 13 lines apart, both before output is moved into PreparedInference at :454. Replace with one local computed above :408:
let opens_reasoning = output
.as_ref()
.is_some_and(|o| o.content.start == crate::output::tagged::OutputStart::Reasoning);
then :414 becomes opens_reasoning in the filter and let preserve_message_anchor = opens_reasoning; (or assign the field directly from opens_reasoning at :452, dropping the intermediate binding). Small, but it is the only place the PR re-states a frontend condition, and the name carries the why better than preserve_message_anchor.
F5 (low) — one local builder for the three repeats of the snapshot-cost fixture
helios/src/scheduler/checkpoints.rs:4791–4802 (repeated verbatim at :4843–4854 and :4869–4880, differing only in the fraction and whether the scheduler is fresh):
let mut scheduler = super::super::tests::scheduler(2, 128, 16);
scheduler.prefill_graphs(&[128, 256, 512]).unwrap();
for (tokens, nanos) in [(128, 100), (256, 110), (512, 200)] {
measure(&mut scheduler, GraphKind::Prefill, tokens, nanos);
}
measure(&mut scheduler, GraphKind::Snapshot, 1, 5);
scheduler
.configure_policy(PolicyConfig {
checkpoint_extra_work_fraction: 0.05,
..Default::default()
})
.unwrap();
No existing helper does this (measure :1151, linear_costs :1167, walk_scheduler :1276 all take a scheduler they do not build). Add one local in the test module:
fn budgeted(fraction: f64) -> super::super::RequestScheduler {
let mut scheduler = super::super::tests::scheduler(2, 128, 16);
scheduler.prefill_graphs(&[128, 256, 512]).unwrap();
for (tokens, nanos) in [(128, 100), (256, 110), (512, 200)] {
measure(&mut scheduler, GraphKind::Prefill, tokens, nanos);
}
measure(&mut scheduler, GraphKind::Snapshot, 1, 5);
scheduler
.configure_policy(PolicyConfig {
checkpoint_extra_work_fraction: fraction,
..Default::default()
})
.unwrap();
scheduler
}
and the three sites become let mut scheduler = budgeted(0.05); / let mut zero_scheduler = budgeted(0.0); / let mut scheduler = budgeted(0.05); — ~20 lines removed and the round numbers (128/256/512, the 400 ns whole / 110 ns split arithmetic documented at :4804–4806) get a single home that the next anchor test can reuse.
Convention note (keep the field, require the argument)
helios/src/scheduler.rs:158–160:
/// Retain the last eligible interior message boundary as the conversation anchor
/// under nonzero `checkpoint_extra_work_fraction` instead of budgeting its split.
pub preserve_message_anchor: bool,
mirrored at helios/src/server/runtime.rs:50–52 and helios/src/scheduler.rs:231. This is structurally a default-false boolean opt-in plumbed Prompt → RequestSpec → LiveRequest — the shape docs/design-review.md:58–61 says to reject ("Reject per-model boolean policy flags, including supports_*, can_*, and default-false opt-ins") and AGENTS.md:180–181 forbids as a bypass ("Flags, enums, callbacks, optional paths, and temporary implementations cannot be used to bypass them"). I checked the two obvious carriers and neither works, so I do not recommend deleting the field:
Prompt.reasoning_cut(runtime.rs:39) isSomeonly whenopts.thinking_budgetis set (request.rs:368), so it is unrelated to how the template opens.Prompt.grammar_reasoning(runtime.rs:43–44) isSomeonly whengrammar.is_some()(request.rs:408–410), so it is absent for ordinary reasoning-enabled chat — precisely the workload this PR targets.
So the field is not derivable from what the scheduler already receives, and the meaning is model-independent (no model-name branch, single shared OutputStart parser state) — it satisfies the charter's model-agnostic rule. What is missing is only the argument: the description never says why the scheduler must be told this rather than derive it, and a reviewer applying the letter of design-review.md will ask. Recommend the author add two sentences to ## What covering (a) why the value cannot be computed scheduler-side and (b) that it is frontend-derived metadata, not a per-model policy flag — the same way grammar_constrained is justified.
Related cost the description does not count: because RequestSpec is built with struct literals throughout the crate, this one field forced ~40 mechanical preserve_message_anchor: false edits — helios/src/scheduler/policy_tests.rs (not opened) alone carries 25 (:147, 1218, 1805, 2437, 3192, 3287, 3549, 4853, 5023, 5169, 6187, 6215, 6305, 7299, 7377, 7423, 7606, 7639, 7714, 9177, 9293, 9396, 9445), plus helios/src/model/tests.rs (not opened) (12), helios/src/server/runtime.rs (4 non-test literal sites), phase_tests.rs (7). That churn is the price of the opt-in shape and is worth naming in the description, since it is what a reviewer will see in git diff --stat.
What is already lean (no action)
- No duplicated pricing logic. The preserved path reuses the existing early
Some(raw_anchor)return atcheckpoints.rs:478–483rather than adding a second estimate;anchor_split_ns(:625),anchor_split_affordable(:635) andallowance(:686) are untouched and uncopied. promote_request_anchorgains only a disjunct (checkpoints.rs:908), not a parallel branch — the latch shape from #582 is preserved.- The docs changes are synchronization, not duplication:
docs/cli-design.md,docs/core-design.md,docs/scheduling-runtime-design.md,helios/README.md(not opened) each restate the same rule in their own register, which is the repo's documented convention for present-state docs; there is nothing to collapse. - No dead code left behind: every new production line is reachable from
request_anchor_endpoint/checkpoint_selection_uncached/promote_request_anchor, and thefraction == 0.0guard at:675still governs the optional-candidate loop for preserved requests.
Open questions / not found
- #655 merge order is unresolved and determines how expensive F1 is: #655 rewrites the snapshot-cost gate at
checkpoints.rs:681in the same function #697 branches into. Landing #697 first makes the fold trivial; landing #655 first turns the fold into a conflict in the same hunk. OutputStart::ToolBodyhas no test although the description lists it among the non-preserved starts (phase tests coverReasoning,Content×2,RecipientHeader,RecipientFrame×2,Completions). Not a subtraction issue, but it means one documented claim rests only on theis_some_and(|o| o.content.start == Reasoning)shape atrequest.rs:427–429.- No reproducer available for the two performance tables, so I could not check whether the preserved path's extra charged prompt-end
Endpointcopy (visible asckpt_caps end60→96 / 64→96 / 61→96 in the PR's own table) is buying enough to justify the snapshot capacity — that is a budget question this lens cannot settle from the repo.