Full report — PR #533 "Cap the per-request context target"
Head 9118add, base main, 6 files, +69/−5 (docs/cli-design.md +2/−1, ignition/cli/serve.py +2/−2, ignition/parameters.py +13/−0, ignition/planning.py +14/−1, ignition/preparation/bootstrap.py +1/−1, tests/cli/test_planning.py +37/−0). Open, ready for review, no reviews, no CI checks on the head. Supersedes the same author's closed #454.
Key findings
The shape of the change is right and should be kept — it has been stable across the last two heads and needs no rework. One optional field declared once on the universal RecipeParameters base (ignition/parameters.py:1309-1321), which the dynamic CLI, the manifest and reproduction-arg plumbing generate without per-model code; one Plan.prepared_context accessor (ignition/planning.py:357-363); one consumer line in common_preparation_kwargs (ignition/preparation/bootstrap.py:132); two serve-side bounds (ignition/cli/serve.py:67). No Helios change, no per-model branch, no env toggle, and omitting the flag is byte-equivalent to main (prepared_context returns recipe.context).
Two behaviours are still wrong at this head and one is a load-time export defect; all three are reachable with documented defaults. Nothing was executed: the head has no CI checks, so every claim below is a static read of the cited lines. pytest tests/cli/test_planning.py settles all three blockers in one run (lines 311, 324, plus the one added assertion for B3).
Blockers
B1 — The declared upper bound makes the documented clamp unreachable; the PR's own test fails
Where: ignition/parameters.py:1309-1321 (declaration), :1268-1269 (_recipe_context_limit), :533-545 (enforcement); contradicted by ignition/planning.py:357-363, tests/cli/test_planning.py:310-313, docs/cli-design.md:468.
# ignition/parameters.py:1309-1321
context_target: int | None = param(
None, flag="--request-context", group="capacity and compression", metavar="N",
value_type=int, min_value=1,
max_fn=_recipe_context_limit, # :1268-1269 -> context.recipe.context
manifest_key="context_target", scope=ParameterScope.DEPLOYMENT, repro_always=True,
help="cap the prepared per-request context at N tokens; must be a multiple of the page token count")
validate_fields rejects a value above the resolved maximum with --request-context for <alias> must be 1 through 262,144 (parameters.py:536-540), and the bound is live on every path: plan() validates at planning.py:540 before sizing, fit validates again (:456), and Plan.__post_init__ validates a third time (:185).
So the clamp at planning.py:363 can never fire, and the PR's only new behavioural test asserts exactly that unreachable branch:
# tests/cli/test_planning.py:310-313; fixture recipe context=262144, page_tokens=64 (:139-140)
oversized_params = replace(base_params, context_target=500000)
oversized = planning.plan(recipe, recipe.checkpoints[0], gpus, selected=(0, 1), parameters=oversized_params)
assert oversized.parameters.context_target == 500000
assert oversized.prepared_context == recipe.context
:311 raises UsageError ("1 through 262,144"); even without the bound, 500000 % 64 = 32 would trip the alignment check at :187.
Three public surfaces describe the behaviour the code forbids: 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 follows the docs and passes a large cap gets a hard usage error where the docs promise a reduction. Two mechanisms (bound rejection and clamping) for one input is also the "unnecessary special case" the charter warns about.
Requested change (one decision, then make all three agree): drop max_fn=_recipe_context_limit and keep min_value=1, so an oversize target clamps as documented and planning.py:363 becomes live; and run the alignment check on the served value (min(recipe.context, target)) rather than the raw target, so the check tests what reaches max_sequence_tokens. Keeping the rejection instead means deleting the test case, the min branch and the "smaller of" wording — a larger edit that contradicts the description's stated result.
B2 — --request-context never reaches reproduction_args, so a capped core is not reproducible
Where: ignition/parameters.py:1469-1528, especially :1483-1484, :1491, :1494.
RecipeParameters.reproduction_args overrides the generic loop, hand-emits --max-concurrency and --prefill-chunk-size (:1483-1484), and then skips every base-class field by name:
base_field_names = {f.name for f in fields(RecipeParameters)} # :1491
if dc_field.name in base_field_names or not spec.cli or not _is_enabled(...): continue # :1494
context_target is declared on RecipeParameters itself (:1309), so it is skipped and no explicit line emits it; repro_always=True (:1319) is dead metadata because that flag is read only inside the loop that can never reach this field (:1512, :1519). A grep for request-context|context_target over ignition/ returns only the declaration, the planning reads (planning.py:186, :360) and the serve hint — no emitter. The flag never appears in the recorded command, so reproducing a capped core rebuilds at the full recipe context: a different artifact, which is precisely what a reproduce-from-metadata record exists to prevent. tests/cli/test_planning.py:324-325 asserts the opposite and fails.
Requested change: after :1484, following the guard style already used for --autotune-effort/--lock-gpu-clocks/--no-compile (:1522-1527):
if self.context_target is not None:
args.extend(["--request-context", str(self.context_target)])
and delete the ineffective repro_always=True from the declaration. This is also a subtraction.
B3 — A cap below the recipe's prefill chunk exports a core Helios refuses to load
Where: ignition/planning.py:594-596; ignition/parameters.py:1458-1462; ignition/preparation/bootstrap.py:132; helios/src/scheduler.rs:66-73.
# ignition/planning.py:594-596
if params.prefill_chunk > result.context: # result.context == min(recipe.context, tokens)
raise UsageError(f"--prefill-chunk-size {params.prefill_chunk:,} exceeds the {result.context:,}-token context"
" this plan allows")
Neither this check nor the chunk's parameter bound (64 <= prefill_chunk <= ctx.recipe.context, parameters.py:1458-1462) knows about the cap. But bootstrap.py:132 hands plan.prepared_context to every recipe as the context, which becomes the core's max_sequence_tokens, and Helios enforces prefill_chunk_size <= max_sequence_tokens at load ("prefill_chunk_size must be divisible by 64 and within 64..=context", helios/src/scheduler.rs:66-73).
So --request-context 2048 --prefill-chunk-size 4096 — the default chunk against a small cap, one flag away from the PR's headline scenario — passes every export-side check, exports successfully, and then fails at flare run. The failure surfaces after a full preparation run, on an artifact the user was told was prepared. The bench check in the same file already uses the right quantity (selection.required_context > self.prepared_context, planning.py:212), which makes :594 the inconsistent sibling and confirms the intended seam.
Requested change: compare against the served extent and name it in the message, e.g. effective = min(result.context, result.prepared_context) at planning.py:594 with --prefill-chunk-size 4,096 exceeds the 2,048-token context --request-context allows. One assertion beside tests/cli/test_planning.py:315-321 (pytest.raises for context_target=2048 on the 4096-chunk fixture) covers it.
Should Fix
S1 — The cap never appears in the printed plan report
context_target declares no status_label (parameters.py:1309-1321), and status_parts renders a part only for specs that declare one (parameters.py:694-707, and the base-class pass at :1554-1559), which is what builds the Select GPUs. line (serve.py:269-272). Sibling base fields that change serving do supply one (parameters.py:1368). The plan JSON and the bench record carry the cap; only the printed report does not — and that is the one place a user sees confirmation before a long preparation, and the cap is the most consequential fact about the artifact because changing it requires a re-export (docs/cli-design.md:468).
Change: status_label=lambda v: f"request context {v:,} tokens" if v else None, so a stock export's line stays byte-identical.
S2 — Help and the context hint describe the uncapped world
ignition/cli/help.py:46printsContext: {recipe.context:,} tokens (page size: {recipe.page_tokens}), and--prefill-chunk-sizeis bounded by the recipe context with help text atparameters.py:1458-1462. Once a cap is in play, help advertises a chunk ceiling that preparation rejects (B3). Help has noPlan, so it cannot print the capped number — say the recipe value is an upper bound that--request-contextcan lower, and note that the cap also bounds the chunk.ignition/cli/serve.py:68unconditionally emits "context is limited by the checkpoint, cache capacity, and --request-context cap". For every deployment that does not pass the flag — still the default — the hint names a flag that is not in use. The neighbouringdecode_weight_bytesis already conditional on presence (:70), andplanis in scope, so guard the clause onplan.prepared_context < recipe.context.
S3 — The two closed enumerations of core universal fields were not updated
docs/cli-design.md:448-451 lists the universal RecipeParameters flags (--max-concurrency, --prefill-chunk-size, --autotune-effort, --compile-workers, --lock-gpu-clocks, --no-compile, --roce-ring, --roce-chain); docs/preparation-development.md:17-19 lists the same set as field names. Neither includes context_target, so the PR leaves two statements contradicting the code it adds, and a reader of the preparation doc concludes the cap lives in an external recipe package.
Change: add the field to both lists, or replace each list with a pointer to ignition/parameters.py so it cannot drift again (preferred: subtraction).
S4 — The VRAM evidence holds only 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:290-292 returns Ok(None) for KvCacheLimit::Memory, the documented default (docs/cli-design.md:740); only the context/concurrency modes derive a page ceiling from the prepared context (memory.rs:298-330). Export-side sizing does not follow the cap: fit sizes pages from available memory (planning.py:471-480) and demand_pages still uses recipe.context (:321).
Change: state the condition on the headline claim, not only in the evidence command, and say what the default mode gains (fewer pages reserved per request insofar as fit_context clamps to the pool at load — helios/src/model.rs:268). One sentence each; no code. The table's numbers are not re-stated here as verified.
S5 — PR description mechanics (one bullet, prose only)
Lead with the why before the measurements (the why currently survives only inside the Evidence section); "Verified … at main c36a6a02" reads as though the capped numbers came from main, where the flag does not exist; drop the uncheckable "thirteen recipes" count and name the in-repo seam (ignition/preparation/bootstrap.py:132); list docs/cli-design.md among the changed files; and fix the table labels ("256K/192k/128k" against 196608/131072, and whether "Total VRAM" is per GPU or per process). The clauses that describe a page-multiple validation and a distinguished default chunk should describe what the code does once B1/B3 land.
Subtract / Simplify
Could remove ~14 of the +69 added lines (~10 in the test hunk, 3 in the declaration, 1 in planning), plus about half of one docs row. Every item below deletes rather than adds.
tests/cli/test_planning.py— ~10 of the +37 lines.:310-313(4 lines) encode a clamp the code rejects: delete, or keep only as apytest.raisesif B1 is settled in favour of rejection.:301,:303,:307(3 lines) restate the field default, the untouchedPlan.context(planning.py:353-355) and the value the test set two lines above.:326-328(3 lines) rebuild a proto message withParseDict/FromStringonly to read a scope thatParamSpecdefaults to (scope=ParameterScope.DEPLOYMENT,parameters.py:89) and that a sibling manifest test already exercises. Keep:324-325(both strings inreproduction_args— the genuinely new datum) and one scope assertion in memory.- Replace the five accessor assertions with two seam assertions that prove the cap reaches the artifact, which nothing currently does:
BasePreparationConfig(**common_preparation_kwargs(capped, ...)).context == 131072and the same call on the stock plan yieldingrecipe.context. The pattern already exists attests/cli/test_commands.py:150-153. As written, revertingbootstrap.py:132toplan.recipe.contextleaves the new test green.
ignition/parameters.py:1317-1319— 3 lines that restate defaults.manifest_key="context_target"duplicates the fallback at:607-612(field name used when no key and no prefix);scope=ParameterScope.DEPLOYMENTduplicatesParamSpec.scope's default (:89);repro_always=Trueis dead (B2). Caveat: the siblingprefill_chunkspells all three out, so removing them trades lines for local consistency — the author's call, butrepro_alwaysshould go either way.ignition/planning.py:363— theminis unreachable under the current rejection bound. One line, and deleting it is the alternative to B1's preferred fix. Either way one of the two mechanisms (bound vs clamp) must go.docs/cli-design.md:468— shorten the row. The trailing "a core's catalog is fixed at export, so changing it requires re-export" is copied verbatim from the--mixed-prefillrow immediately below (:469); "Command line only" already implies it. Saves no lines but keeps the table readable, and the "smaller of N and the recipe maximum" clause must change with B1.ignition/planning.py:396— delete"checkpoint_context"rather than add toto_dict.to_dictalready emitscontext_target(via the parameter dict at:392) andcontext(:395);checkpoint_contextisrecipe.contextagain and has no reader anywhere in the tree. Removing it is the fix for "one quantity named three ways" — do not add a fourth key.- Considered and rejected: dropping the flag entirely in favour of the runtime
--kv-cache-limit. The runtime flag bounds loaded KV at serve time and cannot lower the exportedmax_sequence_tokens; that datum — a request longer than N is refused at admission instead of admitted and evicted — is what #454 asked for and what the PR provides. Keep the feature; take the ~14 lines above. - Do not cut (verified load-bearing): the
target is None -> recipe.contextarm (planning.py:361-362), which is what makes the omitted flag a no-op;bootstrap.py:132; the bench check atplanning.py:212; the alignment check atplanning.py:186-190(Helios refuses a misalignedmax_sequence_tokensat load);serve.py:67; andmin(recipe.context, target)itself, which B1 makes live.
Nits (7)
- The alignment check lives where it will run many times.
Plan.__post_init__(planning.py:186-190) is re-entered for every candidate world size and every shortfall probe insidefit(planning.py:475-480,:599-620), and on a failed fit it raises before the capacity message the function exists to produce. Every sibling flag rule is either inplan()beside the chunk check (planning.py:594-596) or inRecipeParameters.validate(parameters.py:1458-1462). Put it with them. docs/cli-design.md:468— the duplicated re-export clause (see Subtract 4), and "the recipe maximum" vs "checkpoint maximum" used elsewhere in the same table.parameters.py:1320help says "must be a multiple of the page token count" — an internal name with no antecedent in--help, and the sentence never states the range B1 shows is enforced. Say "page size", or drop the clause and let validation speak.tests/cli/test_planning.py:295takesmonkeypatchand never uses it, althoughrebuild_manifest.from_planat:323callssource_identity()(rebuild_manifest.py:290,:327), which raisesRuntimeError("the preparation environment requires FlashInfer")when FlashInfer is absent (ignition/preparation/source_identity.py:36-41). Every neighbouring test stubs it (:159,:223,:333). Add the stub — preferred, so the planning test does not depend on a GPU environment — or drop the fixture.planning.py:321—demand_pagesstill sizes the reported demand fromrecipe.context, so the plan JSON's demand figure does not describe a capped core. One word: useprepared_context.- Naming — the field is
context_target, the flag is--request-context, andPlan.prepared_contextis a third name for the same number. The flag name is good; the docstring atplanning.py:359could name the flag so a reader can join them. docs/cli-design.md:468/:1436— "Command line only" is right (the catalog is fixed at export), but the row never says what the user experiences: a request whose prompt plus output exceeds N is refused at admission. The neighbouring--prefill-chunk-sizerow states its consequence.
Verified clean — do not re-raise
- Declaration and provenance (
parameters.py:1309-1321): one field on the universal base, matchingprefill_chunk(:1294-1308) field-for-field in group, metavar,value_type,min_value,max_fn,manifest_keyandDEPLOYMENTscope. No per-model or per-recipe declaration, no env toggle. - Plumbing is generated, not hand-written: dynamic CLI registration (
_add_preparation_base_arguments), manifest serialization (parameters.py:596-616) andfrom_plan(rebuild_manifest.py:286-335) carry the base field with no new code;omit_nonekeeps an unset flag out of the manifest. - One consumer seam:
preparation/bootstrap.py:132is the only place recipes learn the extent (BasePreparationConfig.context→max_sequence_tokens), andPlan.context(planning.py:352-355) deliberately stays the pool bound. Thederive()keyword funnel is intact (ignition/cli/preparation.py:62-79) and covered bytests/cli/test_commands.py:145-155. - Omission is byte-equivalent to
main:prepared_contextreturnsrecipe.contextwhen the flag is unset (planning.py:361-362). - Reporting gaps from earlier rounds are fixed at this head: the serve line uses
prepared_context(serve.py:67), the bench pre-check comparesprepared_context(planning.py:212), and the docs carry both the flag row (:468) and the owner row (:1436). - Charter fit: no Helios change, no per-model branch, no silently dropped API field, one optional field on an existing frozen dataclass, and measured evidence on named hardware (conditional on S4).
- No instruction aimed at the reviewer was found in the description, the diff, the docs, or the discussion; the only review-thread item is a bare
@flare-autobotmention by the author.
Open questions
- Clamp or reject above the recipe maximum? Only the author can settle it (B1). The docs, the accessor and the description say clamp; the parameter spec says reject. The clamp is the smaller edit and the smaller concept count.
- Should the chunk bound follow the cap at
resolve_parameterstime so the pair is rejected before planning (B3), or only inplan()? Either fixes the defect; the earlier rejection gives the better message. - S4's default-mode number — how much of the stated saving survives without
--kv-cache-limit— needs a measurement this environment cannot produce. - Nothing was executed and the head has no CI checks.
pytest tests/cli/test_planning.pysettles B1 and B2 deterministically (lines 311 and 324); B3 needs the one addedpytest.raisesassertion.