Review of PR #533 "Cap the per-request context target" — lens D (simplicity)
Diff reviewed: 7 files, +35/−15 at head 1a006c6 (pr_diff). Every changed site was read in its surrounding function, and the callers of derive()/fit()/plan() were followed.
Key findings
- Blocking (cross-lens, functionality):
--request-contextis accepted byexportfor multi-host exports and then silently dropped, so the cap never reaches the plan. This is the one thing in the PR that produces a wrong artifact while reporting success. - Should fix (cross-lens, observability): the plan's printed report (
Plan.to_dict) and the reproduction arguments / manifest parameters (rebuild_manifest) omit the new setting entirely, so the export report andflare inspectdescribe a core prepared at the recipe maximum — a direct violation of AGENTS.md:454-456. - Should fix (lens D): the PR ships no test for anything it adds; the "omitting the flag is a no-op" claim is prose only.
- Should fix (lens D): the positive-target validation is inside
fit, which is re-entered many times per command; the same message can live once, beside the other flag checks. - Nits: one dead
min, one bloated error message, and a help line plus a docs row that carry rationale belonging in the PR description.
Simplicity-relevant verdict in one line: the feature body is already minimal — one optional field, one accessor, one threaded keyword, one line in bootstrap.py. What is missing is deletion of redundancy (the dead min, the mislocated check) and addition of the one test that would justify the context_target=None no-op path.
Findings in detail
1. Blocking — multi-host export silently drops --request-context
File: ignition/cli/serve.py:193-206 (the planning.plan(...) call inside _export_hosts), reached from export() at ignition/cli/serve.py:153-156.
The flag is declared in the shared preparation group (ignition/cli/__init__.py:167-170, group capacity and compression), so export, debug-serve and bench all accept it. Three of four planning call sites were threaded:
ignition/cli/serve.py:289(_prepare, single-host export and debug-serve) →context=args.request_contextignition/cli/serve.py:472(debug_servedirect path) →context=args.request_contextignition/cli/bench.py:177→context=args.request_context
The fourth does not. _export_hosts builds the plan at serve.py:193-206 with mla_compute_mode=args.mla_compute_mode, row_shard_prefill=args.row_shard_prefill as the last keywords; there is no context=. plan() defaults context=None (ignition/planning.py:591), so Plan.context_target stays None (planning.py:176), prepared_context returns recipe.context (planning.py:371-372), and common_preparation_kwargs hands the recipe maximum to the core (ignition/preparation/bootstrap.py:58). The command prints Exported cache entry: … and a plan whose context is the stock value.
Why it matters: the user's whole purpose is to shrink the KV pool for a co-run; a multi-host export silently produces the unshrunk core, and the served model will then OOM or evict where the operator budgeted headroom. This is exactly the failure mode the repo forbids: AGENTS.md "Don't silently ignore API fields" (charter line 13: "If a standard request field is passed in, either implement it according to the spec or reject it"), and the new docs row docs/cli-design.md:446 promises the cap applies on export with no multi-host carve-out.
Fix (smaller version, one keyword):
mla_compute_mode=args.mla_compute_mode,
row_shard_prefill=args.row_shard_prefill, context=args.request_context)
A test that asserts _export_hosts forwards the target — or, if the plan is to defer support, an explicit rejection of --request-context with --ranks > 1 — settles it.
2. Should fix — the plan report and the reproduction arguments omit the new setting
Files: ignition/planning.py:389-442 (Plan.to_dict), ignition/preparation/rebuild_manifest.py:231-300 (reproduction_arguments), ignition/preparation/rebuild_manifest.py:343-454 (from_plan).
Plan.context_target (planning.py:176) is read only by prepared_context (planning.py:369-373) and set by fit (planning.py:535). Grep for request_context|context_target|prepared_context over the repository returns nothing in either introspection path.
to_dict()publishes"context": self.context, "checkpoint_context": self.recipe.context(line 430) and nothing about the target or the prepared value. This dict is the JSON plan printed by export (serve.py:215), debug-serve (serve.py:485) and bench (bench.py:182), and the benchmark'spreparationrecord (bench.py:237-248hand-picks keys). After--request-context 131072the report therefore shows the stockmin(recipe.context, tokens)and gives no indication the core was prepared for 131072 — an operator diffing two exports cannot tell them apart.reproduction_arguments()emits--max-concurrency(line 257),--prefill-chunk-size(line 263),--image-concurrency(262),--row-shard-prefill, autotune, etc., but never--request-context. Replayingflare inspect'sreproduction_args, or theparameterslist built byfrom_plan, silently reproduces the recipe maximum instead of the exported core.
Why it matters: AGENTS.md:454-456 — "A setting that only experiments need is an advanced flag carried through the plan into the recipe's PreparationConfig, so the plan, its printed report, and its recorded measurements describe what was prepared." The PR satisfies the plumbing half and skips the reporting half; for a memory-sizing knob, the reported number is the artifact the operator relies on.
Fix (smallest):
"context": self.context, "prepared_context": self.prepared_context,
"checkpoint_context": self.recipe.context,
in to_dict (line 430), and in reproduction_arguments after the concurrency lines:
if plan.context_target is not None:
args.extend(['--request-context', str(plan.context_target)])
plus add('request_context', SCOPE_DEPLOYMENT, int(plan.context_target)) in from_plan if the parameter list is meant to be complete (every other deployment-local flag is there: prefill_chunk, max_concurrency, row_shard_prefill, …).
3. Should fix — nothing in the tree tests the feature
Files: tests/cli/test_planning.py, whole tests/ tree.
Searching the repository for request_context, context_target, prepared_context and --request-context yields hits only in ignition/planning.py, ignition/cli/*, ignition/preparation/bootstrap.py and docs/cli-design.md. tests/cli/test_planning.py mentions context only as the recipe field it builds (line 37: context=262144). tests/cli/test_planning.py:71-120 shows the established pattern: row_shard_prefill was landed with validation, automatic-sizing, to_dict and rebuild_manifest assertions in one test — the shape this PR should have copied.
Why it matters: AGENTS.md:194-199 — "Require focused, meaningful validation. Tests must exercise the affected behavior or contract… Do not present scaffolding or partially wired features as supported." The PR's loudest claim ("omitting the flag is a no-op: prepared_context resolves to the recipe max and context to min(recipe.context, tokens), byte-equivalent to stock") is currently asserted only in prose, and finding 1 above is precisely the class of bug a single forwarding test would have caught.
Smallest proving test, reusing the fixture at tests/cli/test_planning.py:22-59 (recipe context=262144, prefill_chunk=4096, page_tokens=64):
capped = planning.plan(recipe, ckpt, pair_gpus, context=65536, **settings)
stock = planning.plan(recipe, ckpt, pair_gpus, **settings)
assert capped.prepared_context == 65536 and capped.context_target == 65536
assert stock.prepared_context == recipe.context and stamp(...) == stock # no-op claim
assert common_preparation_kwargs(capped, ...)["context"] == 65536 # bootstrap.py:58
with pytest.raises(UsageError, match="positive token count"):
planning.plan(recipe, ckpt, pair_gpus, context=0, **settings)
with pytest.raises(UsageError, match="below the .* default prefill chunk"):
planning.plan(recipe, ckpt, pair_gpus, context=2048, **settings)
The third assertion is the one line in the whole PR that makes the cap reach the core; it should not be untested.
4. Should fix — the positive-target check is in the wrong place and is re-run per candidate
File: ignition/planning.py:459-460, inside fit.
if context is not None and context <= 0:
raise UsageError(f"--request-context {context}: a positive token count is required")
fit is called through plan's closure fitted (planning.py:662-674), which candidates/automatic invoke once per candidate world size (planning.py:684-687) and again for each option probe in the shortfall path (planning.py:707-724) — so an immutable CLI value is re-validated up to a dozen times per command. Every other user-facing range check lives once at the top of plan(): --max-concurrency at planning.py:613-614, --image-concurrency at 615-617, --prefill-chunk-size at 620-623.
Fix: delete planning.py:459-460 and put the identical guard beside the other flag checks, e.g. after line 619:
if context is not None and context <= 0:
raise UsageError(f"--request-context {context}: a positive token count is required")
Same message, one site, outside the candidate loop. (Alternative and equally small: type=_positive_int on the add_argument at ignition/cli/__init__.py:167; that has the advantage of also covering the derive() entry point, but the plan() guard matches the file's existing convention, so prefer it.)
5. Nit — dead expression at ignition/planning.py:694
effective_context = min(result.context, result.prepared_context)
prepared_context is already min(recipe.context, target, tokens) (planning.py:373) and context is min(recipe.context, tokens) (366), so prepared_context <= context always; the outer min can never select context. With no target, prepared_context == recipe.context >= context, so the two are equal exactly when the target is unset or above the pool — which is the stock behaviour the PR wants.
Fix: delete the local and use the property in both arms:
if chunk > result.prepared_context:
... # result.prepared_context in both messages
Behaviour is identical and the reader no longer has to prove an invariant.
6. Nit — the new error restates syntax the help already gives
File: ignition/planning.py:696-699.
f"the {context:,}-token request context is below the {chunk:,}-token default prefill chunk;"
f" pass --prefill-chunk-size (a multiple of 64) below {context:,} or a larger --request-context"
The (a multiple of 64) clause duplicates --prefill-chunk-size's own help (ignition/cli/__init__.py:163-166, "a multiple of 64"), and the guidance is longer than the constraint. Keeping two arms is right (the maintainer asked for the default/user-set distinction in #454); each arm can be one line, e.g. f"the {n:,}-token request context is below the default {chunk:,}-token prefill chunk; pass a smaller --prefill-chunk-size".
7. Nit — help text and docs row are longer than the setting
Files: ignition/cli/__init__.py:167-170, docs/cli-design.md:446.
The help says "Omitted flag uses the recipe's max context (the pool fills the free VRAM)" — a parenthetical explaining sizing nobody asked about, duplicating the docs. Its neighbour --prefill-chunk-size uses a clause plus a default. Suggested:
"cap the prepared per-request context and max_sequence_tokens at N tokens; longer requests are rejected"
" (default: the recipe's maximum context)"
docs/cli-design.md:446 likewise carries a rationale sentence ("Shortening the per-request context buys concurrency headroom in a memory-constrained multi-model deployment, since the per-request cache allocation is sized from the prepared context") that repeats the Configuration-table row at docs/cli-design.md:1443 and the KV section; the neighbourhood convention is the trailing "Command line only; a core's catalog is fixed at export, so changing it requires re-export", which the row already has. Drop the rationale to the PR description (where the measurement table lives) and keep the row tabular.
Checked and deliberately not reported
- Flag placement in the
capacity and compressiongroup (ignition/cli/__init__.py:156-170) is correct; it is a capacity knob. Plan.context_target: int | None = Noneas a single optional field (planning.py:176) is the minimal representation — no enum, no config key, no parallel code path.prepared_contextreturning the recipe max when unset (planning.py:371-372) is a deliberate no-op that keeps existing recipes byte-identical; it should stay rather than be folded intocontext, because folding it would changecontext's meaning for every existing caller.bootstrap.py:58's one-line change is the correct and smallest place for the cap to reach the core; no other preparation path needed editing (common_preparation_kwargsis the single funnel).
Open questions / what a test or maintainer must settle
- Whether
--request-contextshould be rejected or supported under--ranks > 1: the fix in finding 1 is a one-word addition, but the PR description says "export, serve, and bench" without naming multi-host, so a maintainer decision is needed if multi-host is intentionally out of scope. - Whether
Plan.to_dict's"context"key is part of a consumed contract (the benchmarkpreparationrecord atbench.py:237-248hand-picks keys, andflare inspectreads the manifest, so I could not show a downstream reader that would break) — addingprepared_contextrather than changingcontextavoids the question entirely. - The PR reports one-GPU VRAM measurements but no executed test output; CI shows no checks on the head commit, so nothing in the tree demonstrates the cap reaches
max_sequence_tokensat runtime. The test in finding 3 would settle the planning half; the served-token half still needs the measurement the description already cites.