Correctness scratchpad · NVIDIA/hyperflare-inference #533

Raw Markdown for agents: https://autobot.eidonix.com/p/58ffc068-5f64-45b0-8227-3740bd23f6c4.md

#1 [high] Blocking: --request-context is silently ignored on multi-host export

ignition/cli/serve.py:193-206: _export_hosts calls planning.plan(...) with the full flag set but ends at row_shard_prefill=args.row_shard_prefill) — no context=args.request_context, while the same PR added it at serve.py:289 (_prepare), serve.py:472 (debug_serve) and bench.py:177.

Effect: ignition export MODEL --ranks 2 --request-context 131072 accepts the flag and prepares at the recipe max context with no warning; the KV-pool saving the PR is about never happens. The charter ("Don't silently ignore API fields", charter line 13) and AGENTS.md:452-456 make a silently accepted setting a defect. Fix: pass context=args.request_context in the _export_hosts plan() call (and check args carries the attribute for that subcommand — _preparation_arguments is shared by export, so it does).

#2 [high] Blocking: capped context is not page-aligned, so the exported core fails to load in Helios

ignition/planning.py:368-373 Plan.prepared_context returns min(recipe.context, context_target, tokens). fit() validates only context > 0 (planning.py:459-460) and plan() validates only the prefill chunk (planning.py:694-700). Nothing requires the result to be a multiple of the page size.

ignition/preparation/bootstrap.py:58 now puts that value into the preparation config as context, which becomes the core's max_sequence_tokens; Helios reads it as prepared_sequence_tokens (helios/src/server/config.rs:131-148) and helios/src/model/catalog.rs:44-71 rejects a core unless BOTH prepared_sequence_tokens and limits.max_sequence_tokens are multiples of page_tokens ("invalid prepared model configuration").

So ignition export MODEL --request-context 200000 with a 128-token page (MiniMax M3.1 Flash page_tokens=128, per tests/server/test_minimax_m3_cache.py:110; fixture recipes use 64/128) prepares and exports happily, then flare run CORE fails at load with an opaque configuration error. 200000/128 = 1562.5. Fix: round the target down (or reject it) to a multiple of page_tokens in fit()/Plan.__post_init__, and say so in the error message, e.g. "--request-context 200000: must be a multiple of the 128-token page".

#3 [high] Should fix: the cap is invisible in the printed plan and in reproduction arguments

ignition/planning.py:389-442 Plan.to_dict() reports "context": self.context (stock: min(recipe.context, tokens)) and "checkpoint_context": self.recipe.context, but never prepared_context/context_target. ignition/cli/serve.py:215,485 and bench.py:182 print plan.to_dict() as the plan report, so a capped export prints a plan identical to an uncapped one.

Likewise ignition/preparation/rebuild_manifest.py:231-318 reproduction_arguments() emits no --request-context, and from_plan() (rebuild_manifest.py:343-395) records no key for it. AGENTS.md:452-456 requires an advanced flag be "carried through the plan into the recipe's PreparationConfig, so the plan, its printed report, and its recorded measurements describe what was prepared"; docs/runtime-core-design.md:372,452 make reproduction_args the reproduction contract rendered by flare inspect.

Effect: flare inspect prints an ignition export command that reproduces the uncapped 256K core, not the 128K core that was shipped, and neither the printed plan nor the manifest shows the cap. Fix: emit the capped value in to_dict (e.g. a prepared_context/request_context key) and add if plan.context_target is not None: args.extend(['--request-context', str(plan.context_target)]) plus a request_context deployment-scope parameter in from_plan.

#6 [high] Research summary

Reviewed PR #533 (cap the per-request context) through the correctness lens: read the full diff, then the changed functions in context (planning.py Plan/fit/plan, bootstrap.py's common_preparation_kwargs, all four CLI entry points, bench's Settings/BenchmarkSelection) and followed the value into Helios (server/config.rs, model/catalog.rs, model.rs fit_context) and into the export/reproduction paths (rebuild_manifest.py). Four confirmed findings plus verification notes are in the scratchpad:

  1. Blocking — _export_hosts (serve.py:193–206) never forwards context=args.request_context, so ignition export --ranks N --request-context N silently ignores the flag: no error, no cap, no KV saving. This contradicts the charter's "don't silently ignore API fields" rule and the AGENTS.md rule that an advanced flag be carried through the plan.
  2. Blocking — prepared_context = min(recipe.context, target, tokens) is never required to be page-aligned, yet it becomes the core's max_sequence_tokens, which Helios rejects at load unless it is a multiple of page_tokens (catalog.rs:44–71). A cap such as 200000 with a 128-token page exports fine and then fails to load in flare run.
  3. Should fix — Plan.to_dict() and rebuild_manifest.reproduction_arguments()/from_plan() record nothing about the cap, so an export prints a plan identical to an uncapped one and flare inspect reproduces the wrong (256K) core; AGENTS.md and the runtime-core design doc both require the opposite.
  4. Should fix — bench's required_context check (planning.py:248) compares against the stock Plan.context, so a --contexts list above the cap passes planning and only fails in the runner after the whole GPU preparation and graph capture.

Nit: a target above the recipe max is clamped silently, with no notice, though the docs describe the flag as a cap below that maximum. Nothing else surfaced in the changed code; the no-flag path does look byte-equivalent to stock.

#9 [high] Research summary

Verdict: blocking (two defects in the test this PR adds; the earlier code blockers are fixed, and two nits remain). Time ran out before I could write these to the scratchpad, so they are recorded here in full.

Fixed since my last review (verified in code at head de1b5b5)

Blocking: the added test cannot pass — tests/cli/test_planning.py:229-232 contradicts the new validation

The test plans with context=500000 and asserts a plan with prepared_context == min(recipe.context, oversized.tokens). The fixture recipe has page_tokens=64 and RankCosts.page_tokens is unset, so Plan.page_tokens == 64 (planning.py:329-332), and 500000 % 64 == 32. Plan.__post_init__ (planning.py:289-290) therefore raises UsageError("--request-context 500,000 is not a multiple of the 64-token page size"), and the assertion never runs. Fix: use an aligned over-size target (e.g. 524288, which is 64 × 8192) for the clamp case, and keep a separate unaligned value for the rejection case. Note the behavioural consequence of validating the raw target rather than prepared_context: a target above recipe.context/tokens is rejected when unaligned even though it clamps to an aligned value and changes nothing — worth deciding explicitly (accept, floor, or reject) and saying so in the docs row at docs/cli-design.md:446.

Blocking: the manifest assertion names a field that does not exist — tests/cli/test_planning.py:257

assert by_key["context_target"].value.int64_value == 131072 — PreparationValue has int_value = 2 and uint_value = 3 (helios/proto/runtime_core.proto:124-133), and _preparation_value() writes non-negative ints as uint_value (ignition/preparation/rebuild_manifest.py:333). Python protobuf exposes only the declared names, so int64_value raises AttributeError; even with the name corrected to int_value the assertion would read 0 because the oneof holds uint_value. Fix: assert by_key["context_target"].value.uint_value == 131072 (matching tests/preparation/test_native_publication.py:78 (not opened)).

Both failures are plain-arithmetic/name facts, so pytest tests/cli/test_planning.py settles them; the PR head has no CI checks, which is presumably why they were not seen.

Nits

No other caller, configuration, or persisted-state interaction turned up in this lens: derive()/fit()/plan() are the only Plan constructors, Plan is frozen so the new defaulted field cannot break existing construction, replace() in the CLI paths preserves the cap, multi-host peers receive the prepared config from rank zero, and Helios reads the cap only through the existing max_sequence_tokens / limits path.

#10 [high] Blocking: the PR's new test cannot pass — clamp case violates the new page-multiple validation

Verified at head de1b5b5 on PR #533.

tests/cli/test_planning.py:229-232:

    # Clamp: target > recipe max -> prepared_context == min(recipe.context, tokens)
    oversized = planning.plan(recipe, recipe.checkpoints[0], gpus, context=500000, **base)
    assert oversized.context_target == 500000
    assert oversized.prepared_context == min(recipe.context, oversized.tokens)

#4 [medium] Should fix: benchmark required_context is validated against the stock context

ignition/planning.py:248 (if selection.required_context > self.context) still compares a bench --contexts workload against the stock Plan.context, not prepared_context. With ignition bench MODEL --request-context 131072 --contexts 16384 (required_context = 16384 + 2*width ≈ 16400 < 131072) this is harmless, but a contexts list above the cap passes planning and then fails much later in ignition/bench/runner.py:388 ("benchmark case exceeds prepared capacities") — after the full GPU preparation, tuning and graph capture. Fix: compare against self.prepared_context in __post_init__ so the UsageError comes before any GPU work.

Same shape of issue is already handled correctly for the prefill chunk (planning.py:694-700), so this looks like an oversight rather than a deliberate choice.

#5 [medium] Verification notes: page alignment and silent clamping above the recipe max

Caveat for entry #2: recipes live in the external hyperflare_recipes repository (AGENTS.md:381), so a recipe's prepare() could in principle round config.context before declaring max_sequence_tokens. Nothing in this repository does so, and the checks that would catch a non-multiple value live in Helios (helios/src/model/catalog.rs:44-71), i.e. after export, so the worst case is a core that exports and then fails to load. Verify with: export a recipe whose page_tokens is 128 with --request-context 200000 and run flare run on the core; if the recipe rounds, a unit test on Plan.prepared_context page alignment is what settles it.

Related nit (same file, planning.py:459-460): fit() only rejects context <= 0; a target above recipe.context is silently clamped (min(recipe.context, ...)) with no notice, while docs/cli-design.md:446 describes the flag as a cap "below the recipe's maximum". Emitting the effective value in the plan report (entry #3) would make the clamp visible.

#7 [medium] Verified-clean paths (no finding): no-flag equivalence, pool clamp, error messages

Checked and correct, no finding:

Files read in full or in the relevant span: ignition/planning.py (Plan 160-442, fit 445-542, plan 583-732), ignition/preparation/bootstrap.py, ignition/cli/{init,bench,serve,preparation}.py, ignition/preparation/{execution,model,rebuild_manifest,selection}.py, ignition/declaration.py, helios/src/{server/config.rs, model.rs, model/catalog.rs, scheduler.rs, core/memory.rs}, tests/cli/{test_planning,test_commands}.py, docs/cli-design.md diff, charter, AGENTS.md.