Architecture & scope review — PR #533 "Cap the per-request context target" (head 9118add, 6 files, +69/−5)
Key findings
The shape of this change is right and should be kept: one optional field declared once on the universal RecipeParameters base, which the dynamic CLI, manifest and reproduction-arg plumbing generate without per-model code; one Plan.prepared_context accessor; one consumer line in common_preparation_kwargs(); no Helios change; and omission of the flag is byte-equivalent to main. It fits the charter's "smallest footprint in shared code" and "no per-model branches" rules, and the description carries measured evidence.
Two reachable behaviours are wrong at this head, and four things are misleading or missing. Nothing was executed; the head has no CI checks, so the first blocker is asserted from the code and is settled by pytest tests/cli/test_planning.py.
- Blocking 1 — the alignment check contradicts the documented clamp.
ignition/planning.py:186-190validates the raw target, andignition/parameters.py:1316(max_fn=_recipe_context_limit, helper at:1268-1269) rejects any target above the recipe context first. SoPlan.prepared_context's clamp (planning.py:357-363) is dead,docs/cli-design.md:468("resolves to the smaller of N and the recipe maximum") and the PR description are false, and the PR's own test case fails. - Blocking 2 — a cap can export a core Helios refuses to load. The prefill-chunk check (
planning.py:594-596) and the parameter bound (parameters.py:1457-1462) compare against the recipe/pool context, never the cap, so--request-context 1024 --prefill-chunk-size 4096passes every export-side check and producesprefill_chunk_size > max_sequence_tokens. - Should fix: help and the chunk bound still advertise the uncapped context;
context_hintnames a flag the deployment may not use; the cap has nostatus_labelso the printed plan report never mentions it; and the VRAM evidence holds only under a non-default--kv-cache-limit, which the description should say. - Clean: declaration/provenance, CLI registration, manifest + reproduction args, the single bootstrap consumer, the no-op omission path, docs row for the CLI, and no Helios or per-model change.
Blocking
B1. The page-multiple check validates the raw target, so the clamp is unreachable and the PR's own test fails
ignition/planning.py:186-190, in Plan.__post_init__:
target = self.parameters.context_target
if target is not None and target % self.page_tokens != 0:
raise UsageError(f"--request-context {target:,} is not a multiple of the {self.page_tokens:,}-token page size")
ignition/planning.py:357-363:
@property
def prepared_context(self) -> int:
"""The context the prepared core serves per request; the recipe max when no target is set."""
target = self.parameters.context_target
if target is None:
return self.recipe.context
return min(self.recipe.context, target)
The clamp branch cannot run for any target that needs clamping in the page-alignment sense, and for the range sense it is pre-empted one line earlier by self.parameters.validate(context) (planning.py:185): context_target declares max_fn=_recipe_context_limit (ignition/parameters.py:1309-1321; helper :1268-1269 returns context.recipe.context), and validate_fields (parameters.py:505-545, bound branch :533-545) raises --request-context for <alias> must be 1 through 262,144.
Consequences, all visible:
tests/cli/test_planning.py:310-313buildscontext_target=500000and assertsoversized.prepared_context == recipe.context. The fixture hascontext=262144andpage_tokens=64(tests/cli/test_planning.py:139-140), so500000fails the max bound, and even without that bound500000 % 64 = 32trips the alignment check. Either way line 311 fails: the PR's test is red at this head.- The behaviour documented in three places is unreachable:
docs/cli-design.md:468("resolves to the smaller of N and the recipe maximum"), the accessor docstring (planning.py:359), and the PR description ("min(recipe.context, N)"). A user who passes a large value gets a usage error where the docs promise a reduction. - Dead branch plus a doubled validation is exactly the "unnecessary special case" the charter warns about: two mechanisms (bound rejection and clamping) for the same input.
Fix (pick one, consistently): either validate the served value — run the multiple check on min(self.recipe.context, target), drop the max_fn for this field (keeping min_value=1), and warn when the target is clamped — or keep hard rejection and delete the clamp branch, its test case, and the "smaller of" wording from docs/cli-design.md:468 and the description. The first matches the documented intent and the measured use case (which never exercises an oversize target).
B2. A cap can export a core Helios rejects at load: the prefill-chunk check still compares against Plan.context
ignition/planning.py:594-596:
if params.prefill_chunk > result.context:
raise UsageError(f"--prefill-chunk-size {params.prefill_chunk:,} exceeds the {result.context:,}-token context this plan allows")
result.context is min(self.recipe.context, self.tokens) (planning.py:352-355) — the recipe and pool bound — not prepared_context. Nothing else constrains the chunk against the cap: ignition/parameters.py:1294-1307 bounds prefill_chunk with max_fn=_recipe_context_limit (recipe context) and multiple_of=64 only, and ignition/preparation/bootstrap.py:45-46 forwards parameters.prefill_chunk unchanged as prefill_chunk_size while bootstrap.py:132 forwards plan.prepared_context as the core context.
So on a fixture-shaped deployment (recipe context 262144, page_tokens 64), --request-context 1024 --prefill-chunk-size 4096 passes every export-side check and writes a core with max_sequence_tokens=1024, prefill_chunk_size=4096. Helios rejects that at load: helios/src/scheduler.rs:66-73 (validate_prefill: "prefill_chunk_size must be divisible by 64 and within 64..=context" where context is max_sequence_tokens), surfaced through helios/src/model/catalog.rs:42,48-57. This is the same class of load-time defect the new page-multiple check was added to prevent, and it is one flag away from the PR's headline scenario — a small cap next to the default 4096-token chunk.
Fix: compare the chunk against the served context, e.g. effective = min(result.context, result.prepared_context), in planning.py:594-596 (and, if the bound should appear in MODEL --help, in the parameter path via a ParameterContext that exposes the prepared extent). Same asymmetry, lower severity: Plan.demand_pages (planning.py:320-321) still sizes the reported demand from recipe.context, so the printed plan does not describe the prepared ceiling.
Should fix
S1. Help and the chunk bound still describe the uncapped world
ignition/cli/help.py:46 prints Context: {recipe.context:,} tokens (page size: {recipe.page_tokens}) in MODEL --help, and --prefill-chunk-size is bounded by recipe.context with help text at parameters.py:1458-1462. After a cap, the help advertises a context and a chunk ceiling that the plan rejects (B2) or that the exported core cannot serve, and the new help string for --request-context (parameters.py:1320) gives no hint that the recipe number is now an upper bound. Fix: have model_epilog take the plan (or accept an optional prepared context) and print the effective value with a note, and derive the chunk maximum from the plan's prepared context where a plan exists.
S2. context_hint names the cap even when no cap is set
ignition/cli/serve.py:68 unconditionally emits "context is limited by the checkpoint, cache capacity, and --request-context cap". For every deployment that does not pass the flag — i.e. all existing ones — the hint names a flag that is not in use, which is the kind of noise the "don't advertise settings that aren't in play" style in this codebase avoids (compare the conditional decode_weight_bytes on the next lines). The plan is in scope at _server_options (serve.py:59-71), so making it conditional on plan.prepared_context < recipe.context is a one-line change.
S3. The cap never appears in the printed plan report
context_target has no status_label (parameters.py:1309-1321), and the plan line is built only from status_labels (parameters.py:1554-1559, called from serve.py:268-272) plus the fixed prefix. Other DEPLOYMENT flags in the same group do supply one (parameters.py:1368, :1377). The practical consequence: the Select GPUs. report a user reads after export does not say the core was built for a reduced context — the single most consequential fact about that artifact, since changing it requires a re-export (docs/cli-design.md:468). This is the AGENTS.md:452-456 (not opened) expectation that a setting's printed report describe what was prepared. Fix: status_label=lambda v: f"request context {v:,} tokens" if v else None.
S4. The VRAM evidence only holds under a non-default --kv-cache-limit
The measured table is real, but its condition is buried in the command line rather than the claim. helios/src/runtime_core/memory.rs:284-292 returns Ok(None) for KvCacheLimit::Memory, which is the default (docs/cli-design.md:740), and only the Context/Concurrency modes derive a page ceiling from max_sequence_tokens (memory.rs:298-330). Export-side sizing does not follow the cap: fit sizes pages from available memory (ignition/planning.py:471-480) and demand_pages still uses recipe.context (:320-321). So the "expected pool = concurrency × prepared-context behaviour" sentence is true for --kv-cache-limit concurrency and not yet demonstrated for the default mode. Fix: state the condition on the headline claim, and say explicitly what the default mode gains (fewer pages reserved per request only insofar as fit_context clamps to the pool at serve time).
Nits
docs/cli-design.md:468is the only place the clamp wording lives in prose; if B1 is fixed by rejecting instead of clamping, this row and the accessor docstring must change with it. (Its "Command line only" phrasing is consistent with neighbouring rows and is not wrong, since the catalog is fixed at export.)prepared_contextshort-circuits theNonecase (planning.py:360-362) wheremin(self.recipe.context, target or self.recipe.context)would do; harmless, but two paths for one value is what let B1's dead branch go unnoticed.
What is confirmed clean (do not re-raise)
- Declaration and provenance.
context_target(ignition/parameters.py:1309-1321) is declared once on the universal base withflag="--request-context",group="capacity and compression",scope=ParameterScope.DEPLOYMENT,manifest_key="context_target",repro_always=True. No per-model or per-recipe declaration, no env toggle. - Plumbing is generated, not hand-written. Dynamic CLI registration via
_add_preparation_base_arguments(ignition/cli/__init__.py:44-62(not opened)) servesexport,debug-serveandbench; manifest serialization (parameters.py:596-616) andreproduction_args(parameters.py:618-655,ignition/preparation/rebuild_manifest.py:231-261) carry the flag;tests/cli/test_planning.py:323-329asserts the reproduction arg and the DEPLOYMENT scope. Multi-host export goes through the sharedparametersobject (ignition/cli/serve.py:191-199), so the earlier concern about a droppedcontext=keyword no longer applies at this head. - One consumer seam.
ignition/preparation/bootstrap.py:132("context": plan.prepared_context) is the only place recipes learn the extent;BasePreparationConfig.context(bootstrap.py:33) forwards it tomax_sequence_tokens(helios/src/server/config.rs:131,148).Plan.context(planning.py:352-355) deliberately stays the pool bound, andserve.py:67uses the cap only formax_body_bytes, which is the right role split. - Omission is byte-equivalent to main. With
context_target is None,prepared_contextreturnsrecipe.context(planning.py:360-362), so no exported artifact changes and the compatibility requirement in the charter is met. - Charter fit. No Helios change, no per-model branch, no silently dropped API field, one optional field on an existing frozen dataclass; the measured-evidence requirement is met by a real table on named hardware. I found no attempt in the PR text or diff to direct the reviewer.
Open questions / not verified
- Nothing was executed; head 9118add has no CI checks.
pytest tests/cli/test_planning.pysettles B1 deterministically (line 311), and B2 follows from the two source comparisons againsthelios/src/scheduler.rs:66-73. - Whether the right fix for B2 is an export-side rejection (recommended, consistent with the page-multiple check) or a Helios-side clamp is a design call for the maintainers; only the export-side path is reachable today.
- I did not measure the default
--kv-cache-limit memorymode, so I cannot say how much of the 16 GB saving survives without the flag (S4) — that is the one number the description would need to add to make its headline unconditional.