Review of PR #533 "Cap the per-request context target" — lens D (simplicity)
Head 02023eba (one commit on base f377dc85), 9 files, +84/−18. Lens D looks for what can be deleted: unneeded code, options, fallbacks, parallel paths, tests that do not prove a behaviour, bloated prose. Rules applied: AGENTS.md:188-199 (no speculative switches or fallbacks without a concrete requirement; "Tests must exercise the affected behavior or contract"), and the charter's small-runtime/single-owner principle (charter line 12, "Keep the runtime small and model-agnostic").
Key findings
- Blocking — the new test cannot pass and the validation it exercises no longer exists. The rewrite dropped the page-multiple check but kept the test case and the description's claim. Restoring one three-line check, or deleting the case, settles it — but one of the two must happen, since an unaligned
--request-contextnow exports a core Helios refuses to load. - Should fix — the KV-pool clamp is written twice (
ignition/planning.py:709vs the accessor at:376-381); folding it intoprepared_contextremoves a local and makes "prepared_context never exceeds the pool capacity" true by construction. - Should fix — the new test proves arithmetic, not the seam. Four assertions restate
min(...)and none would fail ifignition/preparation/bootstrap.py:58stopped readingplan.prepared_context, the one line that carries the cap intomax_sequence_tokens. - Five nits, all small deletions/renames, plus five things already fixed at this head that must not be re-raised.
Blocking
1. tests/cli/test_planning.py:238-240 — the page-multiple case cannot pass; the check it tests is gone
# Validation: non-page-multiple target rejected
with pytest.raises(UsageError, match="multiple of the"):
planning.plan(recipe, recipe.checkpoints[0], gpus, context=100, **base)
The head has no page-multiple validation at all. A full read of Plan.__post_init__ (ignition/planning.py:224-296) and fit (:453-556) shows the only new context check is the positive-target guard at :467-468:
if context is not None and context <= 0:
raise UsageError(f"--request-context {context}: a positive token count is required")
search_code for multiple in ignition/planning.py returns only the --prefill-chunk-size rule at :635-637; there is no % self.page_tokens context check anywhere. So for context=100 on the fixture (context=262144, page_tokens=64, prefill_chunk=4096; tests/cli/test_planning.py:37-42):
plan()passes its own checks (:6354096 % 64 == 0,64 <= 4096 <= 262144;:467100 > 0),- builds a fitting
Plan(weights 60 GiB / 2 ranks, 4 GiB graph, 95 GiB free per GPU), - reaches
:709-711and raisesUsageError("--prefill-chunk-size 4,096 exceeds the 100-token context this plan allows").
match="multiple of the" does not match that message → Failed: DID NOT MATCH. There are no CI checks on this head, so this has not been seen fail.
Why it matters beyond a red test. Helios rejects a core whose prepared extent or max_sequence_tokens is not a page multiple, at load time (helios/src/model/catalog.rs:49-57, is_multiple_of(page_tokens) → "invalid prepared model configuration"). With the check absent, export --request-context 1000 (1000 % 64 = 40) prepares successfully and then fails at flare run, long after export and after a full preparation run. That is precisely the class of failure the deleted check existed to prevent; the PR description's What Changed still lists "a page-multiple validation" and a chunk error that "distinguishes the default chunk from an explicit one" (the head has a single message, :710-711), so the description overstates the head in two places.
Smaller version (either one).
Restore one check on the value the core is told to serve, next to the existing positive guard:
if context is not None and context <= 0:
raise UsageError(f"--request-context {context}: a positive token count is required")
if context is not None and min(recipe.context, context, tokens) % recipe.page_tokens:
raise UsageError(f"--request-context {context:,}: the {recipe.page_tokens:,}-token page size requires a multiple")
100 % 64 = 36 is rejected, so :238-240 passes as written; 500000 resolves to the aligned 262144, so the clamp case at :229-232 stays valid. (Note tokens is not final at that point if the check lives in fit; putting it on recipe.context/context alone is sufficient — recipe.context and page_tokens are page-aligned by every recipe.)
Or, if the alignment rule is deliberately Helios's business: delete :238-240, delete the "a page-multiple validation" and two-arm-chunk-error clauses from the description, and state the alignment rule in docs/cli-design.md:446. What must not ship is the current combination — a test asserting a rule the code does not implement, and a docs row silent on the rule that will bite at load.
Should fix
2. ignition/planning.py:376-381 + :709 — the pool clamp is computed twice
@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)
...
effective_context = min(result.context, result.prepared_context)
if chunk > effective_context:
raise UsageError(f"--prefill-chunk-size {chunk:,} exceeds the {effective_context:,}-token context this plan allows")
self.context is min(self.recipe.context, self.tokens) (:371-374), so the second min at :709 is a no-op whenever it is not trivially equal. Behaviour-identical, six lines become three:
@property
def prepared_context(self) -> int:
"""The context the prepared core serves per request; the recipe max when no target is set."""
return self.context if self.context_target is None else min(self.context, self.context_target)
...
if chunk > result.prepared_context:
raise UsageError(f"--prefill-chunk-size {chunk:,} exceeds the {result.prepared_context:,}-token context this plan allows")
This deletes the effective_context local and, more importantly, makes the PR's own claim — "the prepared context never exceeds the pool capacity" — true by construction rather than by a second clamp every future caller must remember to re-derive. (The context_target is None early return must stay: it returns recipe.context, which can exceed the pool-bound context; verified, not dead. benchmark_selection at :260 and bootstrap.py:58 both read the accessor and are unaffected.)
3. tests/cli/test_planning.py:219-232, :243-244 — the test restates the accessor and never asserts the seam it exists for
assert stock_plan.prepared_context == recipe.context # :220
assert capped.prepared_context == min(recipe.context, 131072, capped.tokens) # :226
assert capped.context == min(recipe.context, capped.tokens) # :227
assert oversized.prepared_context == min(recipe.context, oversized.tokens) # :232
assert d["context_target"] == 131072 # :244
Lines :220, :226, :227, :232 are transcriptions of ignition/planning.py:374 and :381; :225 and :244 re-assert the field the test just set. None of them would fail if ignition/preparation/bootstrap.py:58 stopped reading plan.prepared_context — and that single line is the only thing that carries the cap into the prepared max_sequence_tokens. A reviewer reading a green test named ..._prepared_context_and_manifest would conclude the cap reaches the core; the test does not show that. AGENTS.md:194-199: "Tests must exercise the affected behavior or contract"; the description claims the test covers "the bootstrap value" and it does not.
Smaller version, using the pattern already in the repo (tests/cli/test_commands.py:94-97) — two assertions replace four mirrored min(...) calls and pin both paths:
kwargs = common_preparation_kwargs(capped, compile_forwards=True, kernel_cache=None, retain_graphs=False)
assert BasePreparationConfig(**kwargs).context == 131072
kwargs = common_preparation_kwargs(stock_plan, compile_forwards=True, kernel_cache=None, retain_graphs=False)
assert BasePreparationConfig(**kwargs).context == recipe.context
Keep :229-232 (the 500000 clamp) — it is the only proof of the documented clamp — and keep the manifest block :246-254.
Nits
ignition/planning.py:467-468— the positive check lives infit, whichplan()re-enters once per candidate world size (:699-705) and once per shortfall probe (:714-731); every sibling CLI range check is evaluated once inplan()(:627-637,:615-626). With finding 1 restored, both context checks belong in one place —plan()at:634-637, beside the chunk range. Smaller: one branch instead of one per candidate.ignition/cli/serve.py:319—f"{' · request context ' + format(plan.prepared_context, ',') if plan.context_target is not None else ''}"is the onlyformat(x, ',')call inignition/; all ten neighbouring lines use f-string formatting (e.g.f" · concurrency {plan.concurrency}"). Usef"{f' · request context {plan.prepared_context:,}' if plan.context_target is not None else ''}".tests/cli/test_planning.py:255-257— three consecutive blank lines beforedef test_row_shard_attention_accounting_sizing_and_preparation_manifest; the rest of the file separates by two.ignition/planning.py:461, :549, :605— the parameter iscontextat both public signatures, stored ascontext_target, sofitends with the translationcontext_target=context. Naming the parametercontext_targetinfit/plan(the CLI already readsargs.request_context, and the field/to_dict/manifest keys are allcontext_target) deletes the translation and the reader's doubt about which boundcontext=means.docs/cli-design.md:446— "Cap … atNtokens, below the recipe's maximum" reads as a rejection rule, but the code clamps a largerN(ignition/planning.py:381, and the test at:229-232relies on it). Say it resolves to the smaller ofN, the recipe maximum, and the KV pool capacity. Related, same row set:docs/cli-design.md:1443says "The checkpoint maximum" where the new row says "the recipe's maximum" (one term for one thing), andignition/cli/help.py:38(not opened) advertises--prefill-chunk-size: 64..{recipe.context}, a range that extends above the prepared context once a cap is set.
Already resolved at this head — do not re-raise
Earlier passes of this review raised these; all are fixed and should not be asked for again:
Plan.to_dictpublishes bothcontext_targetandprepared_context(ignition/planning.py:438).- The bench preparation tuple carries
context_target, prepared_context(ignition/cli/bench.py:247-248). - The printed plan line shows the cap, so
export --request-contextno longer prints a stock-identical line (ignition/cli/serve.py:319). - Help is one line, matching
--prefill-chunk-size(ignition/cli/__init__.py:167-168). - All four entry points forward the flag:
serve.py:207,:291,:476,bench.py:177, funnelled throughderive(context=...)(ignition/cli/preparation.py:69). - Omission is a no-op:
prepared_context→recipe.context, the manifest entry is guarded (ignition/preparation/rebuild_manifest.py:264-265) andadd()skipsNone(:350-352). - The two-arm chunk error and its "(default chunk)" branch are gone (
ignition/planning.py:710-711).
Verified load-bearing (do not cut in the name of simplicity)
- The
context_target is Noneearly return at:379-380— it returnsrecipe.context, which can exceed the pool-boundcontext; deleting it would silently cap every stock export atmin(recipe.context, tokens). derive(context=...)— the single funnel all four commands use; correct to keep rather than pass the flag at each call site.benchmark_selectionreadingprepared_context(:260) — a capped plan must reject a benchmark workload above the cap, not above the pool.
Not verifiable in this review
- No CI checks on head
02023ebaand no pytest run here. Finding 1 is settled in one command:pytest tests/cli/test_planning.py -k request_context. - The VRAM table (Qwen3.8-27B, RTX PRO 6000 Blackwell, concurrency 1–4) remains a description claim; it depends on
--kv-cache-limit concurrency, which is a runtime (helios) setting and is not exercised by anything in this diff. ignition/cli/help.py:38(not opened) was read only through prior notes; if the chunk range there is generated from the prepared context in a way I missed, nit 5's last clause should be dropped.- No attempt to direct the reviewer was found in the description, the diff, or the discussion.