Code correctness report · NVIDIA/hyperflare-inference #708

Raw Markdown for agents: https://autobot.eidonix.com/p/a7757b56-fcc4-4ee5-b2cd-bd46d46f08c3.md

Deep Code Correctness, Invariants & Hot-Path Performance Audit — PR #708 @ 4fee325

Scope & method

This PR is 7 files / ~736 changed lines, but the authored surface (excluding the unrelated doc/AGENTS.md (not opened)/TODO.txt/orbit changes I found in the diff) is a single-subsystem pair: helios (model + server runtime) and ignition. That is ≤ 900 LOC across 2 crates, so per the partitioning rule I audited directly rather than spawning sub-agents.

Every non-trivial changed site was traced with all four protocol steps:

Site Callees/enums opened Result
validate_continuation_prompt_data (model.rs:414-493) PromptData (model.rs:280-292), ImageTokenLayout/ImageSpan (contract.rs:390,420), PreparedContract::validate (contract.rs:542-594), validate_completion (model.rs:374-404), Admission::validate_continuation (admission.rs:76-111) one latent finding below
Admission::validate/validate_continuation/from_continuation (admission.rs:71-163) Error/AdmissionError (error.rs:145-183), validate_prompt (admission.rs:167-225), prompt_metadata::extend_text (admission.rs:25-56) sound
Worker::admit initial-prompt derivation + 3 error-isolation sites (runtime.rs:1629-1717) Carried (runtime.rs:424-434), park_with_tokens (runtime.rs:2496-2559), requeue (runtime.rs:2988-3016), clear_active_entry (runtime.rs:3274-3290), RequestScheduler::cancel/retire (scheduler.rs:3146,3183), TokenStops::new/TextStops::new (stops.rs:14-31,156-166), Incoming::fail/notify_admission (runtime.rs:335-363), http.rs:576 sound
VisionState.validate_prefill / .inject (vision_state.py:38-61) PrefillVisionInputs (vision_state.py:11-22), image_capacity (components/capacity.py (not opened)), torch broadcasting semantics sound
helios/src/model/tests.rs:2459-2581, phase_tests.rs:8685-9385 fixtures enable_vlm_image_tokens, budget_cut, speculative_burst_frame, budget_pass tests are consistent with the code

Finding 1 — Minor (latent): continuation suffix bound uses the wrong vocabulary tier, so forced control tokens can become a hard readmission failure

Diff site — helios/src/model.rs:446-448 (new code):

        || tokens[initial_prompt_tokens..]
            .iter()
            .any(|token| *token as usize >= config.contract.vocabulary)
    {
        return Err("prompt arrays violate prepared geometry".into());

Contradicting callee — helios/src/model/admission.rs:92-95 (unchanged, runs on every admission before the above):

            || self
                .prompt
                .iter()
                .any(|token| *token as usize >= config.contract.input_vocabulary)

And helios/src/model/contract.rs:546-548:

        if self.vocabulary == 0
            || self.input_vocabulary < self.vocabulary
            || self.input_vocabulary > u32::MAX as usize

input_vocabulary is an input-only tier (input embeddings wider than the sampling head) and the contract explicitly allows input_vocabulary > vocabulary. The contract itself validates every image/span token id against the input tier, not the sampling tier (contract.rs:579-591):

        if self.vision.enabled() != self.frontend.image_tokens.is_some()
            || self.frontend.image_tokens.as_ref().is_some_and(|layout| {
                layout.feature_token as usize >= self.input_vocabulary
                    || layout.span.as_ref().is_some_and(|span| {
                        span.max_tokens == 0
                            || span.start_token == span.end_token
                            || [span.start_token, span.end_token]
                                .iter()
                                .chain(&span.interior_tokens)
                                .chain(&span.unscoped_tokens)
                                .any(|id| *id as usize >= self.input_vocabulary)

Counterexample. Core with vocabulary = 100_000, input_vocabulary = 100_512 (control-reasoning tier), qwen-style reasoning.close = 100_200. Request with thinking_budget runs the forced-close path in runtime.rs:2298-2299:

                            if forced {
                                for token in cut.close {
                                    match request.close_reasoning(token, &self.config.eos_token_ids)

…which is then parked with those tokens appended (runtime.rs:2348-2349):

                                let appended: &[u32] = if forced { &injected } else { &[] };
                                self.park(slot, appended, remaining)?;

park_with_tokens calls extend_text(...) and reassigns incoming.prompt.tokens (runtime.rs:2525-2527), so the forced tokens now live at indices >= carried.prompt_tokens, i.e. squarely in tokens[initial_prompt_tokens..]. On readmission Worker::admit runs Admission::from_continuation → validate_continuation → the new suffix check, and 100_200 >= 100_000 is true → Err("prompt arrays violate prepared geometry"). The request dies (cleanly, per the new isolation path) instead of continuing its budget pass. The same holds for a decoded control token in [vocabulary, input_vocabulary).

Note this is a behavior change vs. the old code only in where it fails: previously validate_prompt_data had no vocabulary bound on the tail at all (config.contract.vision.enabled() || *i as usize >= tokens.len() was the only index bound), so a [vocabulary, input_vocabulary) control token in a parked continuation was accepted. The PR's own rationale for the check ("blocking out-of-vocabulary sentinels") does not require the sampling tier — the input tier is the tier that actually holds such tokens.

Why not Major: no in-repo core can trigger it. ignition/preparation/contract.py:159 (not opened) defaults the tier to the sampling vocabulary —

    result = dict(version=3, vocabulary=vocabulary, input_vocabulary=input_vocabulary or vocabulary,

— and no recipe in the tree passes input_vocabulary= (grep of ignition/ and flare-cli/src/ finds only that defaulting line). Every shipped core therefore has the two tiers equal and the finding is unreachable today. It is a latent trap for the first core that uses the documented wide-input tier.

Fix (one line, helios/src/model.rs:448):

        || tokens[initial_prompt_tokens..]
            .iter()
            .any(|token| *token as usize >= config.contract.input_vocabulary)

matching admission.rs:95 and contract.rs:581,589. (If the intent genuinely is "decode can never emit above the sampling head", then the forced-token producer at runtime.rs:2349 must be exempted instead — but the input_vocabulary bound is the consistent choice, since admission.rs:92-95 already proves that tier is legal in prompt.tokens.)


Everything else I traced and cleared (with the reasoning, so the claim is checkable)

1. Strict initial-prompt validation is genuinely preserved. validate_prompt_data now delegates with initial_prompt_tokens = tokens.len() (model.rs:406-408), so every old strict check keeps its exact old domain: the bijection (*token == layout.feature_token) == (*index >= 0) degenerates to the position < initial_prompt_tokens arm (model.rs:459-460), the span-membership scan covers tokens[..initial_prompt_tokens] == all tokens (model.rs:473), the span-end bound s.end > initial_prompt_tokens is the old s.end > tokens.len() (model.rs:443), and the new suffix checks are vacuous over an empty range. prompt.validate (admission.rs:218) and model/prompt.rs:138 still call the strict wrapper, so a user prompt cannot smuggle an unindexed feature_token or a loose span token.

2. No panic path in the new slicing. tokens[initial_prompt_tokens..] (model.rs:446) and tokens[..initial_prompt_tokens] (model.rs:473) are the first-and-second || chains evaluated after initial_prompt_tokens > tokens.len() has already returned Err (model.rs:421-422), so initial_prompt_tokens <= tokens.len() holds at both sites. Admission::from_continuation (admission.rs:161) and Worker::admit (runtime.rs:1629-1648) both surface the Err rather than unwrapping.

3. carried.prompt_tokens cannot drift across repeated parks (the subtle one). park_with_tokens sets prompt_tokens: Some(active.carried.prompt_tokens.unwrap_or(prompt_tokens)) (runtime.rs:2550), so a second park re-carries the original boundary instead of live.prompt_tokens (which now equals original + previously generated). requeue (runtime.rs:3011) passes carried: active.carried unchanged. The test at phase_tests.rs:9181-9187 exercises exactly this. So Worker::admit's parked.as_ref().and_then(|p| p.carried.prompt_tokens).unwrap_or(incoming.prompt.tokens.len()) (runtime.rs:1629-1632) yields the original user prompt length on every readmission, and a decoded feature_token at index >= initial_prompt_tokens can never be mistaken for a real image position.

4. Error isolation is state-complete. All three new Err arms (runtime.rs:1642-1647, 1657-1662, 1677-1682) do self.scheduler.cancel(handle)? → incoming.fail(error) → progress = true → continue, and none of them had already written self.admissions[slot] (the assignment was moved after all three constructions, runtime.rs:1717). cancel → retire releases pages/snapshots/image slot and marks the slot retiring (scheduler.rs:3130-3142); fail routes through finish_error which is idempotent on failure.is_some() (runtime.rs:351-356) and emits GenerationEvent::Error, which http.rs:576 maps to the response error. No slot leak, no double-fail, no admission-counter drift (metrics.admitted is only bumped at runtime.rs:1718-1720, after success). The parked binding is not moved before the failure arms, so the continue paths are borrow-clean.

5. VisionState.inject broadcast shapes are correct and cannot corrupt text rows. visual is built from 1-D tensors of length embedding.shape[0] (vision_state.py:55-60), then visual[:, None] broadcasts against an [N, hidden] embedding and self.arena[slot, indices] (slot clamped, indices clamped) is [N, hidden] because slot is a 1-element tensor after .clamp on a 1-element tensor. The clamp keeps the torch.where data operands in-bounds regardless of gate values, and the gate itself uses unclamped index/feature_slot, so the clamp cannot create a visual position — a stale nonnegative index with feature_slot == -1 yields visual == False and the original text embedding (asserted at test_vision_state.py:117-125). validate_prefill uses the identical unclamped predicate family (vision_state.py:43-48), so validate and inject agree bit-for-bit on which rows are visual — the property the PR needs to keep re-prefill safe. index < self.arena.shape[1] defends against a stale index past arena width, and image_token=None only removes a conjunct (vision_state.py:45), strictly loosening, never making a previously-valid state invalid.

6. Backward compatibility of the Python surface. image_token became image_token=None (vision_state.py:26) without moving it after the *, — it was already keyword-only (*, image_token, features, hidden), so all recipe call sites passing image_token= still bind. test_index_only_vision_state_without_image_token (test_vision_state.py:128-141) covers the omitted case.

7. No hot-path regression. All added work is O(len(tokens)) single-pass over slices already in cache (model.rs:446-448 suffix vocabulary scan, model.rs:473-484 span scan now over a prefix — strictly cheaper than before), and it runs once per admission, not per step/victim/iteration. VisionState gained two elementwise comparisons plus one if on a per-prefill-chunk tensor (vision_state.py:43-46), with no new allocation (visual is a bool tensor that replaces the two tokens == image_token temporaries the old code built, so the net allocation count is down).

8. Tests in the changed code are consistent and would catch the PR's claimed behavior. vlm_feature_token_survives_preemption_and_thinking_budget_readmission (phase_tests.rs:9035-9213) really does assert the packed -1s (:9131-9142), the preserved boundary after a second park (:9186), and the exact post-readmission token stream (:9212); vlm_feature_and_span_tokens_survive_grammar_transition_readmission (:9216-9281) asserts an in-vocab span-start token and feature_token survive a grammar-transition park with carried.prompt_tokens == Some(2); worker_admit_isolates_... (:9284-9385) asserts full slot/page reclamation for all three failure sites. continuation_prompt_validation_... (model/tests.rs:2459-2581) asserts the initial-vs-continuation boundary, the 0/7 invalid boundaries, the OOV suffix, and span-overrun rejection. I found no test that contradicts the code.


Verdict

No Blocker or Major correctness defect is present. The two headline invariants — strict multimodal validation on the user prompt prefix, and unindexed decoded image/span tokens treated as ordinary text on readmission — are correctly established, the same-loop state ordering in Worker::admit is right (admissions[slot] written only after all three fallible constructions succeed, before active[slot]), repeated parking preserves carried.prompt_tokens, and all three new failure paths fully reclaim scheduler slots and pages.

The one real defect is Minor and currently unreachable: model.rs:448 bounds continuation tokens by config.contract.vocabulary while every other input-side check in the same admission path (admission.rs:95) and in the contract's own image-token validation (contract.rs:581,589) uses the wider config.contract.input_vocabulary, which the contract explicitly permits to exceed the sampling vocabulary (contract.rs:547). Because forced reasoning-cut close tokens are appended into the continuation (runtime.rs:2349) and re-validated on readmission, a core that ever populates that documented wide-input tier would fail the affected readmission outright. One-line fix: use config.contract.input_vocabulary at model.rs:448.