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:
- A cap above the recipe maximum is rejected, not clamped. The flag declares
max_fn=_recipe_context_limit,RecipeParameters.validateruns that bound inPlan.__post_init__, and the resultingUsageErrorfires beforeprepared_contextis ever read — so the clamp branch is dead code and the PR's own test fails. - 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'smax_sequence_tokens, and Helios requiresprefill_chunk_size <= max_sequence_tokensat 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:
- The clamp is unreachable.
Plan.prepared_contextcomputesmin(self.recipe.context, target)(planning.py:363), but no path reaches it withtarget > recipe.context, because validation has already rejected that value inside the samePlanconstructor. - The PR's test fails.
tests/cli/test_planning.py:310-313buildsreplace(base_params, context_target=500000)on the fixture recipe withcontext=262144(tests/cli/test_planning.py:139) and assertsoversized.prepared_context == recipe.context.planning.planreachesfit→params.validate→UsageError("--request-context for fixture-alias must be 1 through 262,144"), so lines 311-313 never execute. - Docs and description contradict the code.
docs/cli-design.md(the added--request-contextrow) says the flag "resolves to the smaller of N and the recipe maximum", and the PR description says "min(recipe.context, N) otherwise" and that "a cap above the pool still shrinks the export artifact". Neither is what the code does.
Fix: choose one contract.
- Clamp (matches the docs, the test and
prepared_context's implementation): dropmax_fn=_recipe_context_limitfrom thecontext_targetparam, keepingmin_value=1. Then values above the recipe maximum flow through andplanning.py:363does the clamping it already implements. - Reject: keep the bound, delete the clamp branch and the
oversizedcase attests/cli/test_planning.py:310-313, and rewrite the docs row to say values above the recipe maximum are rejected.
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:
plan()compares 4096 againstresult.context(262144) → passes, export proceeds and succeeds;- the exported catalog carries
max_sequence_tokens = 2048withprefill_chunk_size = 4096; flare runrejects the core with "prefill_chunk_size must be divisible by 64 and within 64..=context".
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
ignition/planning.py:395-396—Plan.to_dict()records"context": self.contextand"checkpoint_context": self.recipe.contextbut notprepared_context. The{"plan": …}JSON printed by export, debug-serve and bench therefore cannot show the context actually exported asmax_sequence_tokens. The flag value itself does appear viaparameters.to_dict, so this is a reporting gap, not a data loss. Fix: add"prepared_context": self.prepared_context.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, viaadjust_page_tokens), and the corresponding check lives inPlan.__post_init__(planning.py:186-190) far from the other flag checks. Behaviour is correct;--request-contextalone can therefore passresolve_parametersand fail later in planning. Cosmetic split.- Model help (
ignition/cli/help.py(not opened),Context: … tokensline) is recipe-static and still advertises the uncapped context and the uncapped--prefill-chunk-sizeupper bound when a cap is in play. Help has noPlan, so this is not fixable from help alone; at minimum keep the--request-contexthelp text saying the cap also bounds--prefill-chunk-size(see B2). tests/cli/test_planning.py:329asserts only the manifest parameter's scope, not its value (the value goes touint_value,ignition/preparation/rebuild_manifest.py:270-283), so a wrong recorded value would not fail the test. Alsotests/cli/test_planning.py:300-303calls the uncapped plan "stock" without defining the term.
Verified clean (no finding)
- No-flag equivalence:
prepared_contextreturnsself.recipe.contextwhencontext_target is None(planning.py:361-362), which is exactly whatcommon_preparation_kwargspassed before this PR (bootstrap.py:132previouslyplan.recipe.context). Omitting the flag is byte-identical to main on the preparation path. - Pool clamp claim in the description: serve-time
fit_contextapplyingmin(context, prepared_context)means a cap above the pool does not raise the pool bound; consistent with the change. - Seam choice:
common_preparation_kwargsis the single place every recipe picks up the context, so the cap cannot be missed by an individual recipe. - Page-multiple validation exists at
planning.py:186-190with the "multiple of the" wording the test matches (tests/cli/test_planning.py:319). - Cap appears in reproduction args:
repro_always=True(parameters.py:1319) withmanifest_key="context_target"andDEPLOYMENTscope, and the test asserts the flag and value (tests/cli/test_planning.py:324-325). - Bench context check now uses
prepared_context(planning.py:212). - Serve body limit now sizes
max_body_bytesfromplan.prepared_context(ignition/cli/serve.py:67), so an over-cap request body is rejected at the HTTP layer instead of at scheduling.
Open questions / what only a test can settle
- Whether maintainers intend the flag to clamp (docs + test +
prepared_contextimplementation) or to reject above the recipe maximum (the parameter spec). B1 is one decision; the code currently implements both partially. - Whether
prefill_chunkshould be lowered automatically when the cap is below it (a clamp, like the context itself) or rejected. B2 assumes rejection is acceptable, matching the existingplan()error style. - No test in the PR covers the chunk-vs-cap pair, an above-maximum cap on a recipe whose context exceeds the pool, or the multi-host export path; only a test on the planning level (not a full
flare runon SM120) settles the Helios load failure end-to-end, thoughvalidate_prefillis unconditional on architecture.
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.