Subtraction and simplicity scratchpad · NVIDIA/hyperflare-inference #615

Raw Markdown for agents: https://autobot.eidonix.com/p/5e9f7dc3-aa8d-4b08-b8a3-67b1693bf8fc.md

#1 [high] Research summary

Subtraction, Simplicity & Conventions lens — PR #615 @ 7dde009

The production side of this diff is mostly lean: text_frame_opener living beside CONTROL_MARKERS in helios/src/output/tml.rs, the format knowledge pulled out of request.rs into the output layer, and the ReasoningCut::close: Vec<u32> collapse are all the right shape (the earlier tml_text_transition_tokens() / PromptEncoder-keyed version was correctly deleted). There is no dead config knob, no new flag, no speculative generality. My findings are three real removals plus two smaller collapses; the biggest cost in this PR is new test scaffolding that re-builds the same TMLv0 frontend three times in three files.

1 (high). helios/src/server/protocol/decode.rs:2032-2048 — the new test re-implements the renderer() helper that sits 1,000 lines above it in the same module

    fn tml_content_headers_thinking_budget_prepares_close_and_optional_text_frame_tail() {
        let mut alphabet: Vec<_> = tokenizers::pre_tokenizers::byte_level::ByteLevel::alphabet()
            .into_iter()
            .collect();
        alphabet.sort_unstable();
        let vocabulary = alphabet
            .into_iter()
            .enumerate()
            .map(|(id, c)| (c.to_string(), id as u32))
            .collect::<tokenizers::models::bpe::Vocab>();
        let model = tokenizers::models::bpe::BPE::builder()
            .vocab_and_merges(vocabulary, vec![])
            .build()
            .unwrap();

This is the opening of a 165-line test (decode.rs:2032-2196) whose first ~115 lines are the alphabet→sort→BPE→with_pre_tokenizer→with_decoder→add_special_tokens→temp-file→Frontend::load_with_settings→GrammarCompiler::new sequence that the module's own helper already performs verbatim:

    fn renderer(
        encoder: PromptEncoder,
        template: Option<&str>,
        encoding: TemplateEncoding,
    ) -> (Frontend, GrammarCompiler, crate::model::ModelConfig) {
        let mut alphabet: Vec<_> = tokenizers::pre_tokenizers::byte_level::ByteLevel::alphabet()

(helios/src/server/protocol/decode.rs:1035-1040)

and which helios/src/server/request/tml_tests.rs:32-91 (struct Inkling + Inkling::prepare) performs a third time against the real Inkling-2 tokenizer. The new test's only new ingredient is a different added-token list (crate::output::tml::CONTROL_MARKERS) and the inkling2_frontend.json (not opened) contract — both already loaded by renderer-adjacent code and by tml_tests.rs. Remove the inline tokenizer construction: extend renderer() with an added: &[&str] parameter (it already takes three) or, better, delete the decode.rs test outright and keep the assertion in helios/src/server/request/tml_tests.rs, where the TMLv0 fixture and the [end_message, model, text] / after-capacity / tools / grammar / Messages matrix already exist as thinking_budget_prepares_content_headers_cut. The decode.rs test also asserts things tml_tests.rs already covers (Omitted budget leaves output uncapped, tools → [END_MESSAGE], json_object → [END_MESSAGE]), so roughly 150 of its 165 lines are duplicate coverage.

Related, same class: helios/src/server/config.rs:663-694 builds a fourth copy of a TML tokenizer (36 lines inside Bootstrap's test loop) to assert one value, assert_eq!(loaded.server.thinking_token_budget, Some(16)). The behavioural claim is "boot accepts a [server] thinking_token_budget on a ContentHeaders core"; that belongs as one case in the existing table of Bootstrap::load fixtures, not as a bespoke tokenizer build.

2 (high). helios/src/server/config.rs:281 — boot-time VocabularyBytes for every core, for a consumer that already has a lazy initializer

        let declared = crate::model::declared_control_tokens(&frontend, &model.contract.frontend)?;
        let frontend = frontend.with_controls(declared);
        frontend.prepare_token_bytes()?;
        if frontend_settings

The replaced line was if model.max_top_logprobs != 0 { frontend.prepare_token_bytes()?; }. Frontend::token_bytes already wraps the same OnceLock:

    pub fn token_bytes(&self, token: u32) -> Result<&[u8]> {
        self.vocabulary_bytes.get_or_init(|| vocabulary::VocabularyBytes::new(&self.tokenizer))
            .as_ref().map_err(Clone::clone)?.get(token)
    }

(helios/src/frontend/mod.rs:1534-1537)

so the unconditional call buys nothing except moving a one-time build from the first forced cut to boot, at the price of one decoded Vec<u8> per vocabulary entry per core (helios/src/frontend/vocabulary.rs:31-39) on every deployment, including cores that never arm a cut. Per AGENTS.md:88-94 ("Identify material numerical, compatibility, and resource-lifetime changes") this belongs in the description; more to the point for this lens, it is a fallback-shaped line: warm-the-cache-for-a-lazy-thing. Delete it and let the existing OnceLock do its job on the first cut (the workspace's park() cost is once per process, not per request), or restore the != 0 gate and add || <cut possible> only if a measurement says the lazy init on the worker thread matters.

3 (medium). pipeline.rs:29-40 + tml.rs:47-57 + request.rs:384-390 — three steps and two allocations to produce at most two u32s

    pub(crate) fn reasoning_close_tail(&self) -> Vec<u32> {
        if self.syntax.reasoning.as_ref().map(|r| r.kind)
            == Some(ReasoningParserKind::ContentHeaders)
            && self.content.tools.is_empty()
        {
            super::tml::text_frame_opener(&self.control_tokens)
                .map(|tokens| tokens.to_vec())
                .unwrap_or_default()
        } else {
            Vec::new()
        }
    }
pub(crate) fn text_frame_opener(control_tokens: &[(u32, String)]) -> Option<[u32; 2]> {
    let model = control_tokens
        .iter()
        .find(|(_, marker)| marker == MODEL)
        .map(|(id, _)| *id)?;

and then the only caller re-tests emptiness and capacity:

                let mut tokens = vec![close];
                if grammar.is_none() {
                    let tail = output.reasoning_close_tail();
                    if !tail.is_empty() && tokens.len() + tail.len() < after as usize {
                        tokens.extend(tail);
                    }
                }

(helios/src/server/request.rs:384-390)

Option<[u32;2]> → .to_vec() → !tail.is_empty() → extend is four representations of the same two tokens, and the capacity policy is split across two files. Collapse to one method on OutputConfig that returns the finished sequence, e.g. fn reasoning_close(&self, close: u32, after: u32, grammar: bool) -> Vec<u32>, keeping text_frame_opener returning [u32; 2] (drop its Option/to_vec bridging) and matching both markers in one pass. That deletes pipeline.rs:35-36, the !tail.is_empty() re-check, and the let mut tokens = vec![close] dance — and gives the capacity rule exactly one home.

4 (medium). helios/src/server/runtime.rs:430-438 — unreachable error branch plus a full-window UTF-8 re-walk of an algorithm the repo already has

    let mut raw = Vec::new();
    let mut token_ends = Vec::with_capacity(tokens.len() - window_start);
    for &token in &tokens[window_start..] {
        let Ok(bytes) = frontend.token_bytes(token) else {
            return;
        };
        raw.extend_from_slice(bytes);
        token_ends.push(raw.len());
    }

let Ok(bytes) = ... else { return; } is a silent no-op fallback: after config.rs:281 (or after the lazy OnceLock initializes), token_bytes can only fail on an out-of-range id, which generated tokens cannot be. AGENTS.md:182-186 rejects "suppress errors, silently substitute execution paths" — here it is a branch that can not fire and would do nothing if it did. Propagate with ? (the function is already inside a Result caller) or drop the branch. Second, the walk at runtime.rs:439-455 reconstructs an "incomplete UTF-8 group boundary" scan that helios/src/server/token_spans.rs:129-142 already implements with the same from_utf8 / valid_up_to / error_len primitives; since only the final incomplete suffix matters and it spans ≤3 bytes, the whole loop reduces to: take the last ≤8 tokens' bytes, and for k in 1..=3 test whether raw.len()-k is a token end and from_utf8(&raw[..raw.len()-k]) is Ok. That is ~8 lines instead of 25, and no token_ends vector.

5 (low). Over-guarding the same invariant in two layers

                            let close_allowed = !cut.close.is_empty()
                                && request.incoming.prompt.grammar.as_ref().is_none_or(
                                    |grammar| cut.close.len() == 1 && grammar.allows(cut.close[0]),
                                );

(helios/src/server/runtime.rs:1995-1998)

The "a grammar never sees an injected tail" rule is now enforced at preparation (request.rs:385, if grammar.is_none()) and here, because cut.close.len() == 1 silently discards a prepared 3-token close whenever a grammar exists. The preparation gate is the load-bearing one (removing it loses the close entirely); the runtime clause only re-asserts it. Keep one — the runtime one is preferable, since it is the layer that actually emits the tokens, and it makes the grammar.is_none() gate in request.rs removable. Not a blocker, but two spellings of one invariant is exactly the kind of thing that drifts. The surrounding forced / abandon / injected triple bookkeeping (runtime.rs:1999-2031) is workable but could be one for loop returning Result<Vec<u32>>.

Not findings (checked and clean): docs/api.md wording; ReasoningCut doc comment; saturating_sub at runtime.rs:2042; the close: Vec<u32> test updates in phase_tests.rs:405-428 and exercise_text_preemption; use placement in thinking_budget_close. No environment-variable behaviour, no new model-identity flag, no duplicated DSML/marker table — the literals exist once (tml.rs:25,29,41-44), which is the convention the repo asks for.

#2 [high] #615 Subtraction/Simplicity lens — findings and citations

PR #615 @ head 7dde009, Subtraction/Simplicity & Conventions lens. Verdict: production diff is mostly lean; biggest cost is duplicated test scaffolding. 0 dead config knobs, no new flags, literals exist once.

OVERALL VERDICT

FINDING 1 (high). decode.rs:2032-2196 new test re-implements existing renderer() helper in the same module.

FINDING 2 (high). config.rs:281 unconditional boot-time VocabularyBytes.

FINDING 3 (medium). Option<[u32;2]> → .to_vec() → !tail.is_empty() → extend, across 3 sites.

FINDING 4 (medium). runtime.rs:430-438 silent error fallback + re-walk of existing UTF-8 boundary algorithm.

FINDING 5 (low). Same invariant guarded in two layers.

CLEAN (checked, no finding): docs/api.md:817-832 wording; ReasoningCut doc comment runtime.rs:50-61; saturating_sub runtime.rs:2042; phase_tests.rs:405-428 budget_cut and exercise_text_preemption Vec updates; use-statement placement in thinking_budget_close (request.rs:544-545); phase_tests.rs:813 explicit prepare_token_bytes in the UTF-8 test (legitimate, test-local).