Review of PR #533 "Cap the per-request context target" — lens D (simplicity)
Head commit: 9118add · base: main · 6 files, +69/−5 · open, ready for review, no CI checks on the head, no reviews yet.
Key findings
Verdict: 1 blocking, 1 should-fix, 5 nits.
The change is small and mostly well placed: one parameter on RecipeParameters, one Plan accessor, one validation, one consumer seam in common_preparation_kwargs. Three of the added lines, however, contradict each other — the parameter rejects what the doc, the accessor and the new test all say gets clamped — and the test that documents the clamp cannot pass. The rest is subtraction: a redundant manifest key, a dead repro_always, a validation that runs far more often than it needs to, a doc clause copied from the row below it, and a test that asserts the accessor five times while never touching the seam that actually carries the cap into the core.
Blocking
1. The documented clamp is unreachable, and the test that encodes it fails
Files: ignition/parameters.py:1309-1321 and 1268-1269; ignition/planning.py:186-190, 357-363, 540; tests/cli/test_planning.py:310-313; docs/cli-design.md:468.
context_target is declared as
context_target: int | None = param(
None, flag="--request-context", ..., min_value=1,
max_fn=_recipe_context_limit, # parameters.py:1316
...)
and _recipe_context_limit returns context.recipe.context (parameters.py:1268-1269). ParameterGroup.validate_fields rejects value > max_val with f"{flag} for {alias} must be {lo} through {hi}" (parameters.py:536-540), and plan() calls params.validate(pre_context) before any plan exists (planning.py:540). So on a 262,144-context recipe, --request-context 500000 raises
--request-context for qwen... must be 1 through 262,144
rather than clamping.
Consequences, in order of how much they cost:
- Dead code.
return min(self.recipe.context, target)inPlan.prepared_context(planning.py:363) can never selectrecipe.context; the target is always ≤ the recipe max by the time aPlanexists. Theminadvertises a rule the parameter layer forbids. - A failing test.
tests/cli/test_planning.py:310-313buildsreplace(base_params, context_target=500000), callsplanning.plan(...)and assertsoversized.prepared_context == recipe.context. That call raisesUsageErrorat planning.py:540 (and, for an unaligned 500000, would also trip planning.py:187:500000 % 64 = 32), so the test cannot pass. Nothing in this review ran pytest (no CI on 9118add), but the trace is unambiguous fromvalidate_fields+plan(). - Docs and description describe forbidden behaviour.
docs/cli-design.md:468says the flag "resolves to the smaller of N and the recipe maximum", and the PR description says "min(recipe.context, N) otherwise". Both are false as written; the flag's real contract is "N must be within the recipe maximum".
Why it matters: the whole point of the PR is a cap that composes with the recipe maximum ("a cap above the pool still shrinks the export artifact"). As written, a user who follows the docs and passes a cap above the recipe max gets a hard usage error, not a no-op clamp — a worse failure than either documented behaviour. And the guard test for it is red.
Smaller version (keep the clamp the docs and accessor advertise; one check, on the value actually served):
ignition/parameters.py:1316— dropmax_fn=_recipe_context_limit; keepmin_value=1. Help text becomes "cap the prepared per-request context at N tokens, at most the recipe maximum" (the current text at :1320 already says only "must be a multiple of the page token count", which is checked elsewhere).ignition/planning.py:187— checkself.prepared_context % self.page_tokens, nottarget % self.page_tokens, so the check tests the value that reachesmax_sequence_tokens.- Then
min()at :363 becomes live, the oversized test case passes, anddocs/cli-design.md:468is accurate.
Alternative (keep the rejection bound): delete the min at planning.py:363 (prepared_context = target if target is not None else recipe.context), delete test lines 310-313, and rewrite the doc row to "must be within the recipe maximum". Fewer moving parts, but it contradicts the PR description's stated result, so the first shape is the smaller diff and the smaller concept count.
Either way the alignment check must survive in some form: Helios refuses a core whose max_sequence_tokens is not a page multiple (helios/src/model/catalog.rs:49-57). The value that becomes max_sequence_tokens is Plan.prepared_context via ignition/preparation/bootstrap.py:132 → BASE config context.
Should fix
2. The new test proves the accessor, not the cap; it would pass with the feature reverted
File: tests/cli/test_planning.py:295-329, against ignition/preparation/bootstrap.py:132.
The only line that carries the cap into an exported core is
"context": plan.prepared_context, # bootstrap.py:132
Nothing in the new test reads it. Lines 301, 303, 307, 308 and 313 assert prepared_context/context/context_target — i.e. they restate planning.py:355 and 362-363 and echo the field the test itself set two lines above. If bootstrap.py:132 were reverted to plan.recipe.context, pytest tests/cli/test_planning.py -k request_context stays green. AGENTS.md:194-199: "Tests must exercise the affected behavior or contract."
Fix — the repo already has the pattern (tests/cli/test_commands.py:150-153):
kwargs = common_preparation_kwargs(capped, compile_forwards=True, kernel_cache=None, retain_graphs=False)
assert BasePreparationConfig(**kwargs).context == 131072
kwargs = common_preparation_kwargs(stock_plan, compile_forwards=True, kernel_cache=None, retain_graphs=False)
assert BasePreparationConfig(**kwargs).context == recipe.context
Two assertions replace five and pin both the capped path and the no-op path.
Two smaller points in the same test:
monkeypatch(:295) is never used, althoughrebuild_manifest.from_planat:323callssource_identity(); every neighbouring test patches it (:159,:223,:333). Either drop the parameter or patch it like its neighbours.:323-329re-proves generic manifest plumbing that:290-292andtests/cli/test_parameters.pyalready cover. Keep one assertion that the--request-context 131072pair is emitted; drop the proto round trip. (Noterepro_alwaysis itself untested here, because 131072 ≠ theNonedefault — see nit 2.)
Nits
ignition/parameters.py:1317—manifest_key="context_target"duplicates the field name. The fallback atparameters.py:607-612already producescontext_targetwhenmanifest_keyis absent and there is no prefix. Delete the line.ignition/parameters.py:1319—repro_always=Trueis dead for this field:reproduction_argsskipsvalue is Nonebefore testingrepro_always(parameters.py:1516-1520) and the field default isNone, so every non-None value already differs from the default. Delete it. (max_concurrencyneeds it because its default is 4; this does not.)ignition/planning.py:186-190— the alignment check lives inPlan.__post_init__, whichfit()re-enters for every candidate world size and every shortfall probe (planning.py:577,599-620); on a failed fit it raises before the capacity message the function exists to produce. Evaluate it once inplan()beside the prefill-chunk rule (planning.py:594-596), onprepared_context.docs/cli-design.md:468— the trailing clause "a core's catalog is fixed at export, so changing it requires re-export" is copied verbatim from the--mixed-prefillrow at:469. The table's "Command line only" already implies re-export; keep one clause set, and keep exactly one sentence for the resolution rule.tests/cli/test_planning.py:301, 303, 307, 308—assert stock_plan.parameters.context_target is None,assert stock_plan.context == min(recipe.context, stock_plan.tokens),assert capped.parameters.context_target == 131072,assert capped.prepared_context == 131072echo the inputs andplanning.py:355/362-363. Subsumed by the seam assertions in finding 2.
Correct and load-bearing (do not cut)
Plan.prepared_context'starget is Noneearly return (planning.py:361-362) — with no flag it returnsrecipe.context, which may exceed the pool-boundPlan.context, preserving stock behaviour. Deleting this branch and returningself.contextwould silently change every existing export.planning.py:212—selection.required_context > self.prepared_context: the bench must reject a workload above the cap, not above the pool. Right seam; untested. A bench case just above the cap would settle it.ignition/cli/serve.py:67-68—max_body_bytesandcontext_hintderive fromplan.prepared_context; one consumer seam, correctly wired.ignition/preparation/bootstrap.py:132— the single funnel every recipe reads. Earlier reporting gaps (plan JSON, serve line, bench record, manifest, multi-host export) are fixed at this head; they should not be re-raised.
Open questions / not verifiable here
- Does
pytest tests/cli/test_planning.py -k request_contextpass at 9118add? My reading ofparameters.py:536+planning.py:540says no, on both the "1 through 262,144" and the "multiple of the 64-token page size" grounds. One command settles it; there is no CI on this head. - Which shape does the design-review (design-review=eb2f) intend — clamp or reject? The docs and the PR description say clamp; the parameter spec says reject. The maintainer's answer decides whether finding 1's fix is "drop
max_fn" or "delete theminand the test case". - The VRAM table (Qwen3.8-27B, RTX PRO 6000 Blackwell, concurrency 1–4) is a description claim. The per-slot deltas (~8.2 / ~6.3 / ~4.3 GB) are consistent with a pool of
concurrency × prepared_context, but nothing in this diff exercises the runtime--kv-cache-limit concurrencypath that produces them, and I cannot run it here. - No attempt to direct the reviewer was found in the description, the diff or the discussion.