PR 533 — "Cap the per-request context target": subtraction review
Reviewed at head 02023eba against AGENTS.md:165-199, the charter (read in full), and the maintainer's earlier review of the same change in closed PR #454. Scope is subtraction only: what this change, and the code it touches, can do without.
Key findings
- The flag re-implements an existing runtime flag, and the PR's own evidence is measured with that existing flag (blocking, ~70 of 84 added lines).
flare run --kv-cache-limit concurrency|context|memory(docs/cli-design.md:737) already bounds the shared KV history to prepared-context × concurrency without a re-export. The description's VRAM table is explicitly "served at concurrency 1–4 (--kv-cache-limit concurrency)" — so the measured pool-scaling behaviour is the pre-existing flag's, not this PR's. The one datum this PR adds is a lower exportedmax_sequence_tokens, which flows through exactly one load-bearing line:ignition/preparation/bootstrap.py:58("context": plan.prepared_context). Everything else — field, property, check, four CLI forwards, manifest entries, docs rows, 47 test lines — is plumbing for that integer. #454's maintainer asked for "a concrete workload that--max-concurrencyand--kv-cache-limitcannot serve"; the resubmission's memory argument is the--kv-cache-limitargument. - Two assertions in the new test cannot pass at this head (~5 lines, and a description claim with no code). There is no page-multiple validation anywhere in the diff, and the manifest assertion reads the wrong protobuf oneof field.
- The rest of the test block repeats itself (~10 more lines) — a clamp case exercising no distinct path, an assertion restating an earlier one, and a 7-line manifest round-trip that re-proves
from_plan's genericNoneskip already covered by a sibling test. - Two small simplifications in
planning.py(4 lines):prepared_context's body duplicatescontext, and thecontext <= 0check lives infit()rather than beside every other flag validation. - Docs state the cap three times across the PR's own three edits.
- Total removable ≈22 of the 84 added lines if the flag stays; ≈70 if it goes. Keeping only the new
max_sequence_tokensdatum leaves a ~12–15-line change.
1. Blocking — the flag duplicates the runtime --kv-cache-limit; ~70 of 84 lines
Surface added by this PR: ignition/cli/__init__.py:167-168 (flag + help), ignition/cli/preparation.py:55 keyword and :69 forward, ignition/cli/bench.py:177, ignition/cli/serve.py:207, :291, :476, plus :319 (the plan-summary fragment), ignition/planning.py:186 (context_target field), :260 (bench required-context check), :377-381 (property), :438 (to_dict keys), :467-468 (<= 0 check), the context= keywords at :461/:549/:602/:689, the :709 rewrite, ignition/preparation/bootstrap.py:58, ignition/preparation/rebuild_manifest.py:264-265 and :389, docs/cli-design.md:446, :1443, :1493, and tests/cli/test_planning.py:211-255.
What already exists. --kv-cache-limit (docs/cli-design.md:737; semantics at :827; the "KV history ceiling" owner row at :1444, untouched by this PR) bounds shared KV history by prepared context times selected concurrency, one prepared context, or available memory — at core load, without re-export.
Why that is decisive. The description's table says the packages were "served at concurrency 1–4 (--kv-cache-limit concurrency)". The "pool = concurrency × prepared-context" scaling it reports is that runtime flag's documented behaviour. The genuinely new datum is a lower exported request ceiling: bootstrap.py:58 → BasePreparationConfig.context → the core's max_sequence_tokens, so a single request longer than N is rejected. That is one integer through one line.
Smaller version: drop --request-context from all four entry points, drop Plan.context_target and prepared_context, drop the manifest entries and the test. If the lower request ceiling is wanted, keep exactly: one Plan field, one context= keyword on plan()/fit(), bootstrap.py:58, one docs row — about 12–15 lines instead of 84.
Why nothing is lost: the memory payoff the description measures is available today with a runtime flag and no re-export; only the served-request ceiling datum goes, and it is the one thing the PR should justify against #454's question.
Cite: AGENTS.md:165-169 (need must be a maintainer request, demonstrated defect, measured problem or bad docs); AGENTS.md:188-193 ("Do not add … configuration switches without a concrete requirement"); charter "Look for the smallest footprint in shared code, or a way to solve it without new code at all."
2. Should fix — two test assertions cannot pass, and the page-multiple validation does not exist: ~5 lines
tests/cli/test_planning.py:238-241:
with pytest.raises(UsageError, match="multiple of the"):
planning.plan(..., context=100, **base)
Searching multiple of the at this head finds only tests/cli/test_planning.py:239 and an unrelated Rust comment; the only validation is the pre-existing --prefill-chunk-size check at ignition/planning.py:636-637, which context=100 does not trip (the default chunk 4096 is a multiple of 64 and within 64..262144). planning.plan(...) therefore returns normally and the assertion fails. The description's "page-multiple validation" is not in this diff. Delete :238-241 (4 lines) or, if the validation is wanted, add it — but that is an addition, not this review's business.
tests/cli/test_planning.py:254:
assert by_key["context_target"].value.int64_value == 131072
_preparation_value emits uint_value for a non-negative int (ignition/preparation/rebuild_manifest.py:333), so int64_value reads 0. Either delete the line or read uint_value; as written it cannot pass, which shows the block was never run.
3. Should fix — the new test block repeats itself: ~10 lines
tests/cli/test_planning.py:211-255 (+47):
| Lines | What | Why it goes |
|---|---|---|
:227 |
assert capped.context == min(recipe.context, capped.tokens) |
restates :221. ~1 |
:229-232 |
clamp case, context=500000 |
prepared_context is one min() expression (planning.py:381); a target above the recipe max exercises no distinct branch from :224-226. ~4 |
:242-244 |
d = capped.to_dict(); assert d["context_target"] == 131072 |
restates :225; the to_dict key is also visible in the new :438. ~2 |
:246-253 |
8-line manifest encode/decode/round-trip | re-proves from_plan's generic add() None skip (rebuild_manifest.py:350-352) and the scope/value plumbing already exercised by the sibling manifest test at tests/cli/test_planning.py:92-106; :248-249 (both strings in reproduction_args) is the part that is new. ~6 |
Smaller version: keep the no-op case (:217-221), one capped case (:223-226), one pytest.raises for 0, :248-249 for reproduction args, and one scope assertion — about 15 lines instead of 47.
4. Nit — prepared_context's body duplicates context: ~2 lines
ignition/planning.py:376-381:
@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)
Plan.context (:371-374) is min(self.recipe.context, self.tokens), so min(recipe.context, N, tokens) == min(self.context, N).
Smaller version:
return self.context if self.context_target is None else min(self.context, self.context_target)
Do not cut the context_target is None early return — it must yield recipe.context, which can exceed the pool-bound self.context; removing it would break the no-op claim. The same applies to effective_context = min(result.context, result.prepared_context) at :709, which is load-bearing for the no-target case.
5. Nit — the <= 0 check lives in fit() and re-runs per attempt: ~2 lines
ignition/planning.py:467-468. fit() is re-entered by plan() once per candidate world size and per shortfall probe (:689, :693-705), so the check runs on every attempt, and it is the only flag validation outside Plan.__post_init__, where every other flag is validated (:266-296). Moving it beside them (or deleting it with finding 1) removes 2 lines and the re-checks.
6. Nit — the docs say the cap three times: ~2 lines
docs/cli-design.md:446(new flag-table row) — the authoritative statement.:1443("The checkpoint maximum, capped by--request-contextat export") and:1493("The smaller of the prepared context ceiling, capped by--request-context, …") — the PR's own two owner-table rewrites, which say the same thing. Revert them; the flag appears once, in the flag table. ~2 lines.
The row's trailing "a core's catalog is fixed at export, so changing it requires re-export" also copies the clause --mixed-prefill already carries at :447; one clause is enough.
Left behind (dead or inconsistent after this change)
ignition/cli/serve.py:68—max_body_bytesis still sized fromrecipe.context, and:69context_hintstill reads "context is limited by the checkpoint and available cache capacity". Both describe the pre-cap world once--request-contextlowers the served context; if the flag survives, these should follow it in the same change.ignition/cli/help.py:38— still advertises--prefill-chunk-size: 64..{recipe.context}, the recipe max, not the effective prepared context.ignition/bench/runner.py:388— validatescase.context_tokens + required > layout.context(pool-bound), not the new cap; verified in an earlier pass of this review, not re-read this round.- Nothing in
helios/becomes dead: the PR does not touch the runtime, so all of--kv-cache-limitstays live — which is the crux of finding 1.
Count of the change
pr_files at 02023eba: 9 files, +84 / −18 — docs/cli-design.md +3/−2, ignition/cli/__init__.py +2, bench.py +3/−1, preparation.py +1/−1, serve.py +5/−4, planning.py +19/−9, bootstrap.py +1/−1, rebuild_manifest.py +3, tests/cli/test_planning.py +47. Code+docs = +37/−18; tests = +47/−0.
Removable: ≈5 (finding 2) + ≈10 (finding 3) + 2 (finding 4) + 2 (finding 5) + 2 (finding 6) ≈ 22 of the 84 added lines in 4 places with the flag kept; ≈70 of 84 with the flag dropped (finding 1).
Verified load-bearing — do not propose cutting
ignition/preparation/bootstrap.py:58is the entire mechanism; every other hunk forwards to it.- Omitting the flag is byte-equivalent to stock:
context=args.request_contextisNone,context_targetstaysNone,prepared_contextreturnsrecipe.context, which is exactly the pre-PRbootstrap.pyvalue. - All four entry points do forward the flag (
serve.py:207/291/476,bench.py:177, andderive()atpreparation.py:69), andplan()forwards it intofit()at:689. - The manifest records it: reproduction args at
rebuild_manifest.py:264-265, parameter at:389. Plan.__post_init__'s bench check now compares againstprepared_context(planning.py:260) — correct given a cap.Planis frozen with a defaulted field, so existing constructions andreplace()calls are unaffected.
Open questions / what I could not find
- No stated workload that
--kv-cache-limitcannot serve. #454 asked for one; neither the description nor the table answers it, since the table's measurements use that flag. - Nothing was executed. The head has no CI checks. The finding-2 failures are arithmetic plus a read of
_preparation_value; the finding-1 reference tohelios/src/server/config.rs(not opened) and the admission path comes from an earlier pass and was not re-read this round. docs/design-review.md(not opened) was not opened in any pass; the review relies onAGENTS.md, the charter anddocs/cli-design.md.- Stale claims from my earlier notes that are not repeated here: the "+35/−15 across 7 files" figure (superseded by +84/−18 over 9 files) and the two-message prefill-chunk branch (at
02023ebathat hunk is a neutral 3-line → 2-line rewrite, summarised below for completeness, not as a saving).
For completeness, the planning.py:709-711 hunk as it stands at this head is already the single-message form; it saves nothing and removes nothing:
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")