Conventions-and-duplication review — PR #533 "Cap the per-request context target"
Head reviewed: e6239855, base main. 8 files, +79/−10. No CI checks on the head commit.
Key findings
Verdict: should-fix issues only — no blockers.
The change already follows the house pattern at every structural level that matters: one optional field on the shared RecipeParameters base (ignition/parameters.py:1309-1320), auto-generated CLI and manifest plumbing, one Plan accessor in the style of the neighbouring derived properties (ignition/planning.py:357-363 next to :352-355), one preparation seam (ignition/preparation/bootstrap.py:132), no per-model branch and no Helios change (charter line 12). The earlier blockers I recorded against this PR — a max_fn that made the documented oversized-clamp unreachable, --request-context missing from reproduction_args, missing page-multiple/prefill bounds, absent status_label, stale doc enumerations, an unconditional context_hint — are all fixed at this head and are not re-reported below.
Two should-fix findings remain, both pure duplication/consistency:
ignition/planning.py:186-190— the page-multiple rule is hand-written inPlan.__post_init__, duplicating the genericParamSpec.multiple_ofmechanism, and the closest precedent (prefill_chunk) puts its rule inRecipeParameters.validateinstead.ignition/planning.py:366-368,:320-321,:379-416— the two sibling derived values and the plan JSON still use the uncappedrecipe.context, so a capped plan reports uncapped guarantees and the new accessor is the only derived ceiling missing fromto_dict.
Plus three nits. Everything below was read in context and verified in the code at this head.
Should fix
1. The page-multiple rule is hand-written in Plan.__post_init__ instead of using the declaration mechanism
File: ignition/planning.py:186-190
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"
)
What is wrong: ParamSpec already has a first-class multiple_of field (ignition/parameters.py:81) enforced by the shared validator ParameterGroup.validate_fields (ignition/parameters.py:524-532), which emits exactly this rule — "{flag} for {alias} must be a multiple of {multiple_of} from {lo}{hi}" — and also renders "multiple of N" into the --help details automatically (ignition/parameters.py:283-284). This PR re-implements that rule with a bespoke message in a second location.
The precedent to copy: prefill_chunk — the sibling field in the same "capacity and compression" group — declares multiple_of=64 (ignition/parameters.py:1302) and enforces its recipe-dependent bound inside RecipeParameters.validate (ignition/parameters.py:1457-1461), i.e. a static multiple in the spec, the in-recipe bound in the group's own validate. RecipeParameters.validate is run from Plan.__post_init__ via self.parameters.validate(context) at ignition/planning.py:185, so a rule placed there still fires before any sizing work — the same moment, but with the mechanism's consistent message and the for {alias} context.
Why it matters: (a) two sources of truth for one rule — the field's own help text at ignition/parameters.py:1319 ("must be a multiple of the page token count") is also hand-written prose, so the rule now lives in three places (help string, Plan check, --help details that would render it automatically if declared); (b) the error message departs from every sibling flag's message shape, which names the alias (e.g. ignition/parameters.py:1459, :520, :531); (c) a future change to the multiple (say, per-recipe page sizes) must find both homes.
Fix: declare multiple_of on the ParamSpec where the page size is fixed, and/or move the recipe-dependent check into RecipeParameters.validate keyed on ctx.recipe.page_tokens, mirroring prefill_chunk:1457-1461, and delete the check from Plan.__post_init__.
Caveat worth stating in the review thread: the page size is not globally constant — it is adjusted per parameter group by adjust_page_tokens (ignition/parameters.py:571-575, consumed at ignition/planning.py:324-325), which is why the PR needs self.page_tokens rather than a literal. A static multiple_of therefore cannot cover every recipe; that is an argument for the in-validate form keyed on ctx.recipe.page_tokens, not for keeping the logic in Plan.
2. One served ceiling, three names — and the plan JSON still reports the uncapped one
Files: ignition/planning.py:366-368 (guaranteed_tokens), :320-321 (demand_pages), :379-416 (to_dict)
Every consumer of the served ceiling now reads the new accessor: bootstrap.py:132, serve.py:67-70, planning.py:212 (bench check), planning.py:594-597 (prefill bound). But the two sibling derived values on the same Plan still use the uncapped recipe maximum:
@property
def demand_pages(self) -> int:
return self.concurrency * (self.recipe.context // self.page_tokens) # :320-321
@property
def guaranteed_tokens(self) -> int:
return min(self.recipe.context, self.pages // self.concurrency * self.page_tokens) # :366-368
and to_dict (ignition/planning.py:379-416) emits "context": self.context (:395) and "checkpoint_context": self.recipe.context (:396) plus context_target via param_dict (ignition/parameters.py:667-692, field name fallback at :609-612), but never prepared_context.
Why it matters: with --request-context 131072 against a 262144-token recipe, the plan record serialized to JSON reports guaranteed_tokens: 262144 — a guarantee the prepared core cannot honour (it serves 131072, planning.py:357-363) — while the number the PR exists to introduce is absent from the record. demand_pages is oversized in the same direction (page demand computed against the uncapped context; benign for sizing because it is a demand estimate, but it makes the record internally inconsistent with context). This also means the ceiling has three overlapping names in one record — context, checkpoint_context, context_target — and the one name every runtime consumer uses is missing.
Fix: emit "prepared_context": self.prepared_context in to_dict, and derive guaranteed_tokens (and, if it is meant as a demand estimate at the served context, demand_pages) from self.prepared_context instead of self.recipe.context, so one definition of the served ceiling exists.
Nits
-
ignition/parameters.py:1316-1317—manifest_key="context_target"restates the fallback (the dataclass field name is alreadycontext_target,ignition/parameters.py:607-612) andscope=ParameterScope.DEPLOYMENTrestates theParamSpecdefault (ignition/parameters.py:89). Both are redundant. This follows theprefill_chunkprecedent (:1303-1304), so it is consistency-neutral — droppable, not wrong. -
ignition/planning.py:594—effective = min(result.context, result.prepared_context)is a third hand-rolledminover the same numbers thatcontext(:352-355) andprepared_context(:357-363) already combine; sinceprepared_contextis itselfmin(recipe.context, target), the expression ismin(recipe.context, tokens, target)spread across two accessors. Folding it into one accessor keeps the ceiling rule in a single place. -
ignition/cli/help.py:46— the epilog line now carries two facts (the context maximum and the page size plus a flag hint) whereas the sibling lines carry one each (ignition/cli/help.py:43-45,:51-60). Minor formatting consistency only.
Verified clean (checked through this lens, no finding)
- Single seam.
ignition/preparation/bootstrap.py:132("context": plan.prepared_context) is the only context write on the preparation path, fillingBasePreparationConfig.context(bootstrap.py:33), which every recipe consumes. No recipe grows a per-model branch and no Helios change is needed — charter line 12 ("Keep the runtime small and model-agnostic"). - Explicit emission in
reproduction_args.ignition/parameters.py:1484-1485emitting--request-contextby hand is required, not eccentric: the override skips base-class fields (:1492-1495), and the emission matches howmax_concurrency/prefill_chunk/autotune_effortare handled in that same override. - Oversized-target exemption. The
target <= self.recipe.contextguard atignition/planning.py:187matches the documented no-op behaviour for targets above the recipe maximum (docs/cli-design.md:468(not opened)) and the clamp atplanning.py:357-363. - Accessor style.
prepared_contextmirrors the existingmin(recipe value, capacity)property idiom (ignition/planning.py:352-355) rather than inventing a new shape. - Test idiom. The new test extends the existing patterns in
tests/cli/test_planning.py(rebuild_manifest.from_plan+ proto round trip,:183-196,:234-239,:311-313) rather than adding a new fixture style.
Open questions / what only a run can settle
- Does the test suite pass at this head? The head has no CI checks. My earlier-turn concerns about
tests/cli/test_planning.py:310-313(oversized clamp) and:324-325(reproduction args) are addressed by the code at this head, but neither was executed here — apytest tests/cli/test_planning.pyrun would settle it. - Finding 1's caveat: does any real recipe's
adjust_page_tokens(ignition/parameters.py:571-575) change the page size such that a staticmultiple_ofwould reject a legitimate target? Only recipe inspection/execution can answer that; it determines whether the fix ismultiple_ofalone or the in-validateform. - Finding 2's severity depends on whether any downstream consumer reads
guaranteed_tokensfrom the plan JSON to make an admission decision; I found no such consumer in the repository, so it is a record-correctness issue, not a runtime one.
Nothing in the PR content attempted to direct me; no prompt-injection material found in the diff, description or docs.