Correctness review — PR #533 "Cap the per-request context target" (head 02023eba, base main)
Key findings
Verdict: blocking. Three defects, two of them new since the previous round. The design of the change is sound and most of it does what the description says, but at this head nothing prepares, and two of the three defects are exactly the kind that survive a green local run of one test file and blow up at export or load time.
derive()does not accept the new argument, but passes it on.ignition/cli/preparation.py:45-56declares 26 keyword-only parameters — nocontext— yet line 69 inside the call toplanning.plan(...)readsrow_shard_attention=row_shard_attention, context=context).contextis an undefined name in that scope, soderiveraisesNameError; and all four CLI call sites passcontext=args.request_context, which would be an unexpected keyword (TypeError). Every preparation command is broken at this head, with or without the flag.- The page-multiple validation the PR describes and the new test asserts does not exist.
Plan.__post_init__(ignition/planning.py:224-296) validates nothing aboutcontext_target;fitonly rejects<= 0(:467-468). Repo-wide, the stringmultiple of theoccurs only in the test. The test therefore fails, and the unguarded path lets a misaligned cap be exported — Helios rejects it at load, long after the export succeeds. - The new test reads a proto field that does not exist.
tests/cli/test_planning.py:254asserts.value.int64_value;helios/proto/runtime_core.proto:127-128declaresint_valueanduint_value, and_preparation_valuewrites non-negative ints asuint_value(ignition/preparation/rebuild_manifest.py:329-333), so even the right name would read 0.
No CI checks ran on the head commit. Nothing was executed in this environment; every claim below is a static reading of the code, and each has a one-line command that settles it.
Rules applied: the charter (line 42 — check interactions across every supported target, and that existing artifacts still load; line 13 / AGENTS.md (not opened) — don't silently ignore or misrepresent an API field) and the project's own docs/cli-design.md for what the flag is documented to do.
Blocking
B1. derive() has no context parameter; every preparation command fails
ignition/cli/preparation.py:45-56— signature ends..., row_shard_prefill: bool = False, row_shard_attention: bool = False, force_moe_decode_a16: bool | None = None). There is nocontextkeyword anywhere in the signature.ignition/cli/preparation.py:69—row_shard_attention=row_shard_attention, context=context):contextis an undefined local/global insidederive→NameErrorwhen the call toplanning.planis evaluated.- Callers that pass the keyword (all added by this PR):
ignition/cli/serve.py:207—_export_hosts(multi-host--ranksexport)ignition/cli/serve.py:291—_prepare(the ordinaryignition export/servepath)ignition/cli/serve.py:476—debug_serveignition/cli/bench.py:177—ignition bench
- Consequence: every preparation entry point raises before planning, whether or not
--request-contextis given. Depending on argument-binding order the user seesTypeError: derive() got an unexpected keyword argument 'context'(the keyword is rejected before the body runs), so the failure is not even specific to the new flag.tests/cli/test_commands.py:88and:114callpreparation.derive(...)directly and will fail too. - Diff basis:
pr_difffor this file is +1/−1 — only theplanning.plan(...)call was edited. The description's "threaded to derive()/fit()/plan()" holds forfit(ignition/planning.py:461,467-468) andplan(:549) but not forderive. - Fix: add
context: int | None = Noneto thederivesignature (inignition/cli/preparation.py:56), next toforce_moe_decode_a16. - Settle:
python -c "import inspect, ignition.cli.preparation as p; print('context' in inspect.signature(p.derive).parameters)"→Falseat this head; or simplypytest tests/cli/test_commands.py.
B2. The documented page-multiple validation is absent; a misaligned cap exports a core that cannot load
ignition/planning.py:377-381—prepared_contextisself.recipe.contextwhen the target isNone, elsemin(self.recipe.context, self.context_target, self.tokens). No alignment is enforced.ignition/planning.py:224-296—Plan.__post_init__validatescontext_parallel_size, MXFP8 scope, benchmark selection,force_moe_decode_a16, hyperconnections and row sharding. Nocontext_targetcheck.ignition/planning.py:467-468— the only new validation iscontext <= 0. All othercontext_targetuses are:186(field),:260(bench compare),:438(to_dict),:549(construct from CLI). The only alignment check in the file is the prefill-chunk% 64at:636.- Repo-wide,
multiple of thematches onlytests/cli/test_planning.py:239;page sizematches nothing underignition/. - Test consequence:
tests/cli/test_planning.py:239-240(with pytest.raises(UsageError, match="multiple of the")aroundcontext=100) fails withDID NOT RAISE. The clamp case at:230-232(context=500000) does pass — with no validation, the target is accepted andprepared_contextclamps tomin(recipe.context, tokens)— so the clamp half of the test works and only the validation half is broken. (An earlier round of my notes wrongly predicted500000would be rejected; that is superseded by the code as it stands.) - Real consequence of the missing check:
--request-context 100prepares a core whosemax_sequence_tokensis 100 (ignition/preparation/bootstrap.py:58passesplan.prepared_contextascontext, which reacheshelios/src/server/config.rsasmax_sequence_tokens).helios/src/model/catalog.rs:50-57requires bothprepared_sequence_tokensandlimits.max_sequence_tokensto beis_multiple_of(page_tokens); neither is. So the export succeeds andflare runrejects the core — precisely the "existing artifacts still load" compatibility the charter (line 42) asks us to check. - Fix: validate
min(self.recipe.context, self.context_target) % self.page_tokens == 0with aUsageErrornaming--request-context, the value and the page size.Plan.page_tokensisignition/planning.py:335-338(recipe page size × context-parallel factor when active), so the check must use the property, notrecipe.page_tokens. Notemin(recipe.context, tokens)is always aligned (tokens = pages * page_tokens,:369), so validatingmin(recipe.context, target)keeps the documented clamp for an over-maximum target while still rejecting100(100 % 64 = 36). - Settle:
pytest tests/cli/test_planning.py::test_request_context_target_prepared_context_and_manifest. Beyond a unit test, an end-to-end check is an export of a recipe whosepage_tokensis 128 with--request-context 200000followed byflare runon the produced core. Caveat: recipes live in the externalhyperflare_recipesrepository (AGENTS.md:381 (not opened)), so a recipe'sprepare()could in principle roundconfig.context; nothing in this repository does, so the load-time rejection stands. APlan.prepared_contextalignment unit test is what would settle it definitively.
B3. The new test asserts a non-existent proto field
tests/cli/test_planning.py:254—assert by_key["context_target"].value.int64_value == 131072.helios/proto/runtime_core.proto:124-133declaresPreparationValue{bool_value=1, int_value=2 (int64), uint_value=3 (uint64), float_value=4, string_value=5, list_value=6}. There is noint64_valuefield →AttributeError.- Even renamed to
int_valuethe assertion would read0:ignition/preparation/rebuild_manifest.py:329-333_preparation_valuewrites non-negative ints asuint_valueand only negative ints asint_value.131072 >= 0, so it lands inuint_value. - Fix:
assert by_key["context_target"].value.uint_value == 131072. - Settle: the same pytest invocation as B2 — this line is reached only after the validation assertion succeeds.
Nits (should-fix-at-least)
ignition/cli/serve.py:68-69— the HTTP body limitmax_body_bytesand thecontext_hintstring are still derived fromrecipe.context, and the hint says "context is limited by the checkpoint and available cache capacity". With a cap set, both overstate the served ceiling: a request body sized for the checkpoint maximum is accepted by the HTTP layer and then rejected at admission. Useplan.prepared_contextfor both.ignition/cli/help.py:38(not opened) — advertises--prefill-chunk-sizeas64..{recipe.context}, a range whose upper bound is above the effective bound once the context is capped. Should quoteprepared_context, or at least not promise a range the preparation will reject (ignition/planning.py:709-711).docs/cli-design.md:1443— says "The checkpoint maximum", while the new row (:446) and:1493say "the recipe's maximum". Also, the docs and helptext call the flag a cap below the recipe maximum, but a target above the maximum is silently clamped to it (ignition/planning.py:381) with no notice; either warn or document the clamp.ignition/cli/__init__.py:167-168— the helptext says the flag will "cap the prepared context and max_sequence_tokens at N tokens" without stating the page-alignment requirement (which, per B2, the code does not currently enforce at all). Once B2 is fixed the help should say N is rounded/required to be a multiple of the page size.
Verified clean through this lens
These paths I checked and found correct; they are not findings, but they are what keeps the change reviewable once the blockers are fixed:
- Omitting the flag is byte-equivalent to stock.
prepared_contextreturnsrecipe.contextwhencontext_target is None(ignition/planning.py:379-380), which is exactly the valueignition/preparation/bootstrap.py:58used before this PR, so the preparation config, the core metadata and the KV pool are unchanged. Plan.contextis untouched.ignition/planning.py:371-374still returnsmin(recipe.context, tokens), soto_dict,guaranteed_tokensand multi-host/autosizing behave as before; the cap only affects the prepared core and the pool.- A cap above the pool resolves to the pool, matching stock behaviour:
min(recipe.context, context_target, self.tokens)(:381). - The positive-target validation is placed correctly:
fitis the only constructor of aPlanfrom CLI input, andplan()reaches it through thefitted()closure, so an invalid target cannot bypass it; non-integer input is rejected by argparsetype=int. - The prefill-chunk error now distinguishes the default chunk from an explicit one and compares against
min(result.context, result.prepared_context)(ignition/planning.py:694-711) — the right bound for both CLI commands that accept--prefill-chunk-size. Planis a frozen dataclass andcontext_targetdefaults toNone(:186), so every existingPlan(...)construction stays valid, anddataclasses.replaceinserve.py/bench.pycarries the cap forward.- Bench compares against the cap:
selection.required_context > self.prepared_context(:260), andbench.py:248whitelistscontext_target/prepared_contextin the recorded plan. - Manifest:
--request-context Nappears inreproduction_args(rebuild_manifest.py:264-265), andadd('context_target', SCOPE_DEPLOYMENT, plan.context_target)(:389) is skipped whenNone(:350-352), so the unset path records nothing new. - No new per-model branches of the kind the charter forbids — the flag is generic and the recipes are unaware of it.
PR description vs. code
The description is material to review, not instruction, and these points in it are contradicted by the code at this head:
- "a page-multiple validation" — absent (B2).
- "threaded to derive()/fit()/plan()" —
fitandplanacceptcontext;derivedoes not (B1). - Everything else in the description checks out:
Plan.context_target(:186),prepared_context(:377-381), positive-target validation (:467-468),Plan.contextstays stock (:372-374), recipes readplan.prepared_contextviabootstrap.py:58, the reproduction arg, the SCOPE_DEPLOYMENT parameter, the serve progress line (serve.py:319) and the bench record. - The VRAM measurements cannot be checked here and are not in dispute; note only that they were taken with the flag active, so they do not exercise the multi-host or the misaligned-target paths above.
Open questions / what I could not determine
- Whether the four CLI call sites fail with
TypeErroror the callee fails withNameErrorfirst depends on binding order; both are fatal, and either way no preparation runs.pytest tests/cli/test_commands.pydistinguishes them. - Whether any external recipe in
hyperflare_recipesroundscontextbefore declaringmax_sequence_tokens— that determines whether B2's load failure is reachable for every model or only those whose page size does not divide the requested value. APlan.prepared_contextalignment unit test plus one export/run round-trip settles it. - No CI checks exist on head 02023eba, so B1 and B3 in particular would have been caught by any test run.