Skip to content

fix(helios,ignition): handle decoded VLM feature tokens on continuation readmission and unify index-driven VisionState - #708

Merged
lukealonso merged 1 commit into
mainfrom
unify-vlm-index-driven-vision-state
Dec 3, 2026
Merged

lukealonso merged 1 commit into
mainfrom
unify-vlm-index-driven-vision-state

Conversation

@lukealonso

Copy link
Copy Markdown
Collaborator

Why

Vision-language models that place their image feature token inside the decoded vocabulary (Nemotron-H, GLM-5.3, Qwen3.8, Qwen3.8-Dense, Inkling2, Kimi3, MiMo-V2, MiniMax-M3, and Step5) can sample that token—or an in-vocabulary atomic image span delimiter—during ordinary text decode because Helios does not mask image feature tokens during decode. When a request later parks for KV cache preemption (Worker::park_if_preempted), thinking_token_budget enforcement (Worker::park), or a speculative-reasoning grammar transition (Worker::park_grammar_transition), Worker::park_with_tokens appends the generated continuation tokens to the prompt history and assigns vision_token_indices = -1 to every appended position.

On readmission, two failures occurred:

  1. Fatal worker crash in Helios (helios/src/server/runtime.rs, helios/src/model.rs): Worker::admit called Admission::from_prompt, whose validate_prompt_data enforced a strict bijection (*token == layout.feature_token) == (*index >= 0) and atomic ImageSpan membership across the entire tokens array. Any decoded in-vocabulary feature or span token caused validate_prompt_data to return Err, which propagated via ? out of Worker::run, marked worker_health unhealthy, failed every concurrent request on that worker, and permanently terminated the flare-model worker thread. Errors from TokenStops::new and TextStops::new in Worker::admit propagated out of Worker::run in the same way.
  2. Token-keyed embedding validation and injection in Ignition (ignition/components/vision_state.py): The shared VisionState used by 9 VLM recipes keyed both validate_prefill and inject on tokens == self.image_token rather than vision_token_indices >= 0 (unlike qwen38's index-driven injection). Relaxing Helios validation without updating VisionState would let re-prefill of an unindexed decoded image_token either fail device validation or overwrite its text embedding with an arena feature vector.

Separating the immutable initial prompt prefix (0..initial_prompt_tokens, anchored in Carried::prompt_tokens) from generated continuation tokens (initial_prompt_tokens..tokens.len()) preserves strict multimodal validation on user prompts while allowing decoded continuation tokens to remain ordinary text (index == -1). Making VisionState index-driven aligns re-exported cores on the same invariant across all recipes sharing ignition.components.vision_state.

Decode-time masking of feature_token on legacy token-keyed cores is intentionally omitted:

  • Captured graphs expose no per-token decode mask other than GrammarMask gated by GrammarEnabled. Enabling GrammarEnabled breaks speculative verification (valid &= (~gram_en) | (prefix == 0)) and requires grammar_constrained = true, permanently forcing width-1 synchronous decode and disabling 2-frame pipelining.
  • Existing index-driven qwen38 cores and legacy token-keyed qwen38_dense cores carry identical ModelContract metadata (ImageLayoutKind::Qwen, feature_token = 248056, span = None, ValueSource::ImageFeatureIndex), so Helios cannot distinguish them without model-identity branching or capability flags disallowed by docs/design-review.md Principles 3 and 13.
  • Without decode masking, legacy token-keyed cores remain safe: continuations that reuse a cached KV prefix past the decoded token succeed, and continuations that re-prefill it abort only that request inside legacy GPU validate_prefill (ExecutionError::Device { code: 32 }, active = False) with zero embedding corruption, zero state mutation, and a healthy worker thread.

What changed

1. Index-driven VisionState in Ignition (ignition/components/vision_state.py, tests/components/test_vision_state.py)

  • Before: VisionState.__init__ required image_token; validate_prefill required (~image & (index == -1)) | (image & (index >= 0) & (index < count[slot])) and rejected any image_token with index == -1; inject copied arena features wherever metadata.token_ids == self.image_token.
  • After: VisionState.__init__ defaults image_token=None while remaining backward-compatible with all recipe call sites passing image_token=.... validate_prefill keys on visual = index >= 0: index == -1 is accepted for any token without requiring a bound feature_slot or matching generation, while visual positions require index < count[slot], index < arena.shape[1], matching generation, valid feature_slot, and tokens == self.image_token when image_token is set. inject keys replacement on (index >= 0) & (index < arena.shape[1]) & (feature_slot >= 0) & (feature_slot < arena.shape[0]).
  • Added unit tests covering text-only and mixed chunks containing unindexed image_token, negative and out-of-bounds indices, stale nonnegative tail indices when feature_slot == -1, and image_token=None.

2. Continuation-aware prompt validation in Helios (helios/src/model.rs, helios/src/model/admission.rs, helios/src/model/tests.rs)

  • Before: validate_prompt_data, Admission::validate, and Admission::from_prompt applied strict initial-prompt feature-token and atomic-span checks across the entire tokens slice.
  • After: Added validate_continuation_prompt_data(config, tokens, data, initial_prompt_tokens), Admission::validate_continuation, and Admission::from_continuation. Existing validate_prompt_data, Admission::validate, and Admission::from_prompt delegate with tokens.len(), preserving strict initial-prompt checks. Continuation validation keeps strict feature-index bijection and atomic-span membership on 0..initial_prompt_tokens, while requiring vision_token_indices == -1, no spans extending past initial_prompt_tokens, and in-vocabulary tokens (< config.contract.vocabulary, blocking out-of-vocabulary sentinels) on initial_prompt_tokens..tokens.len().
  • Added unit tests covering initial vs. continuation boundaries, out-of-vocabulary continuation tokens, nonnegative continuation indices, and atomic ImageSpan tokens.

3. Per-request admission error isolation (helios/src/server/runtime.rs, helios/src/server/runtime/phase_tests.rs)

  • Before: Worker::admit called Admission::from_prompt(...)?, TokenStops::new(...)?, and TextStops::new(...)?, terminating Worker::run on any failure, and assigned self.admissions[slot] before stop-matcher construction completed.
  • After: Worker::admit computes initial_prompt_tokens from parked.as_ref().and_then(|parked| parked.carried.prompt_tokens).unwrap_or(incoming.prompt.tokens.len()), calls Admission::from_continuation, isolates Err from Admission::from_continuation, TokenStops::new, and TextStops::new by calling self.scheduler.cancel(handle)?, incoming.fail(error), setting progress = true, and continuing the loop, and writes self.admissions[slot] only after all three succeed.
  • Added runtime phase tests covering KV preemption (with and without checkpoint eviction, verifying packed -1 vision_token_indices and repeated parking preserving carried.prompt_tokens), thinking_token_budget park/readmission, park_grammar_transition with in-vocabulary feature and span tokens, and error isolation across all three Worker::admit failure sites alongside a healthy concurrent request with full slot and page reclamation.

Compatibility

  • No Protobuf schema or ModelContract fields changed. Previously exported cores load without re-export.
  • Existing index-driven qwen38 cores gain full continuation readmission immediately.
  • Legacy token-keyed cores exported from earlier ignition.components.vision_state.VisionState require re-export to re-prefill unindexed decoded feature tokens as text; until re-exported, such re-prefills fail only the affected request cleanly (ExecutionError::Device { code: 32 }) without corrupting embeddings or terminating the worker thread.

Claimed result

  • VLM requests that decode in-vocabulary image feature or span tokens no longer crash the flare-model worker thread upon KV preemption, thinking_token_budget, or grammar-transition readmission, and malformed admission or stop-matcher inputs fail only the affected request with complete scheduler slot and page cleanup.
  • Re-exported VLM cores built with ignition.components.vision_state.VisionState validate and inject visual features solely by vision_token_indices >= 0, keeping decoded continuation feature tokens as ordinary text embeddings.

Evidence

  • Python CPU component and CLI suites:
    PYTHONPATH=. .venv/bin/python -m pytest tests/components/test_vision_state.py -v
    PYTHONPATH=. .venv/bin/python -m pytest tests/components tests/cli -q
    Result: tests/components/test_vision_state.py 5 passed, 0 failed; tests/components + tests/cli 336 passed, 56 skipped (FLARE_RUN_CUDA_TESTS unset).
  • Targeted Helios continuation validation and runtime worker tests:
    cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --target-dir flare-cli/target --lib -- continuation_prompt_validation vlm_feature_token vlm_feature_and_span worker_admit_isolates
    Result: 4 passed, 0 failed.
  • Rust release crate test suites (CPU):
    • helios --features runtime-core,server --lib: 1,837 passed, 47 ignored, 7 failed (6 template tests require FLARE_TEST_TEMPLATE_DIR; engram::reader::tests::equal_offsets_in_separate_files_never_coalesce failed under an artificially lowered ulimit -l 65536 and passed 1/1 when re-run under default ulimit -l unlimited).
    • helios feature-matrix cargo check (default, runtime-core, runtime-core,server): 0 warnings in modified files.
    • flare: 255 passed, 0 failed, 4 ignored.
    • flare-cli: 246 passed, 0 failed, 3 ignored.
    • heliopause: 229 passed, 0 failed, 6 ignored.
  • TLA+ formal models and Rust observed-edge conformance:
    python3 verification/helios-lifecycle/check.py --tlc-jar /home/luke/.cache/flare-formal/tla2tools-1.7.4.jar --target-dir flare-cli/target
    Result: all passed — Lifecycle (1,710 edges), RankProtocol (1,291 edges), DispatchRing (7,940 edges), OffloadTransfer (8,490 edges), CacheOwnership (222,817 edges), Speculation (13,566 edges), ResponseLifecycle (365,508 edges), CheckpointReservation (68 edges), RankDispatch, and all 12 targeted concurrency/lifecycle regression tests.
  • Unrun checks and limitations:
    • GPU/CUDA tests (FLARE_RUN_CUDA_TESTS=1), checkpoint-backed image_admission tests (FLARE_TEST_SNAPSHOT / FLARE_NEMOTRON_TEST_SNAPSHOT), and live VLM core re-export + flare run serving were not executed on GPU.
    • Template-fixture tests requiring FLARE_TEST_TEMPLATE_DIR (tests/frontend/prepare_templates.py) were not run.
    • cargo-kani and cargo-mutants are not installed on this host, so Kani sequential proofs and mutation tests were not run locally.

Discord: lukealonso

@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 708.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@flare-autobot flare-autobot added bug Something isn't working triage:review Proposed change needs code review; this does not imply merge readiness. triage:validation Proposed implementation needs acceptance evidence; no claim that a reported defect is fixed. and removed triage:review Proposed change needs code review; this does not imply merge readiness. labels Dec 3, 2026
@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Ready To Merge

PR #708 does exactly what it claims, at the right layer, with no per-model branching and no core-format change. Every load-bearing site was verified at 4fee325 with no code bug found; the only material gap is evidence, not code, raised as a pre-merge WARN.

  • Blockers: 0 · Should fix: 0 · Subtract/Simplify: 3 · Nits: 5
Walkthrough
  • Helios prompt validation split by boundary (helios/src/model.rs:406-493): validate_prompt_data now delegates with tokens.len(), so the feature-token bijection (:452-467) and atomic-span membership scan (:468-487) keep their exact old domain on 0..initial_prompt_tokens; continuation positions must carry index == -1 (:459-464) and be < config.contract.vocabulary (:446-448), with boundary rejections at :421-422 guarding both slices against panics.
  • Boundary threaded through admission (helios/src/model/admission.rs:76-111,140-163): validate_continuation/from_continuation added, validate/from_prompt retained as strict delegating wrappers; input_vocabulary bound at :95 still rejects out-of-range prompt tokens before the new data checks.
  • Worker readmission boundary (helios/src/server/runtime.rs:1629-1717): initial_prompt_tokens comes from Carried::prompt_tokens, which park_with_tokens pins to the original prompt length (:2550), so repeated parks cannot drift the boundary (asserted phase_tests.rs:9186).
  • Per-request error isolation (runtime.rs:1641-1683): the three former ? sites become scheduler.cancel(handle)? → incoming.fail(error) → progress = true → continue, which at incoming.fail also wakes the admission waiter (runtime.rs:351-362); self.admissions[slot] is written only after all three constructions succeed (:1717).
  • Index-driven VisionState (ignition/components/vision_state.py:38-61): validate_prefill keys on visual = index >= 0 with slot/count/generation/feature-slot checks gated on visual, and inject replaces embeddings on (index >= 0) & index < arena.shape[1] & feature_slot in [0, rows), so an unindexed decoded feature token stays text in both paths.
Merge Risk: Low · up to 4fee325
  • Admission/readmission logic in a hot, fast-moving file (helios/src/server/runtime.rs: ≥29 PRs in 180 days) is restructured (+71/−33), but the new phase_tests.rs:9035-9385 cases drive the real Worker loop through preemption (with and without checkpoint eviction), thinking_token_budget, grammar transition, and all three failure sites.
  • The load-bearing compatibility claim for already-exported token-keyed cores is unmeasured on GPU (code: 32, active = False, no embedding corruption); failure mode is documented as clean single-request failure, not worker death.
  • ignition/components/vision_state.py semantics change for 9 external recipes that are not in this repository (AGENTS.md:382-396); in-tree blast radius is zero (image_token= appears only in tests/components/test_vision_state.py:18,40,56,82), and legacy cores keep working until re-exported.
Pre-merge checks: ✅ 3 passed · ⚠️ 1 warnings

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

Want a frontier second opinion? If these findings look noisy, request a one-time SuperAgent Review on 4fee325 (~3–4 min; re-adjudicates existing findings without re-running discovery).

To opt out, include #autobot:ignore in your post or comment.

…on readmission and unify index-driven VisionState

Vision-language models that place their image feature token inside the
decoded vocabulary (such as Nemotron-H, GLM-5.3, Qwen3.8, Qwen3.8-Dense,
Inkling2, Kimi3, MiMo-V2, MiniMax-M3, and Step5) can sample that token—or
an in-vocabulary atomic image span delimiter—during ordinary text
generation because Helios does not mask image feature tokens during
decode. When a request later parks for KV cache preemption,
`thinking_token_budget` enforcement, or a speculative-reasoning grammar
transition, `Worker::park_with_tokens` extends the prompt history with the
generated continuation tokens and assigns `vision_token_indices = -1` to
every appended token. On readmission, two failures occurred:
1. In Helios (`helios/src/server/runtime.rs`), `Worker::admit` called
   `Admission::from_prompt`, whose `validate_prompt_data`
   (`helios/src/model.rs`) enforced a strict bijection
   `(*token == layout.feature_token) == (*index >= 0)` and required atomic
   span membership across the entire `tokens` array. Any decoded
   in-vocabulary feature or span token returned `Err`, propagating via `?`
   out of `Worker::run`, marking worker health unhealthy, failing all
   concurrent requests, and permanently terminating the `flare-model`
   worker thread. Failures from `TokenStops::new` and `TextStops::new` in
   `Worker::admit` propagated out of `Worker::run` in the same way.
2. In Ignition (`ignition/components/vision_state.py`), the shared
   `VisionState` used by 9 VLM recipes keyed both `validate_prefill` and
   `inject` on `tokens == self.image_token` rather than
   `vision_token_indices >= 0` (unlike `qwen38`'s index-driven injection).
   Relaxing Helios alone would allow re-prefill of an unindexed decoded
   `image_token` to fail device validation or overwrite its text embedding
   with an arena vector.

Separating the immutable initial prompt prefix (`0..initial_prompt_tokens`,
anchored in `Carried::prompt_tokens`) from generated continuation tokens
(`initial_prompt_tokens..tokens.len()`) keeps strict multimodal validation
on user prompts while treating decoded continuation tokens as ordinary
text (`index == -1`). Making `VisionState` index-driven aligns re-exported
cores on the same invariant. Decode-time masking of `feature_token` on
legacy token-keyed cores is intentionally omitted because captured graphs
only support per-token decode masking via `GrammarMask`/`GrammarEnabled`
(which disables speculative verification and 2-frame pipelining) and
existing index-driven `qwen38` cores share identical `ModelContract`
metadata with legacy token-keyed `qwen38_dense` cores. Legacy token-keyed
cores remain safe without decode masking: continuations that reuse a KV
checkpoint past the decoded token succeed, and continuations that must
re-prefill it abort only that request inside legacy GPU `validate_prefill`
(`ExecutionError::Device { code: 32 }`) without mutating state or killing
the worker thread.

What changed:
- `ignition/components/vision_state.py` and
  `tests/components/test_vision_state.py`: before, `VisionState.__init__`
  required `image_token`, `validate_prefill` rejected unindexed
  `image_token`, and `inject` replaced embeddings wherever
  `metadata.token_ids == self.image_token`. After, `image_token` defaults
  to `None` (preserving compatibility with existing recipe call sites),
  `validate_prefill` keys on `visual = index >= 0` (allowing `index == -1`
  on any token without requiring a feature slot or matching generation,
  while checking `index < count[slot]`, `index < arena.shape[1]`,
  generation match, valid `feature_slot`, and `tokens == self.image_token`
  when `image_token` is set on visual positions), and `inject` keys
  replacement on `(index >= 0) & (index < arena.shape[1]) & (feature_slot >= 0) & (feature_slot < arena.shape[0])`.
  Added unit tests covering unindexed `image_token` in text-only and mixed
  chunks, invalid/out-of-bounds indices, stale tail indices with
  `feature_slot == -1`, and `image_token=None`.
- `helios/src/model.rs`, `helios/src/model/admission.rs`, and
  `helios/src/model/tests.rs`: before, `validate_prompt_data`,
  `Admission::validate`, and `Admission::from_prompt` applied strict
  initial-prompt validation to every token. After, added
  `validate_continuation_prompt_data`, `Admission::validate_continuation`,
  and `Admission::from_continuation`, with existing entry points
  delegating with `tokens.len()`. Continuation validation enforces strict
  feature-index bijection and atomic spans on `0..initial_prompt_tokens`,
  while requiring `vision_token_indices == -1`, no spans past
  `initial_prompt_tokens`, and in-vocabulary tokens
  (`< config.contract.vocabulary`) on `initial_prompt_tokens..tokens.len()`.
  Added unit tests for initial vs. continuation boundaries, OOV
  continuation tokens, nonnegative continuation indices, and atomic
  `ImageSpan` tokens.
- `helios/src/server/runtime.rs` and
  `helios/src/server/runtime/phase_tests.rs`: before, `Worker::admit`
  propagated `Admission::from_prompt`, `TokenStops::new`, and
  `TextStops::new` errors via `?` out of `Worker::run` and stored
  `self.admissions[slot]` before stop-matcher construction finished.
  After, `Worker::admit` computes `initial_prompt_tokens` from
  `parked.carried.prompt_tokens` (falling back to `incoming.prompt.tokens.len()`),
  calls `Admission::from_continuation`, isolates errors from all three
  constructors via `self.scheduler.cancel(handle)?`, `incoming.fail(error)`,
  and `progress = true; continue;`, and writes `self.admissions[slot]`
  only after all three succeed. Added phase tests covering KV preemption
  (with and without checkpoint eviction, packed `-1` indices, and repeated
  parking), `thinking_token_budget` readmission, `park_grammar_transition`
  with in-vocabulary feature and span tokens, and error isolation across
  all three `Worker::admit` failure sites with full slot and page
  reclamation.
- Compatibility: no Protobuf schema or `ModelContract` fields changed.
  Previously exported cores load without re-export; existing `qwen38`
  cores work immediately, while legacy token-keyed cores require re-export
  to re-prefill unindexed decoded feature tokens as text.

Claimed result:
- VLM requests that decode in-vocabulary image feature or span tokens no
  longer terminate the `flare-model` worker thread upon KV preemption,
  `thinking_token_budget`, or grammar-transition readmission, and
  malformed admission or stop-matcher inputs fail only the affected
  request while reclaiming scheduler slots and pages.
- Re-exported VLM cores using `ignition.components.vision_state.VisionState`
  validate and inject visual features solely by `vision_token_indices >= 0`,
  keeping decoded continuation feature tokens as ordinary text embeddings.

Evidence:
- Python CPU tests (`PYTHONPATH=. .venv/bin/python -m pytest`):
  `tests/components/test_vision_state.py` 5 passed; `tests/components` and
  `tests/cli` 336 passed, 56 skipped (`FLARE_RUN_CUDA_TESTS` unset).
- Targeted Helios unit and runtime tests (`cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --lib -- continuation_prompt_validation vlm_feature_token vlm_feature_and_span worker_admit_isolates`):
  4 passed, 0 failed.
- Rust release crate tests (CPU): `helios --features runtime-core,server --lib`
  1,837 passed, 47 ignored, 7 failed (6 template tests require
  `FLARE_TEST_TEMPLATE_DIR`; `engram::reader::tests::equal_offsets_in_separate_files_never_coalesce`
  failed under an artificially lowered `ulimit -l 65536` and passed 1/1
  under default `ulimit -l unlimited`); `helios` feature-matrix `cargo check`
  (default, `runtime-core`, `runtime-core,server`) produced 0 warnings in
  modified files; `flare` 255 passed, 4 ignored; `flare-cli` 246 passed,
  3 ignored; `heliopause` 229 passed, 6 ignored.
- TLA+ formal models and Rust observed-edge conformance (`python3 verification/helios-lifecycle/check.py --tlc-jar /home/luke/.cache/flare-formal/tla2tools-1.7.4.jar --target-dir flare-cli/target`):
  all passed (`Lifecycle` 1,710 edges, `RankProtocol` 1,291 edges,
  `DispatchRing` 7,940 edges, `OffloadTransfer` 8,490 edges,
  `CacheOwnership` 222,817 edges, `Speculation` 13,566 edges,
  `ResponseLifecycle` 365,508 edges, `CheckpointReservation` 68 edges,
  `RankDispatch`, and all 12 targeted concurrency/lifecycle regression tests).
- Unrun checks: GPU/CUDA tests (`FLARE_RUN_CUDA_TESTS=1`), checkpoint-backed
  `image_admission` tests, live VLM core re-export and `flare run` serving,
  `FLARE_TEST_TEMPLATE_DIR` template tests, Kani sequential proofs
  (`cargo-kani` not installed locally), and mutation tests (`cargo-mutants`
  not installed locally).

Design-Signed-Off-By: Antigravity (Gemini); design-review=2e5b
@lukealonso
lukealonso force-pushed the unify-vlm-index-driven-vision-state branch from 4fee325 to f0676b6 Compare December 3, 2026 18:23
@lukealonso
lukealonso merged commit 452c368 into main Dec 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working triage:validation Proposed implementation needs acceptance evidence; no claim that a reported defect is fixed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants