Subtraction, Simplicity & Conventions review — PR #533, head 503a438
Key findings
The architecture of this PR is lean and idiomatic: one declarative field (context_target), one accessor (Plan.prepared_context), one seam (ignition/preparation/bootstrap.py:132), and one genuine subtraction done right (the long inline flag enumerations in docs/cli-design.md and docs/preparation-development.md replaced by a pointer to RecipeParameters). What the diff adds on top of that is redundancy: the same min(target, ceiling) clamp is re-derived in six places, and two of those derivations are removable outright with no behaviour change on any shipped recipe.
Ranked, high value first:
- S1 — dead conjunct in the alignment gate (
ignition/planning.py:198-200).target <= self.declared_contextcan never change the outcome; gate onself.prepared_context % self.page_tokensinstead. Pure deletion that also collapses the twin alignment rules (help vs code vs docs) at their source. - S2 — make
Plan.contextcap-aware (ignition/planning.py:367-370) and delete the twomin(context, prepared_context)re-derivations at:222and:626, plus the extra"prepared_context"key at:409. - S3 — delete the third clamp in
RecipeParameters.status_parts(ignition/parameters.py:1606-1607), which uses a different base (context.recipe.context) than the plan report; and un-branchcontext_hint(ignition/cli/serve.py:73-74). - S4 — revert the help-epilog over-stuffing (
ignition/cli/help.py:46) and drop--request-contextfrom the hand-maintained flag list indocs/direct-execution.md:54-56— the very enumeration this PR deletes elsewhere. - S5 — rename
context_target→request_contextso field, plan JSON, manifest key and flag agree (5 source lines, 6 test lines — mechanical).
None of these are correctness bugs; they are removable code and removable second rules. Concrete citations and replacements below.
S1 — Delete the dead target <= self.declared_context conjunct (highest value)
ignition/planning.py:197-200, verbatim:
_validate_declared_context(self.recipe, self.checkpoint, self.declared_context)
target = self.parameters.context_target
if target is not None and target <= self.declared_context and target % self.page_tokens:
raise UsageError(f"--request-context {target:,} for {self.recipe.name} is not a multiple of the {self.page_tokens:,}-token page size")
The middle conjunct is dead. _validate_declared_context on the preceding line already guarantees declared % recipe.page_tokens == 0 (ignition/planning.py:432-441):
def _validate_declared_context(recipe: Recipe, checkpoint: Checkpoint, declared: int) -> None:
if type(declared) is not int or not 64 <= declared < 2**31 or declared % 64:
raise UsageError(
f"{checkpoint.alias} declared context ({declared!r}) must be a 64-aligned positive int32"
)
if declared % recipe.page_tokens:
raise UsageError(
f"{checkpoint.alias} context ({declared:,}) must be a multiple of"
f" the recipe page size ({recipe.page_tokens})"
)
and prepared_context clamps an oversized target down to declared (ignition/planning.py:372-375):
@property
def prepared_context(self) -> int:
"""The context the prepared core serves per request (``--request-context``); the declared context when no target is set."""
return min(self.declared_context, self.parameters.context_target or self.declared_context)
Replace the three added lines with:
if self.prepared_context % self.page_tokens:
raise UsageError(f"--request-context {self.prepared_context:,} for {self.recipe.name} is not a multiple of the {self.page_tokens:,}-token page size")
Why this is behaviour-preserving and strictly smaller:
- In-range target:
prepared_context == target, identical check and identical message. - Oversized target:
prepared_context == declared, which_validate_declared_contextalready proved aligned, so500000stays an accepted no-op —tests/cli/test_planning.py:308-310still passes;100still raises on"multiple of the"—:319-321still passes. - The only divergence is a recipe where
adjust_page_tokensmakesPlan.page_tokens != recipe.page_tokens; per the dossier no shipped recipe overrides it (the only definition is the base default inhyperflare_recipes/parameters.py(not opened)).
What it buys: one alignment rule instead of two. Today help says the value "must be a multiple of the page size" unconditionally (ignition/parameters.py:1351), the code enforces it only when in range (:199), and docs/cli-design.md:458 asserts both in one self-contradictory sentence. Gating on the effective value removes the contradiction instead of rewording three surfaces. It also deletes the "values above the recipe maximum are accepted as no-ops" branch — exactly the kind of second code path AGENTS.md:188-193 warns against ("Do not add … speculative compatibility, fallback layers, or configuration switches without a concrete requirement").
S2 — Make Plan.context cap-aware; delete two min(...) re-derivations and one printed key
ignition/planning.py:367-370, verbatim:
@property
def context(self) -> int:
"""The longest sequence one request may reach."""
return min(self.declared_context, self.tokens)
The docstring already claims the value the cap changes, but the property ignores the cap, so every caller re-derives it. The two places that do:
ignition/planning.py:222:
if selection.required_context > min(self.context, self.prepared_context):
raise UsageError("benchmark workload and output allowance exceed the prepared context")
ignition/planning.py:624-629:
result = attempt(params, flags=explicit_flags)
if result is not None:
effective = min(result.context, result.prepared_context)
if params.prefill_chunk > effective:
raise UsageError(f"--prefill-chunk-size {params.prefill_chunk:,} exceeds the {effective:,}-token context"
" this plan allows")
return result
Redefine the property as return min(self.prepared_context, self.tokens); both call sites collapse to self.context and result.context and the local effective variable disappears. Also prefer an explicit None check over the or idiom at :375 (context_target or self.declared_context silently treats a target of 0 as unset — belt-and-braces even though min_value=1 at ignition/parameters.py:1350 currently prevents it).
Safety: Plan.context is read only inside ignition/planning.py (:222, :407, :626) and asserted in tests/cli/test_planning.py:471,474,530, all with no cap set, where prepared_context == declared_context. ignition/bench/runner.py:388 and ignition/direct/* read Layout.context, a different object — unaffected.
Consequence for to_dict (ignition/planning.py:407-409):
"context": self.context,
"checkpoint_context": self.declared_context,
"prepared_context": self.prepared_context,
Once context reports the effective value, the third key is a duplicate of the first, so the PR's new printed key can be dropped and the diff's to_dict change goes to zero lines. (If the maintainer prefers three distinct keys, keep them — but then context should stop being documented as "the longest sequence one request may reach".) demand_pages at :330-331, guaranteed_tokens at :380 and the serve body sizing at ignition/cli/serve.py:71 all keep using prepared_context unchanged.
S3 — Delete the third clamp in status_parts, and un-branch context_hint
ignition/parameters.py:1597-1608, verbatim:
for dc_field, spec in self._param_fields():
if spec.status_label is None or not _is_enabled(self, spec, ctx):
continue
label = spec.status_label(getattr(self, dc_field.name))
if label:
parts.append(label)
if self.context_target is not None:
parts.append(f"request context {min(self.context_target, context.recipe.context):,} tokens")
parts.append(f"compile workers {self.compile_workers or 'auto'} per host")
This is a third copy of the clamp, computed from a different base: context.recipe.context rather than the adjust_context-aware declared_context the plan uses. Under any recipe adjust_context hook (e.g. ToyContextScaleGroup, tests/cli/test_planning.py:405-421) the help/status line and the plan report print different numbers for the same plan.
Per AGENTS.md:456-460 ("Configuration"): a setting that only experiments need is "carried through the plan into the recipe's PreparationConfig, so the plan, its printed report, and its recorded measurements describe what was prepared" — and the plan report now does carry prepared_context (ignition/planning.py:409), so a bespoke second description in status_parts is redundant.
Delete the two lines. If a fragment is still wanted, express it as status_label on the field (ParamSpec.status_label, ignition/parameters.py:105, consumed at :707-720 — the generic mechanism the loop directly above already uses), not as a new hardcoded branch in RecipeParameters.status_parts.
Same family, ignition/cli/serve.py:73-74, verbatim:
"context_hint": ("context is limited by the checkpoint and cache capacity"
+ (", and the --request-context cap" if plan.prepared_context < plan.declared_context else "")),
Replace with one unconditional string — "context is limited by the checkpoint, cache capacity, and any --request-context cap" — dropping the branch and the re-derivation of prepared_context < declared_context inside a hint sentence. Both items are test-safe: search_code for context_hint|request context .* tokens|context is limited under tests/ returns no matches.
S4 — Revert the help-epilog over-stuffing and the re-listed doc flag list
ignition/cli/help.py:46, verbatim (now a ~200-character line):
f" Context: {recipe.declared_context(checkpoint):,} tokens max (page size: {recipe.page_tokens}); --request-context can lower this (a cap below --prefill-chunk-size is rejected)",
The page-multiple rule is already in the flag's own help (ignition/parameters.py:1351), and the chunk interaction is a plan-time UsageError (ignition/planning.py:626-629), not help-text material. Keep the original short line and let the option help carry the cap:
f" Context: {recipe.declared_context(checkpoint):,} tokens max (page size: {recipe.page_tokens})",
Related churn, docs/direct-execution.md:53-57, verbatim:
Every host needs the same Flare, Ignition and FlashInfer sources, as for any
multi-host preparation. Preparation flags (`--max-concurrency`,
`--prefill-chunk-size`, `--request-context`, `--mtp-draft-tokens`,
`--no-mtp-adaptive-verification`, `--no-mtp`, `--no-context-parallel`,
`--no-stream-overlap`, `--no-compile`) apply as they do without `--direct`; direct execution runs what they prepared.
--request-context was inserted into a hand-maintained enumeration in a file whose only claim is "applies as it does without --direct, like every other preparation flag" — which is true of the flag by construction and needs no edit. This is the same enumeration pattern the PR correctly deleted from docs/cli-design.md:446-453 and docs/preparation-development.md:14-25; adding to it here re-creates the maintenance burden. Revert the three-line docs hunk (net −3/+3 becomes 0) or replace the list with a pointer to the flag table.
S5 — context_target → request_context (naming, minor)
ignition/parameters.py:1344-1352, verbatim:
context_target: int | None = param(
None,
flag="--request-context",
group="capacity and compression",
metavar="N",
value_type=int,
min_value=1,
help="cap the prepared per-request context at N tokens; must be a multiple of the page size",
)
There is no manifest_key, so the manifest and reproduction metadata record context_target (fallback at ignition/parameters.py:620-626; pinned by tests/cli/test_planning.py:329), a name that appears in no CLI surface and no docs row. Rename the field to request_context and flag, plan JSON key, manifest key and reproduction_args (ignition/parameters.py:1529-1530) all agree with no other change. Mechanical: context_target occurs in exactly 5 source lines (ignition/parameters.py:1344,1529,1530,1606, ignition/planning.py:198,375) and 6 test lines (tests/cli/test_planning.py:304,308,317,321,329).
(A default_label for the flag — currently generated help renders default: none — is the Correctness lens's item; noted there, not duplicated here.)
Explicitly lean — keep as is
- The single
Plan.prepared_contextaccessor (ignition/planning.py:372-375) and the single bootstrap seamignition/preparation/bootstrap.py:132("context": plan.prepared_context): one seam, no per-recipe branch, no Helios change. Correct shape. - The cap-aware bench guard reusing the same accessor (
ignition/planning.py:222) and the cap-awaredemand_pages(:330-331) — good, once S2 removes the redundantmin. - The docs paragraphs that replaced inline flag enumerations with a pointer to
RecipeParameters(docs/cli-design.md:446-453,docs/preparation-development.md:14-25) — this is the subtraction this PR does right. RecipeParameters.reproduction_argsemitting the flag only when set (ignition/parameters.py:1529-1530) — minimal and correct;repro_alwayswas rightly not set.- The single added test
tests/cli/test_planning.py:298-329is compact and covers resolution, the seam, both rejections and the manifest — no bloat to trim.
Conventions check
No structural AGENTS.md violation: no environment variable, no new framework or extension point, one flag with one home (--request-context as an advanced flag carried into PreparationConfig, per AGENTS.md:456-460). The only tension is S1's extra branch and S3's second description of a value the plan already owns — both addressed above.
Open questions
- Does the maintainer prefer three printed JSON keys (
context,checkpoint_context,prepared_context) or one effectivecontext? S2's deletion of the new key depends on that choice, not on correctness. - Is
context_targetintentionally distinguishable from the flag name in the manifest (S5 assumes not)? - Whether external
hyperflare_recipesprepare()implementations re-roundconfig.context— unverifiable in this tree; if one does, S1's clamp-derived gate is still correct because it validates the value actually passed atignition/preparation/bootstrap.py:132. - No execution evidence at any head appears in the thread; all statements above are a static read of
503a438.