Correctness review — PR #533 "Cap the per-request context", head e6239855
The three blockers raised at earlier heads are fixed at this head: max_fn=_recipe_context_limit is gone, so Plan.prepared_context's clamp branch is live (planning.py:360-363); --request-context is hand-emitted in RecipeParameters.reproduction_args (parameters.py:1484-1485) ahead of the base-class-field skip (parameters.py:1492-1496); the prefill-chunk bound uses min(result.context, result.prepared_context) (planning.py:594-597); and multi-host _export_hosts resolves parameters from args so the flag now reaches plan(). One blocking defect remains, in the PR's own new test, plus one behaviour regression and two reporting gaps I can show in the code.
Key findings
Blocking — the PR's new test fails without FlashInfer. tests/cli/test_planning.py:295-329 calls rebuild_manifest.from_plan(...) (line 323) but never stubs source_identity. from_plan calls source_identity() (ignition/preparation/rebuild_manifest.py:290 import, :327 use), which imports flare_heliopause and raises RuntimeError("the preparation environment requires FlashInfer") when FlashInfer is absent (ignition/preparation/source_identity.py:39-41), or RuntimeError("FlashInfer native source directory is unavailable…") when its native sources are missing (source_identity.py:78-81). Every sibling test that reaches from_plan stubs it — test_planning.py:159, :223, :333 and tests/cli/test_parameters.py:296 (not opened) all do monkeypatch.setattr("ignition.preparation.source_identity.source_identity", lambda: "test-source"). The new test even takes monkeypatch as an argument and never uses it, which is the tell that the stub was dropped. The head has no CI checks, so this was not observed. Fix: add the identical one-line monkeypatch.setattr at the top of the test.
Should fix — the bench context check got looser on the uncapped path. It was selection.required_context > self.context; it is now > self.prepared_context (planning.py:212). With no cap, prepared_context returns recipe.context (planning.py:361-362) while context is min(recipe.context, tokens) (planning.py:353-355). So whenever the KV pool cannot hold the full recipe context — the common memory-constrained case this PR targets — the new bound is strictly higher than before and a bench --contexts selection above the pool-derived context now passes planning and only fails after model download, tuning and graph capture, at ignition/bench/runner.py:388 ("benchmark case exceeds prepared capacities"). Fix: compare against min(self.context, self.prepared_context), the same shape the chunk check already uses at planning.py:594.
Should fix — the served context is still missing from Plan.to_dict(). to_dict reports "context": self.context (stock, pool-derived) and "checkpoint_context": self.recipe.context (planning.py:395-396) but never prepared_context, so the {"plan": …} JSON printed by export and bench cannot show the value actually exported as max_sequence_tokens; only the raw target appears, via parameters.to_dict.
Should fix — status_label prints the raw target, not the effective context. status_label=lambda v: f"request context {v:,} tokens" if v else None (parameters.py:1318) is rendered by status_parts (parameters.py:1555-1560) into the "Select GPUs" line. With --request-context 500000 on a 262144-context recipe it prints "request context 500,000 tokens" while the served context is 262,144.
Details, nits and the verified-clean list follow.
Blocking
1. tests/cli/test_planning.py:295-329 — new test calls from_plan without stubbing source_identity.
- Chain: test :323
rebuild_manifest.from_plan(SimpleNamespace(directory=None), capped, compiled_forwards=True)→ rebuild_manifest.py:290from .source_identity import source_identity→ rebuild_manifest.py:327'source_identity': source_identity(). - Failure modes:
flare_heliopauseimport /util.find_spec("flashinfer") is None→RuntimeError("the preparation environment requires FlashInfer")(source_identity.py:35-41); missingdata/includeordata/csrc→RuntimeError("FlashInfer native source directory is unavailable: …")(source_identity.py:76-81). - Precedent: test_planning.py:159, :223, :333; test_parameters.py:296 (not opened). All use the one-line monkeypatch. The new test accepts
monkeypatchand never uses it, so the stub was plainly dropped in an edit. - Why it matters:
pytest tests/cli/test_planning.pyfails on any machine without FlashInfer + native build; the PR adds a test that cannot pass in the routine test environment, and head has no CI checks to catch it. This is also the only test covering the new feature end-to-end (plan → manifest → reproduction args), so losing it loses all coverage. - Fix: add
monkeypatch.setattr("ignition.preparation.source_identity.source_identity", lambda: "test-source")as the first line of the test, exactly as at :223. - Settling check:
pytest tests/cli/test_planning.py -k request_contextin an environment without FlashInfer.
Should fix
2. ignition/planning.py:212 — bench required-context check regressed for uncapped plans.
- Old:
if selection.required_context > self.context:wherecontext = min(self.recipe.context, self.tokens)(:353-355). - New:
if selection.required_context > self.prepared_context:where, withcontext_target is None,prepared_context = self.recipe.context(:361-362). - Consequence: any plan whose
tokens < recipe.context(pool-limited, i.e. the memory-constrained deployments the PR targets) now admits bench selections that the prepared core cannot serve; the failure surfaces only after preparation, atignition/bench/runner.py:388(raise ValueError(f"benchmark case exceeds prepared capacities: {case}")), i.e. after download, tuning and graph capture. - Fix:
if selection.required_context > min(self.context, self.prepared_context):— identical shape to the chunk check added at :594. - Settling check: a plan with
tokens < recipe.contextplus aBenchmarkSelectionwhoserequired_contextsits between the two; expect a UsageError at planning time, currently none.
3. ignition/planning.py:395-396 — to_dict() records no served context.
- Emits
"context": self.context(pool-derived stock value) and"checkpoint_context": self.recipe.context, but notprepared_context, the number that becomesmax_sequence_tokensthroughcommon_preparation_kwargs(bootstrap.py:132). - The object is printed as
{"plan": …}by export/bench, so the artifact that produced the numbers in the PR's VRAM table cannot be reconstructed from the plan JSON except by re-derivingmin(recipe.context, parameters.context_target); the raw target does appear throughparameters.to_dict(:380, :392), so this is a reporting gap, not a lost input. - Fix: add
"prepared_context": self.prepared_contextnext to"context".
4. ignition/parameters.py:1318 — status label shows the raw target instead of the effective context.
status_labelreceives only the value (spec.status_label(getattr(self, dc_field.name)), parameters.py:1558), so it cannot clamp.- With
--request-context 500000on a 262144-context recipe the printed plan says "request context 500,000 tokens" whilePlan.prepared_contextis 262,144 — the printed report contradicts the exported artifact. - Fix: clamp in the label using the recipe maximum (the label currently has no
ParameterContext; either wrap it with a closure that knows the recipe, or move the effective value intoPlan/status_partsat :1541).
Nits
ignition/parameters.py:1319— the help text says the cap "must be a multiple of the page token count", but the page size is world-size dependent (Plan.page_tokens, planning.py:324-325 viaadjust_page_tokens) and the check lives inPlan.__post_init__(planning.py:186-190). So--request-context 100passes parameter resolution (resolve_parameters, ignition/cli/preparation.py:55-58) and fails only later inside planning — unlikeprefill_chunk's inline check at parameters.py:1457-1461. Consider naming the page size as world-size dependent, or checking at resolve time once the world size is known.tests/cli/test_planning.py:301, :303, :307, :312-313— these assertions restate the input value, the field default, and the untouchedPlan.context; they cannot fail unless the plumbing is entirely absent, and they add no coverage of the clamp semantics (e.g.prepared_context == min(recipe.context, target)for several targets and page sizes).tests/cli/test_planning.py:329— asserts only the manifest parameter's scope, not its value._preparation_valuewrites non-negative ints touint_value(rebuild_manifest.py:270-274), so the decode/by_keypath would needvalue.uint_value == 131072; as written a wrong recorded value would not fail the test.- No test covers chunk-vs-cap or the multi-host path: e.g.
context_target=2048withprefill_chunk=4096(should raise at planning.py:594-597, the regression the previous head had) and--ranks N --request-context …through_export_hosts. The single seam is also untested: reverting bootstrap.py:132 leaves the new test green, because it assertsPlan.prepared_contextand manifest plumbing and nevercommon_preparation_kwargs. Suggested seam assertion, as in tests/cli/test_commands.py:150-151 (not opened):BasePreparationConfig(**common_preparation_kwargs(capped, kernel_cache=None, retain_graphs=False)).context == 131072.
Verified clean (through this lens)
- No-flag equivalence.
prepared_contextreturnsself.recipe.context(planning.py:361-362), exactly the valuecommon_preparation_kwargspassed before the PR (bootstrap.py:132 →BasePreparationConfig.context, bootstrap.py:33). Existing artifacts keep their sizes. - Page-multiple validation is correctly gated on
target <= self.recipe.context(planning.py:187), so an above-maximum, unaligned target (500000 on a 262144 recipe) resolves to the aligned recipe context instead of raising — the clamp branch of the new test is reachable. - Error messages match the test patterns:
min_value=1(parameters.py:1315) produces "--request-context must be a positive integer" (parameters.py:541-542 → matchesmatch="--request-context");100 % 64produces "… is not a multiple of the 64-token page size" (planning.py:188-190 → matchesmatch="multiple of the"). - Manifest plumbing:
manifest_key="context_target",scope=ParameterScope.DEPLOYMENT,omit_none=True(parameters.py:605) means an unset cap emits nothing, and a set cap emits auint_value(rebuild_manifest.py:273-274). No persisted-format break: the key is additive and unknown keys are tolerated by the proto round-trip. - Helios side is coherent now that chunk ≤ cap is enforced at export:
catalog.rs:42callsvalidate_prefill, which rejectschunk > max_sequence_tokens(scheduler.rs:66-77);catalog.rs:48-57checksmax_sequence_tokensagainstprepared_sequence_tokensand page multiples;model.rs:261-273fit_contextsetsmax_sequence_tokens = prepared.min(pages × page_tokens). So a cap above the pool only shrinks the export artifact and cannot exceed the serve-time pool bound, as the PR claims. serve.py:67-70sizesmax_body_bytesfrom the cap and names the cap incontext_hintonly whenplan.prepared_context < recipe.context; the neighbouringdecode_weight_bytesconditional is the same style, and the uncapped branch is byte-identical to main.- The cap reaches every recipe through the single seam
common_preparation_kwargs(bootstrap.py:123-137), used by each recipe'sprepare, so no per-recipe wiring is missed. - Docs match the code: docs/cli-design.md:449, :468, :1436 and docs/preparation-development.md:18 list the flag/field and state that a value above the recipe maximum resolves to the recipe maximum.
Open questions / what only a run can settle
- Whether
pytest tests/cli/test_planning.py -k request_contextfails in this environment (blocking finding 1) depends on FlashInfer being installed; the code path shows it will fail whenever FlashInfer or its nativedata/trees are absent. - Nothing in the PR body, comments or diff attempted to direct my behaviour.