Subtraction review — PR #533 "Cap the per-request context target"
Key findings
- Only one line of this PR carries behaviour:
ignition/preparation/bootstrap.py:58, which swapsplan.recipe.contextforplan.prepared_contextand thereby lowersBasePreparationConfig.context/max_sequence_tokens. The other 34 added lines are plumbing to that one datum. - The flag's headline benefit already exists at runtime.
flare run --kv-cache-limit concurrency|context|memory(docs/cli-design.md:738, :828-833; docs/model-preparation.md:396-402;page_ceiling, helios/src/runtime_core/memory.rs:284-331) already bounds the shared KV pool to one prepared context per active request, at core load, without a re-export. The PR's own VRAM table is produced with--kv-cache-limit concurrency(description), so the measured "pool = concurrency × prepared-context" scaling is that pre-existing flag's documented behaviour. The genuine delta is only that a single request longer thanNis now rejected. Maintainer yatesdr asked for exactly this distinction in the previous submission (#454: "start from a concrete workload that --max-concurrency and --kv-cache-limit cannot serve"). - Two of the new code blocks restate existing ones (
prepared_contextvscontext, the 9-line chunk branch vs the stock 3-line check), and one new parameter is a pure pass-through. - Docs say one thing three times, and add a "memory-constrained multi-model deployment" rationale that AGENTS.md:171-174 lists as unapproved scope without a maintainer decision.
- The new setting never appears in the plan report (
to_dict()), which AGENTS.md:452-456 requires, so the flag changesmax_sequence_tokensinvisibly.
Findings, ranked by lines saved
1. Blocking — the flag re-implements a runtime setting, and 28 of the 35 added lines exist only to feed one datum (~28 lines)
Where: ignition/cli/__init__.py:167-170 (4), ignition/cli/preparation.py:56,68 (2), ignition/cli/bench.py:176-177 (2), ignition/cli/serve.py:289,472 (2), ignition/planning.py:176,368-373,453,459-460,535,591,674 (~18), docs (3+); the only load-bearing survivor is ignition/preparation/bootstrap.py:58.
What goes: the whole --request-context flag, the Plan.context_target field, the context= keyword on plan()/fit()/derive(), the positive-value check, the prepared_context property, and the chunk-branch rewrite.
Replaced by: nothing. The pool cap is already served by --kv-cache-limit concurrency (docs/cli-design.md:828-833), applied at core load without another export — which is what the PR's own measurement uses.
Why nothing is lost: the PR's charter hook is AGENTS.md:165-169, which requires "a demonstrated defect, a measured performance or memory problem". The memory problem demonstrated is already solved by the runtime flag; the only residual behaviour is that max_sequence_tokens (ignition/direct/scheduler.py:110 (not opened)) matches the cap. If a maintainer decides that residual is wanted, the smallest shape is one Plan field + one plan()/fit() keyword + bootstrap.py:58 + one docs row (~7 lines instead of 35 — see finding 2-5 for the remainder of that shape).
Lines saved: about 28 of the 35 added.
2. Should fix — Plan.prepared_context duplicates Plan.context (~4 lines)
Where: ignition/planning.py:368-373, and its second consumer at ignition/planning.py:694.
Plan.context (planning.py:363-366) is min(self.recipe.context, self.tokens). The new property returns min(self.recipe.context, self.context_target, self.tokens) — exactly min(self.context, N). The five-line body collapses:
@property
def prepared_context(self) -> int:
"""The context the prepared core serves per request."""
return self.context if self.context_target is None else min(self.context, self.context_target)
and the call site at :694 (effective_context = min(result.context, result.prepared_context)) becomes redundant, since prepared_context <= context always. Why nothing is lost: identical value for every input, including the omitted-flag case (returns recipe.context). Lines saved: 2 in the property (4 with its extra min), 2 at the call site.
3. Should fix — the two-message chunk branch adds 6 lines to say what the 3-line error says (~6 lines)
Where: ignition/planning.py:692-701 (+7/−3).
Stock was:
if chunk > result.context:
raise UsageError(f"--prefill-chunk-size {chunk:,} exceeds the {result.context:,}-token context"
" this plan allows")
The PR turns it into a 9-line block with a nested if prefill_chunk is None branch and a second error string, only because a recipe default chunk can now exceed a small --request-context. The generic message already names both numbers, which is what a user needs to pick either remedy. Smaller, one message:
limit = min(result.context, result.prepared_context)
if chunk > limit:
raise UsageError(f"--prefill-chunk-size {chunk:,} exceeds the {limit:,}-token context this plan allows")
Why nothing is lost: same condition, same numbers, same remedies. No test asserts either new string (grep of tests/ for request-context, prepared_context, context_target → no matches). Lines saved: 6.
4. Should fix — the docs state the cap three times, and advertise out-of-scope multi-model hosting (~3 lines)
Where: docs/cli-design.md:446 (one very long new row) and the PR's other two edits at :1443 and :1493.
:446 repeats (a) the reject behaviour, already written at :1443 and :1493 by this same PR; (b) "the per-request cache allocation is sized from the prepared context", already documented for every core at :828-833; (c) "Command line only; … requires re-export", already carried by --mixed-prefill (:447) and by the --kv-cache-limit note (:874-876). One row suffices:
| `--request-context N` | Cap the prepared per-request context and `max_sequence_tokens` at `N` tokens. Command line only; changing it requires re-export. | The recipe's maximum context |
and the :1443/:1493 rewords can be dropped (the flag then appears once, in the flag table). The removed prose also carries "a memory-constrained multi-model deployment", which AGENTS.md:171-174 rejects as scope expansion. Lines saved: ~2 doc lines plus roughly half of row :446.
5. Nit — derive()'s new parameter is a pure pass-through; the setting is invisible in the plan report (~2 lines, plus a consistency gap)
Where: ignition/cli/preparation.py:56 (added keyword) and :68 (context=context forward).
All three callers pass args.request_context or nothing (bench.py:177, serve.py:289, serve.py:472) — there is no per-command variation to justify the extra hop; pass it where it is used or drop it with the flag (finding 1). Lines saved: 2.
Separately, Plan.to_dict() (ignition/planning.py:389-442) records every other plan setting (context, checkpoint_context, prefill_chunk, mixed_prefill, …) but not context_target/prepared_context, even though AGENTS.md:452-456 requires the plan, its printed report and recorded measurements to describe what was prepared, and bench.py:237 publishes plan.to_dict() as details["configuration"]. As a subtraction this reinforces finding 1: the field has no reporting consumer, only bootstrap.py:58.
Left behind (dead or inconsistent after the change)
ignition/cli/serve.py:68-69:max_body_bytesis still sized fromrecipe.contextandcontext_hintstill says "context is limited by the checkpoint and available cache capacity" — no longer true once a target caps it.ignition/bench/runner.py:388(not opened) /ignition/planning.py:248: benchmark cases are still validated against the recipe max (selection.required_context > self.context), not the prepared context, sobench --request-contextcan select a context the prepared core cannot serve.ignition/cli/help.py:38(not opened): the--prefill-chunk-sizerange still advertises64..recipe.context, above the prepared context.ignition/planning.py:389-442:to_dict()never reports the new setting (see finding 5).- Pre-existing documentation that keeps its old promise:
docs/cli-design.md:874-876states the runtime flags need no re-export, which is the subtraction argument in finding 1.
File-by-file confirmation that nothing else can be cut
ignition/preparation/bootstrap.py:58(+1/−1) — the only load-bearing line; nothing to subtract.ignition/cli/__init__.py:167-170(+4) — flag + 3-line help; exists solely to feed the line above; goes with finding 1.ignition/cli/bench.py:176-177,ignition/cli/serve.py:289,472(+4/−3) — forwards; go with finding 1, nothing else in those files.ignition/planning.py(+21/−7) — field, property, check, two keywords, two forwards, one branch rewrite: all scaffolding except the property and branch, both of which have smaller equivalents (findings 2, 3).docs/cli-design.md(+3/−2) — finding 4.
Already minimal: the flag's help text and the bootstrap.py swap are as short as they can be; the change is not padded with tests or comments, and adds no new helper, type or constant that duplicates a repository one.
Open questions / not found
- No test anywhere asserts the new behaviour (
tests/has no match forrequest_context,prepared_context,context_target), so nothing pins the branches in findings 2 and 3 either way — the maintainer asked for such a test in #454 and this resubmission still has none. - I could not find a workload in the description, #454, or the docs that
--max-concurrencyplus--kv-cache-limitcannot serve; the description's own table is produced with the runtime flag. That is the case for dropping the flag (finding 1) rather than shrinking it.