Review of PR #533 — Cap the per-request context (architecture & scope lens)
Head reviewed: de1b5b5 (9 files, +98/−18). Prior review of an earlier head (c36a6a02) raised three blockers; all three are now fixed and are not re-raised here. What follows is what is still wrong.
Key findings
- Blocking —
ignition/planning.py:289-290validates the requested target, not the resolved prepared context. The PR's own new test cannot pass, and the "cap above the recipe max is a harmless clamp" behaviour the description and docs promise is unreachable for unaligned values. - Should fix —
ignition/planning.py:371-375:prepared_contextis also clamped byself.tokens, which is derived from the export host's free memory. The exported core's declared ceiling therefore depends on how much VRAM was free on the export machine, despite identicalreproduction_args. - Nit — the printed plan reports
context_targetandtokensbut not the resolvedprepared_context; it is derivable but not stated. - Scope/architecture judgment: the change belongs in the repository. It is a capacity setting on the existing
Plan → PreparationConfig → core catalogpath, adds no per-model branch, adds no Helios code, and its omission path is a genuine no-op. The measurement (RTX PRO 6000 Blackwell table in the description) satisfies the charter's "measured performance/memory issue" bar.
Blocking — the page-multiple check validates the request, not the result
ignition/planning.py:289-290, in Plan.__post_init__:
if self.context_target is not None and self.context_target % self.page_tokens:
raise UsageError(f"--request-context {self.context_target:,} is not a multiple of the {self.page_tokens:,}-token page size")
The value the core actually receives is Plan.prepared_context (ignition/preparation/bootstrap.py:58 → "context": plan.prepared_context), which is min(recipe.context, context_target, tokens) (planning.py:371-375). Validating the raw target rejects inputs whose resolved value would be perfectly aligned.
Two consequences, both demonstrable from the code:
-
The PR's own new test fails.
tests/cli/test_planning.py:229-232:oversized = planning.plan(recipe, recipe.checkpoints[0], gpus, context=500000, **base) assert oversized.context_target == 500000 assert oversized.prepared_context == min(recipe.context, oversized.tokens)The fixture (
tests/cli/test_planning.py:37-38) hascontext=262144,page_tokens=64, and itsRankCosts(:43) declares nopage_tokens, soPlan.page_tokens == recipe.page_tokens == 64(planning.py:328-332).500000 % 64 == 32, soplanning.planraisesUsageErrorbefore the assertions run. The test and the validation contradict each other; at least one is wrong, and the validation is the newer, more consequential one. -
The documented no-op path is unreachable for unaligned values.
docs/cli-design.md:446states the flag caps "atNtokens, below the recipe's maximum", with default "The recipe's maximum context", and the PR description says "a cap above the pool resolves to the pool capacity, as stock". With this check,--request-context 262145on a 256K recipe fails outright rather than resolving to the recipe max. Rejecting a value that will be clamped away is user-hostile and inconsistent with how the rest ofplantreats capacity (planning.py:538-544clamps pages,:370-375clamps context — neither rejects).
Why it matters: the alignment requirement is real (helios/src/model/catalog.rs:50-57 requires both prepared_sequence_tokens and limits.max_sequence_tokens to be multiples of page_tokens), so some check is needed — but it must apply to the value the core will be told to serve.
Fix: validate the resolved value. __post_init__ cannot do it, because the first Plan is built with pages=0 (planning.py:528-537) so tokens == 0 and prepared_context == 0; the memory-dependent half only exists after replace(..., pages=...) (:543-544). Put the check at the end of fit (planning.py:538-544) or in plan after attempt() (:694-701), where plan already computes effective_context = min(result.context, result.prepared_context) (:696) and raises chunk errors from it — the natural place. Validate min(recipe.context, context_target) % page_tokens if the check must be memory-independent, or prepared_context directly. Then the 500000 test case becomes the proof that an oversized target is a no-op, which is what its comment already claims.
Honesty note: I did not execute pytest (no runtime in this review); the failure is arithmetic over the fixture constants and is one command to confirm (pytest tests/cli/test_planning.py).
Should fix — prepared_context is clamped by the export host's free memory
ignition/planning.py:370-375:
@property
def prepared_context(self) -> int:
"""The context the prepared core serves per request; the recipe max when no target is set."""
if self.context_target is None:
return self.recipe.context
return min(self.recipe.context, self.context_target, self.tokens)
self.tokens is pages * page_tokens (planning.py:362-363) and pages is sized from the exporting host's free supply (planning.py:538-544). This value becomes the exported core's max_sequence_tokens (ignition/preparation/bootstrap.py:58).
Three problems:
- Non-reproducible artifact. Two exports with byte-identical
reproduction_args(ignition/preparation/rebuild_manifest.py:231-320, which now includes--request-contextat:264-265) can declare differentmax_sequence_tokensdepending on how much VRAM happened to be free at export. That is the opposite of AGENTS.md:452-456 ("the plan, its printed report, and its recorded measurements describe what was prepared") and of the pin-everything principle in the same section. - Silent under-delivery. On a host whose pool is smaller than the requested cap,
--request-context 131072prepares, say, a 20000-token core with no warning;to_dictstill printscontext_target: 131072alongsidecontext: 20000(planning.py:432,:440-441), so the report reads as if the cap was honoured while the core is smaller. - Duplicated clamp. Helios already narrows the advertised ceiling to the physical pool:
helios/src/model.rs:268-272(fit_context:max_sequence_tokens = prepared_sequence_tokens.min(pages.saturating_sub(draft_pages) * page_tokens)), andhelios/src/model/catalog.rs:49only requiresmax_sequence_tokens <= prepared_sequence_tokens. Sizing the pool is the runtime's job (charter line 12: Helios "handles scheduling, caches, and requests"); ignition's job is to declare the model's ceiling.
Fix: drop the self.tokens term — return min(self.recipe.context, self.context_target). The no-target branch already returns recipe.context, which preserves stock behaviour exactly. Page alignment then follows from validating the target alone (and the resolved value is always aligned when the target is), which also removes the awkward interaction with the blocking finding above.
Nit — the served value is derivable but not printed
ignition/planning.py:432 adds context_target next to context (stock, pool-bound) and checkpoint_context (recipe max). The value the core will serve is min(context_target, checkpoint_context) — derivable, and tokens/page_tokens are printed (:440-441) — but not stated. A one-word prepared_context key in to_dict would let an operator read the prepared ceiling straight off the plan report instead of recomputing it. Not blocking; the current keys are sufficient to reconstruct it.
What is clean (verified in code, do not re-raise)
- The cap reaches the core.
ignition/preparation/bootstrap.py:58is the single consumer, and it passesplan.prepared_context; all thirteen recipes readcontext=plan.prepared_context. Helios consumes it asprepared_sequence_tokensand boundslimits.max_sequence_tokensby it (helios/src/model/catalog.rs:43-57). - Omission is a true no-op. With no target,
prepared_contextreturnsrecipe.context, exactly the oldplan.recipe.context; the manifest emits nothing (rebuild_manifest.py:264-265is insideif plan.context_target is not None:, andadd()skipsNoneat:350-355). Byte-equivalent to stock. - All four planning sites forward the flag (
ignition/cli/serve.py:193-206,:274-289viaderive,:459-472,ignition/cli/bench.py:162-177viaderive;derivepassescontext=contextatignition/cli/preparation.py:56, :68). The multi-host_export_hostsgap from the earlier head is fixed. - Manifest and report carry it (
rebuild_manifest.py:264-265,:390atSCOPE_DEPLOYMENT;planning.py:432). - Bench consistency: the workload check moved to
prepared_context(planning.py:248), matching the core. - Docs:
docs/cli-design.md:446correctly scopes the VRAM payoff to--kv-cache-limit concurrency, consistent withhelios/src/runtime_core/memory.rs:284-331(page_ceilingreturnsNonein defaultmemorymode);:1443and:1493updated. - Scope / architecture: one shared capacity flag on the existing
Plan, threaded toPreparationConfig; no per-model branch (charter line 12), no new flag family, no Helios change, no env toggle (AGENTS.md:448-451). It is a "measured performance/memory issue" per the charter's merge bar, with the Blackwell table in the description. The earlier nit that the motivation leaned on a multi-model-hosting non-goal no longer applies.
Open questions / not verified
- I did not run the test suite or any export; the blocking test failure is inferred arithmetically from the fixture constants. Running
pytest tests/cli/test_planning.pysettles it. - If the fix moves validation to the resolved value, confirm at what point a misaligned
prepared_contextwould otherwise surface:helios/src/model/catalog.rs:50-57rejects it at core load, which would be much later than export — an argument for keeping an export-time check, just on the right quantity. - I did not review unrelated branch commits (e.g. the helios
persistent_workerchange) that are not in this PR's 9-file diff.