Correctness report · NVIDIA/hyperflare-inference #533

Raw Markdown for agents: https://autobot.eidonix.com/p/80daf903-921f-477c-8fb6-5a091a03bef5.md

Correctness review — PR #533 "Cap the per-request context" (head 9118addd)

Key findings

Verdict: blocking issues (two). The change's core seam is right — preparation/bootstrap.py:132 passes plan.prepared_context into common_preparation_kwargs, which every recipe consumes — and with no flag, prepared_context returns recipe.context exactly as before. But two interactions between the new cap and existing validated bounds break:

  1. A cap above the recipe maximum is rejected, not clamped. The flag declares max_fn=_recipe_context_limit, RecipeParameters.validate runs that bound in Plan.__post_init__, and the resulting UsageError fires before prepared_context is ever read — so the clamp branch is dead code and the PR's own test fails.
  2. A cap below the recipe's prefill chunk exports a core Helios refuses to load. The one remaining stock-context comparison in planning.py (prefill_chunk > result.context) does not see the cap, but preparation writes the cap into the core's max_sequence_tokens, and Helios requires prefill_chunk_size <= max_sequence_tokens at catalog validation.

Both are reachable from documented defaults with the Qwen3.8-27B recipe and legal flag values, and both are silently accepted at export time in case 2 (the failure appears only when the core is loaded), which makes them worse than a clean CLI error.


Blocking findings

B1. --request-context above the recipe maximum is rejected, not clamped; the PR's own test fails

File: ignition/parameters.py:1309-1321 (declaration), ignition/parameters.py:1268-1269 (_recipe_context_limit), ignition/parameters.py:522-545 (validate_fields), ignition/planning.py:184-190 (Plan.__post_init__), ignition/planning.py:357-363 (prepared_context), tests/cli/test_planning.py:310-313

context_target is declared with min_value=1, max_fn=_recipe_context_limit, and _recipe_context_limit(group, context) returns context.recipe.context (parameters.py:1268-1269). ParameterGroup.validate_fields resolves that maximum (_resolved_max, parameters.py:241-246) and raises when the value is outside it (parameters.py:536-540, message form "… must be {min} through {max}"). Plan.__post_init__ calls self.parameters.validate(context) as its first action (planning.py:185), and fit validates too (planning.py:456).

Consequences:

Fix: choose one contract.

Either way the help text at parameters.py:1320 should state the bound.

Settles it: pytest tests/cli/test_planning.py -k request_context.


B2. A cap below the recipe's prefill chunk exports a core Helios refuses to load

Files: ignition/planning.py:594-596, ignition/parameters.py:1294-1308 (prefill_chunk, max_fn=_recipe_context_limit), ignition/preparation/bootstrap.py:132, helios/src/scheduler.rs:66-77, helios/src/model/catalog.rs:42

The export-side check still compares the chunk against the stock context:

if params.prefill_chunk > result.context:      # result.context == min(recipe.context, tokens)
    raise UsageError(f"--prefill-chunk-size {params.prefill_chunk:,} exceeds the {result.context:,}-token context"
                     " this plan allows")

(ignition/planning.py:594-596)

RecipeParameters.prefill_chunk is likewise bounded only by the recipe context via max_fn=_recipe_context_limit (parameters.py:1301). Neither knows about context_target.

Preparation, however, hands plan.prepared_context to every recipe as the context (ignition/preparation/bootstrap.py:132), which is what becomes the exported core's max_sequence_tokens, and Helios enforces:

pub(crate) fn validate_prefill(&self) -> Result<()> {
    if self.prefill_chunk_size < 64
        || !self.prefill_chunk_size.is_multiple_of(64)
        || self.prefill_chunk_size > self.max_sequence_tokens

(helios/src/scheduler.rs:66-77), called from validate_inner during catalog validation (helios/src/model/catalog.rs:42).

Concrete reproduction from documented defaults: Qwen3.8-27B's recipe prefill chunk is 4096 (docs/cli-design.md:244 region, cited from the earlier read) and its context is 262144. Running ignition export qwen3.8-27b … --request-context 2048 is fully legal — 2048 ≥ 1, ≤ recipe max, and a multiple of the page size — so:

The failure surfaces only at serve time, on an artifact the user was told was prepared successfully. The same applies to any --request-context below the chunk (64, 128, … 2048 with the default 4096). This is particularly easy to hit because the stated purpose of the flag is memory pressure — i.e. users are pushing the value down.

Note that the bench check in the same file was already switched to the cap (selection.required_context > self.prepared_context, planning.py:212), so planning.py:594-596 is the one remaining stock-context comparison in that file.

Fix: in planning.plan (and/or Plan.__post_init__, where the other cross-parameter checks now live), compare against the effective context, e.g. effective = min(result.context, result.prepared_context) and raise naming the cap: --prefill-chunk-size 4096 exceeds the 2048-token context --request-context allows. Also consider bounding prefill_chunk's max_fn by the cap so resolve_parameters rejects the pair before planning, matching how the chunk's other bounds are enforced.

Settles it: pytest tests/cli/test_planning.py plus a unit assertion that planning.plan(..., parameters=replace(base, context_target=2048)) raises for a recipe with prefill_chunk=4096. Nothing in the current test file covers the chunk-vs-cap pair.


Nits

  1. ignition/planning.py:395-396 — Plan.to_dict() records "context": self.context and "checkpoint_context": self.recipe.context but not prepared_context. The {"plan": …} JSON printed by export, debug-serve and bench therefore cannot show the context actually exported as max_sequence_tokens. The flag value itself does appear via parameters.to_dict, so this is a reporting gap, not a data loss. Fix: add "prepared_context": self.prepared_context.
  2. ignition/parameters.py:1320 — the help text says the cap "must be a multiple of the page token count", but page size is world-size dependent (Plan.page_tokens, planning.py:323-325, via adjust_page_tokens), and the corresponding check lives in Plan.__post_init__ (planning.py:186-190) far from the other flag checks. Behaviour is correct; --request-context alone can therefore pass resolve_parameters and fail later in planning. Cosmetic split.
  3. Model help (ignition/cli/help.py (not opened), Context: … tokens line) is recipe-static and still advertises the uncapped context and the uncapped --prefill-chunk-size upper bound when a cap is in play. Help has no Plan, so this is not fixable from help alone; at minimum keep the --request-context help text saying the cap also bounds --prefill-chunk-size (see B2).
  4. tests/cli/test_planning.py:329 asserts only the manifest parameter's scope, not its value (the value goes to uint_value, ignition/preparation/rebuild_manifest.py:270-283), so a wrong recorded value would not fail the test. Also tests/cli/test_planning.py:300-303 calls the uncapped plan "stock" without defining the term.

Verified clean (no finding)

Open questions / what only a test can settle

Notes on process

Earlier rounds of this review (recorded in the scratchpad) raised findings that are now fixed at this head and are not repeated above: the missing context= parameter on derive(), the absent page-multiple validation, the manifest/reproduction silence on the flag, and the multi-host export path dropping the flag. The scratchpad's earlier "500000 clamp case fails" note is superseded by B1, which rests on the max_fn bound rather than page alignment.