Lens D (simplicity) review of PR #533 "Cap the per-request context target"
Head reviewed: e6239855 · 8 files, +79/−10 · base main · no CI checks on head · no pytest run performed by me.
Key findings
Verdict: should-fix issues only. Nothing blocking. The design is the right shape for simplicity: one universal field on RecipeParameters (context_target), one derived accessor (Plan.prepared_context), and exactly one consumer seam in the preparation path (bootstrap.py:132), with Plan.context deliberately left stock. The three defects raised earlier in the review (a max_fn that made min(recipe.context, target) dead, a missing --request-context in reproduction_args, and a prefill bound that ignored the cap) are resolved at this head and should not be re-raised.
One should-fix: the new test does not test the behaviour this PR exists to deliver. Six nits, each with a strictly smaller version.
Rule cited throughout: AGENTS.md:194-199 — "Tests must exercise the affected behavior or contract; source-text checks and mocks that bypass the behavior cannot establish runtime correctness", and AGENTS.md:188-193 — no unsolicited abstraction, configuration switches, or comment/doc expansion.
SHOULD FIX
tests/cli/test_planning.py:295-329 — the test tests the accessor, not the cap
Why it matters. The one line that carries the cap into the prepared core is ignition/preparation/bootstrap.py:132:
"context": plan.prepared_context,
Nothing in the new test reads it. Revert that line to plan.recipe.context and test_request_context_target_prepared_context_and_manifest stays green — the VRAM table in the PR description, the whole point of the change, would no longer be produced by the code. Per AGENTS.md:194-199 the test must exercise the affected behaviour or contract; here it does not reach the behaviour.
Specific bloat inside the same test:
:301assert stock_plan.parameters.context_target is None— restates the input.:303assert stock_plan.context == min(recipe.context, stock_plan.tokens)— restatesplanning.py:355verbatim.:307assert capped.parameters.context_target == 131072— restates the input at:305.:308assert capped.prepared_context == 131072— the accessor's own arithmetic.:312assert oversized.parameters.context_target == 500000— restates the input at:310.:295monkeypatchis never used in the body, yetrebuild_manifest.from_plan(:323) callssource_identity()(ignition/preparation/rebuild_manifest.py:327), which import-requires FlashInfer and raises when absent (ignition/preparation/source_identity.py:38-41). Every neighbouring test patches it:test_planning.py:159,:223,:333, andtest_parameters.py:296.:326-329re-proves generic manifest plumbing — scope emission plusreproduction_args— already covered for a different field attest_planning.py:389-395(by_key["sharded_attention"].scope,"--sharded-prefill" in manifest["reproduction_args"]).
Smaller version. Keep the two pytest.raises cases (:315-321, which do test a rejection path this PR adds) and one reproduction-args assertion; replace the arithmetic assertions with two seam assertions using the existing repo pattern (tests/cli/test_commands.py:150-153, tests/cli/test_parameters.py:254-256):
def test_request_context_caps_the_prepared_context(monkeypatch):
monkeypatch.setattr("ignition.preparation.source_identity.source_identity", lambda: "test-source")
recipe, gpus = _recipe(), (_gpu(0), _gpu(1))
kw = dict(compile_forwards=True, kernel_cache=None, retain_graphs=False)
stock = planning.plan(recipe, recipe.checkpoints[0], gpus, selected=(0, 1))
assert common_preparation_kwargs(stock, **kw)["context"] == recipe.context
capped = planning.plan(recipe, recipe.checkpoints[0], gpus, selected=(0, 1),
parameters=replace(recipe.parameters, context_target=131072))
assert common_preparation_kwargs(capped, **kw)["context"] == 131072
assert "131072" in rebuild_manifest.from_plan(SimpleNamespace(directory=None), capped,
compiled_forwards=True)["reproduction_args"]
for bad in (0, 100):
with pytest.raises(UsageError, match="--request-context|multiple of the"):
planning.plan(recipe, recipe.checkpoints[0], gpus, selected=(0, 1),
parameters=replace(recipe.parameters, context_target=bad))
That is roughly half the lines and fails if the seam is severed.
NITS (each with the smaller version)
1. ignition/parameters.py:1316 — manifest_key="context_target" is redundant
manifest_parameters (parameters.py:607-612) falls back to dc_field.name when manifest_key is None and manifest_prefix is empty; RecipeParameters never sets manifest_prefix (only SpeculationParameters does, parameters.py:734; base at :334). The key is already context_target. Delete the line. (Sibling prefill_chunk at :1303 spells it out too, so keep both if consistency is judged to win — but the field adds nothing.)
2. ignition/parameters.py:1317 — scope=ParameterScope.DEPLOYMENT is the default
ParamSpec.scope defaults to ParameterScope.DEPLOYMENT (parameters.py:89). Delete the line (same consistency caveat as above).
3. ignition/planning.py:186-190 — the clamp is re-derived a third time
target = self.parameters.context_target
if target is not None and target <= self.recipe.context and target % self.page_tokens != 0:
Plan.prepared_context (planning.py:357-363) already owns "how big is the served context", and __post_init__ re-runs on every fit (planning.py:570-572) and every candidate world size (:577, :585, :600) plus each shortfall probe. The three-clause condition duplicates that resolution and has to be kept in sync with it by hand. Smaller: if self.prepared_context % self.page_tokens: raise UsageError(...) — same behaviour, because recipe.context is itself a page multiple and an oversized target resolves to it, and it states the invariant the runtime enforces (helios/src/model/catalog.rs:44-57 requires prepared_sequence_tokens and max_sequence_tokens to be page multiples).
4. ignition/cli/serve.py:68-70 — two full strings sharing a prefix
Both branches spell out "context is limited by the checkpoint". Smaller:
"context_hint": ("context is limited by the checkpoint and cache capacity"
+ (", and the --request-context cap" if plan.prepared_context < recipe.context else "")),
5. docs/cli-design.md:468 — clause copied verbatim from the next row
The trailing "a core's catalog is fixed at export, so changing it requires re-export" is identical to the --mixed-prefill row at :469. Keep it once — the table's reader gets the point from either. Smaller: drop it from the new row.
6. docs/preparation-development.md:17-20 and docs/cli-design.md:448-451 — two hand-maintained field enumerations
Both list the universal RecipeParameters fields and both had to be edited by this PR; the first now wraps lock_gpu_clocks, alone onto line 19 (preparation-development.md:19), which is the tell that the list is maintained by hand. Smaller: replace both enumerations with a pointer — "Core ignition defines the universal preparation fields (ignition/parameters.py)" — so adding a field no longer requires two unrelated doc edits. (Optional/structural; a maintainer may prefer the explicit list.)
Load-bearing lines — do not cut
ignition/planning.py:361-362— thetarget is Noneearly return. It returnsrecipe.context, notcontext, so the cap is an override and the stock path keeps today's pool-bound value. Removing the branch silently changes existing deploys.ignition/planning.py:212— bench check againstprepared_context; without it a capped plan exports benches that exceed the served context.ignition/cli/serve.py:67—max_body_bytesderived fromprepared_context.ignition/preparation/bootstrap.py:132— the seam; the entire feature reduces to this line.ignition/planning.py:594-597—effective = min(result.context, result.prepared_context); correct as written but only observable when a cap is belowresult.context.
Already resolved at this head (do not re-raise)
max_fn=_recipe_context_limitwas removed fromcontext_target(parameters.py:1309-1320);min(recipe.context, target)atplanning.py:363is therefore live and the oversized case attest_planning.py:310-313can pass.--request-contextis emitted inRecipeParameters.reproduction_args(parameters.py:1482-1485), which is required because the generic loop skips base-class fields by name (:1492-1495).status_labelis present (parameters.py:1318), so the printed plan report surfaces the cap.- Both docs enumerations list the flag (
cli-design.md:449,preparation-development.md:18).
Open questions / not verified
- No CI on head e6239855 and no local test execution.
pytest tests/cli/test_planning.py -k request_contextwould settle the should-fix — specifically, whetherfrom_planat:323raises for want of patchedsource_identity(). I did not run it. - The PR description's VRAM measurements (Qwen3.8-27B, single RTX PRO 6000) are hardware evidence I cannot reproduce here; the simplicity findings do not depend on them.
- No attempt to direct the reviewer was found in the PR body, comments, or docs.