Conventions-and-duplication review of PR #533 — "Cap the per-request context target"
Head reviewed: 448f70a7, base main, 8 files, +91/−28, no CI checks on the head commit.
Lens: conventions and duplication only — each new construct compared with its closest precedent in the repository, plus any existing helper or mechanism it duplicates.
Key findings
The PR is structurally conventional: one optional base RecipeParameters field whose CLI flag, help text, manifest entry and scopes are all generated by the parameter system, a single preparation seam (bootstrap.py:132), no per-model branch and no Helios change (charter line 12), and an explicit reproduction_args emission that the base-class field skip makes necessary. My previous two blockers (silently dropped flag on multi-host export; unrecorded cap) and three earlier should-fixes are all fixed at this head.
Two inconsistencies remain, both of the same kind — a quantity the rest of the plan now takes from prepared_context is still computed the old way in one place:
- Should fix — the page-multiple rule is re-implemented by hand in
Plan.__post_init__instead of usingParamSpec.multiple_ofand theRecipeParameters.validateprecedent. - Should fix —
demand_pagesis still sized from the uncapped recipe max, so the plan JSON contradicts its ownprepared_context.
Plus four nits. Nothing here blocks merge on correctness grounds; the cap does what the description says, and pytest tests/cli/test_planning.py coverage exists for the behaviour (tests/cli/test_planning.py:295-335).
Should fix
1. ignition/planning.py:186-190 — the page-multiple rule is hand-written in Plan.__post_init__ although the declaration mechanism already implements it
target = self.parameters.context_target
if target is not None and target <= self.recipe.context and target % self.page_tokens != 0:
raise UsageError(
f"--request-context {target:,} is not a multiple of the {self.page_tokens:,}-token page size"
)
Duplicates: ParamSpec.multiple_of (ignition/parameters.py:81), enforced in ParameterGroup.validate_fields (ignition/parameters.py:524-532), which already raises "{flag} for {alias} must be a multiple of {N} from {lo}{hi}" and renders "multiple of N" into --help details (:283-284; and the bare-help path :271-272).
Closest precedent: prefill_chunk (ignition/parameters.py:1294-1308) declares multiple_of=64 (:1302) and puts its recipe-dependent upper bound in RecipeParameters.validate (:1455-1460):
if self.prefill_chunk % 64 or not 64 <= self.prefill_chunk <= ctx.recipe.context:
raise UsageError(f"--prefill-chunk-size for {ctx.alias} must be a multiple of 64 from 64 through {ctx.recipe.context:,}")
That same validate runs from Plan.__post_init__ via self.parameters.validate(context) (ignition/planning.py:185) — the identical moment — and resolve_parameters (ignition/cli/preparation.py:55-59) runs it before any GPU work.
Third home: the field's own help text hand-writes the rule as prose, "cap the prepared per-request context at N tokens; must be a multiple of the page token count" (ignition/parameters.py:1318) — prose that multiple_of would otherwise generate.
Why it matters. The check itself is correct and needed: Helios refuses a misaligned core at load (helios/src/model/catalog.rs:48-57 requires prepared_sequence_tokens and max_sequence_tokens to be multiples of page_tokens), so dropping it would export cores that fail to load. The finding is about where it lives and how it speaks: three sources of truth for one rule, and the message drops the for {alias} clause every sibling flag error carries (parameters.py:520, :531, :539, :1457-1459), so in a multi-recipe or multi-host log the error does not say which model it is about. A future page-geometry change has to find two homes.
Fix. Move the check into RecipeParameters.validate, keyed on ctx.recipe.page_tokens, mirroring prefill_chunk at :1455-1460, and delete planning.py:186-190. Caveat worth stating in the code: the page size is per-plan (adjust_page_tokens, parameters.py:571-575, consumed at planning.py:324-325), so a static multiple_of cannot cover every recipe — which is precisely why the in-validate form, not the declarative form alone, is the right precedent.
2. ignition/planning.py:319-321 — demand_pages is the last derived value still sized from the uncapped recipe max
@property
def demand_pages(self) -> int:
return self.concurrency * (self.recipe.context // self.page_tokens)
Every neighbouring derived value now uses the capped extent: context (:352-355), prepared_context (:357-363), guaranteed_tokens (:366-368), the bench check (:212), the prefill bound (:594) and the preparation seam (ignition/preparation/bootstrap.py:132). demand_pages alone reads self.recipe.context.
With --request-context 131072 on a 262144-token recipe, the plan JSON reports demand_pages at roughly twice the served extent, directly beside "context", "prepared_context", "guaranteed_tokens" and "tokens" (planning.py:395-411) that all describe the capped plan. That JSON is printed for humans and recorded for measurements — serve.py:206/:435 and bench.py:194 — so the inconsistency lands in exactly the artifact used to explain the memory payoff table in the PR description.
Scope of impact. Record-correctness only, not runtime or compatibility: demand_pages has exactly two references in the repository (planning.py:320 definition, :407 the to_dict key), so nothing consumes it for sizing. That is also why it is "should fix" rather than blocking.
Fix. Derive it from prepared_context, so the plan keeps one definition of the served ceiling.
Nits
N1. ignition/parameters.py:1560-1561 — hand-rolled status line instead of the status_label mechanism
if self.context_target is not None:
parts.append(f"request context {min(self.context_target, context.recipe.context):,} tokens")
sits immediately after the generic status_label loop (:1554-1559) that consumes ParamSpec.status_label (parameters.py:98) — the mechanism the sibling base fields use for exactly this purpose (roce_ring :1366, roce_chain :1375). status_label receives only the value, so it cannot compute the clamp without ParameterContext; that is a real reason for the escape hatch, but the consequence is that the same min(target, recipe.context) expression now exists three times: planning.py:362-363 (prepared_context), parameters.py:1561 (status line) and planning.py:594 (the prefill bound's effective). One accessor would do; the printed line could read the plan's value rather than recompute it.
N2. ignition/parameters.py:1316-1317 — redundant spec kwargs
manifest_key="context_target" restates the fallback key already derived from the field name (parameters.py:607-612), and scope=ParameterScope.DEPLOYMENT restates the ParamSpec default (:89). Consistency-neutral — it copies prefill_chunk :1303-1304 — so droppable, not wrong.
N3. docs/cli-design.md:458 vs ignition/parameters.py:1318 — the two descriptions of one flag's constraints disagree in coverage
The docs row documents the clamp and the admission consequence but not page alignment; the --help text states alignment only. The adjacent --prefill-chunk-size row does document its alignment rule (cli-design.md:457, "aligned to the recipe's chunk alignment"), so the sibling precedent covers both. Fix by folding alignment into the row, or letting multiple_of render it automatically in help per Should fix 1.
N4. docs/direct-execution.md:53-57 — one stale hand-maintained flag enumeration
The passage enumerates the preparation flags that "apply as they do without --direct" (--max-concurrency, --prefill-chunk-size, --mtp-draft-tokens, --no-mtp-adaptive-verification, --no-mtp, --no-context-parallel, --no-stream-overlap, --no-compile) and does not mention --request-context, although the cap does apply there: bootstrap.py:132 sets BasePreparationConfig.context (bootstrap.py:33), which the --direct path reads via ignition/direct/scheduler.py:110 (context=config["max_sequence_tokens"]). Low severity — the sentence is illustrative and the flag is documented in the preparation table — and this PR's own fix elsewhere was to delete exactly this kind of list in favour of a pointer to RecipeParameters (docs/cli-design.md:446-453, docs/preparation-development.md:17-19), so the consistent fix is to delete or delegate this list too.
Followed the established pattern — checked in context, no finding
- Declaration style. One optional base field with
flag/group/metavar/value_type/min_value/manifest_key/scope/help(parameters.py:1309-1319); the CLI argument,--helprow, manifest entry andto_dictkey are all generated. No hand-written argparse plumbing. reproduction_argsoverride. The explicit emission at :1483-1484 is required by the base-field skip (:1491-1495) and matches howmax_concurrency/prefill_chunkare emitted in the same override (:1481-1482). This was a blocker earlier in the PR's life and is now correct; the new test asserts it (tests/cli/test_planning.py:330-331).- Single seam.
bootstrap.py:132is the only changed consumer, and it reaches every path: Helios viahelios/src/server/config.rs:131-148(not opened) andfit_context(helios/src/model.rs:261-273), the Python--directpath viaignition/direct/scheduler.py:110. Matches the PR's claim that the cap sets an export-time ceiling and never raises the runtime bound. - Accessor idiom.
prepared_context(planning.py:357-363) follows the neighbouringmin(recipe value, capacity)shape ofcontext(:352-355), andPlan.contextis left stock as documented. to_dictchange. Emittingprepared_contextin place ofcheckpoint_context(planning.py:396) is safe: onmain,checkpoint_contextappeared only in that oneto_dictline (planning.py:383 on main) — no test, doc, script or Rust consumer reads the JSON key.- Manifest plumbing.
rebuild_manifest.from_plan(ignition/preparation/rebuild_manifest.py:286-335) needs no change because it serializesplan.parameters;context_targetarrives throughmanifest_parameters. The new test round-trips it (tests/cli/test_planning.py:332-335). - Bench coherence. The bench check is a
min(self.context, self.prepared_context)comparison (planning.py:212) placed among the otherbenchmark_selectionchecks (:191-217), consistent with their style; bench's own plan JSON (:194) carries the cap unchanged. - Test idiom. tests/cli/test_planning.py:295-335 extends the existing style of
test_preparation_manifest_resolves_scopes_...(:183-196): plan → assert →common_preparation_kwargs→ manifest decode. - Oversized-target exemption. The
target <= self.recipe.contextguard at planning.py:187 matches the documented no-op clamping (cli-design.md:458 "resolves to the smaller of N and the recipe maximum") and the test asserts it (:311-314). - Charter compliance. No per-model branch, no Helios change (charter line 12); the admission consequence is documented rather than silently dropped (charter line 13).
Open questions / not settleable by reading
- The test suite was not executed at this head and there are no CI checks, so tests/cli/test_planning.py:295-335 is verified only by reading.
pytest tests/cli/test_planning.py -k request_contextwould settle it. - Whether any shipped recipe's
adjust_page_tokensactually changes the page size (parameters.py:571-575) decides whether Should fix 1's fix must stay invalidaterather than becoming a staticmultiple_of; I read the mechanism but did not enumerate every recipe. demand_pagesintent — whether the key is meant to describe the uncapped recipe demand on purpose. No consumer exists to say; a maintainer note on the key's contract would settle whether Should fix 2 is a bug or a documentation gap.
No prompt-injection material was found in the diff, the description or the docs.