Conventions-and-duplication review of PR #533 "Cap the per-request context target"
PR: https://github.com/NVIDIA/hyperflare-inference/pull/533 — author roobyz (CONTRIBUTOR), open, base main, head de1b5b5, 9 files, +98/−18, no reviews, no CI checks. Supersedes closed PR #454 (same author, same title, closed 2026-11-23 after CHANGES_REQUESTED).
Lens: compare each new construct with its closest in-repository precedent and flag departures, citing the precedent; flag duplicated helpers/abstractions/mechanisms. Every changed file was read in its surrounding code, not only the diff, and callers of the changed behaviour (export, debug-serve, bench, multi-host export, derive/fit/plan, bootstrap.common_preparation_kwargs, rebuild_manifest) were followed.
Rules applied: charter line 13 ("Don't silently ignore API fields… Never accept it and quietly drop it (#417)"); AGENTS.md "Configuration" lines 452-456 (a plan-carried setting must be described by "the plan, its printed report, and its recorded measurements"); docs/cli-design.md §3.1-3.4 and the derived-owner tables.
Key findings
- Should fix — the cap reaches neither the printed plan line (serve.py:302-316) nor the recorded benchmark configuration (bench.py:243-248); every sibling preparation setting appears in both.
- Should fix — the flag's validation is split across
fit(planning.py:461-462) andPlan.__post_init__(planning.py:289-290), against the--prefill-chunk-sizeprecedent that keeps form and range in one block (planning.py:622-625). - Nit —
Plan.prepared_contextrestatesPlan.contextwith one added term, andeffective_context = min(result.context, result.prepared_context)(planning.py:696) never changes the value. - Nit —
to_dict()["context"]keeps reporting the pool-bound limit beside the cap, so the exported JSON names a ceiling the prepared core will reject.
Two findings from an earlier review of this branch are fixed at head de1b5b5 and are not re-raised: _export_hosts now forwards the flag (serve.py:206), and the cap is now recorded in Plan.to_dict() (planning.py:432), reproduction_arguments (rebuild_manifest.py:264-265) and from_plan (rebuild_manifest.py:390, SCOPE_DEPLOYMENT). The earlier "bench should not inherit the flag" concern is also withdrawn: bench.py:177 threads it and planning.py:248 now compares selection.required_context against prepared_context, so bench's --contexts contract is coherent.
Should fix
1. The cap is missing from the printed plan line and the benchmark's preparation record — ignition/cli/serve.py:302-316, ignition/cli/bench.py:243-248
AGENTS.md:452-456: a setting "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 plan JSON and the manifest now satisfy this (planning.py:432, rebuild_manifest.py:264-265, :390); the printed report and the recorded measurements do not.
(a) The printed report. The "Select GPUs" progress line enumerates each preparation choice:
302 stage.update(f"GPU{'s' if plan.world_size > 1 else ''} {indices}{restricted}"
303 f" · concurrency {plan.concurrency} · images {plan.image_concurrency} · …
304 f" · prompt logprobs {'on' if plan.prompt_logprobs else 'off'}"
305 f" · mixed prefill {'on' if plan.mixed_prefill else 'off'}"
306 f" · expert scales {plan.expert_scale_compression or 'native'}"
307 f"{(' · online MXFP8 ' + plan.online_mxfp8_scope) if plan.online_mxfp8 else ''}"
308 f"{' · language model only' if plan.language_model_only else ''}"
…
314 f"{' · joint tuning' if plan.joint_tuning else ''}"
315 f"{' · BF16 sharded hyperconnections' if plan.shard_hyperconnections else ''}"
316 f"{' · row-sharded prefill' if plan.row_shard_prefill else ''}")
--request-context adds no field. ignition export M --gpus 0 --request-context 131072 therefore prints a plan line byte-identical to stock while preparing graphs and KV pages at a different context — the one number that changes the pool size (the PR's own evidence table) is invisible in the terminal. The nearest precedent, row_shard_prefill (line 316), is a one-token addition in exactly this f-string.
(b) The recorded measurements. bench._measure builds details["configuration"]["preparation"] from a whitelist of 17 plan.to_dict() keys (bench.py:237-248): tensor_parallel, prefill_chunk, stream_overlap, context_parallel, context_parallel_size, native_dense_activations, force_moe_decode_a16, autotune_effort, compile_workers, speculative_token_capacity, speculation, expert_scale_compression, mla_compute_mode, row_shard_prefill, online_mxfp8, online_mxfp8_scope, language_model_only. The PR threads the flag into bench (bench.py:177) and adds context_target to to_dict() (planning.py:432), but the key is not whitelisted, so a --request-context benchmark run writes JSON whose configuration does not state the context its graphs were prepared at — a comparison of two runs at different caps records identical configurations.
Fix: add a · request context {plan.prepared_context:,} (guarded so the stock case stays quiet) to the serve.py f-string next to row-shard-prefill, and add "context_target" to the bench.py key tuple next to "row_shard_prefill". Both are one-liners following the adjacent precedent.
Settle-by-check: plan.to_dict() already carries the key (planning.py:432), so (b) is a mechanical omission, provable without a test; a test asserting details["configuration"]["preparation"]["context_target"] for a capped plan would pin it. (a) has no test precedent — the plan-line f-string is untested.
2. One flag's validation is split across two homes — ignition/planning.py:461-462 and ignition/planning.py:289-290
The positive-count check lives in fit:
461 if context is not None and context <= 0:
462 raise UsageError(f"--request-context {context}: a positive token count is required")
The page-multiple check lives in Plan.__post_init__:
289 if self.context_target is not None and self.context_target % self.page_tokens:
290 raise UsageError(f"--request-context {self.context_target:,} is not a multiple of the {self.page_tokens:,}-token page size")
The precedent for a chunk-shaped flag is a single block in plan() owning both its form and its range: --prefill-chunk-size validates "multiple of 64" and the 64..recipe.context bound together (planning.py:622-625). __post_init__ holds cross-field checks that need other plan fields (benchmark selection :230-253, force_moe_decode_a16 :254-263, row_shard_prefill :269-283); a single flag's own form does not belong there.
Why it matters beyond symmetry: fit is called through fitted (planning.py:666) from automatic, candidates and attempt — i.e. the positivity check re-executes for every candidate world size and every retry at a reduced reserve, so a validation that can never differ gets re-run under the search loop while its sibling runs once. And a reader documenting or changing the flag must open two functions to find its rules.
Fix: move the positivity check into Plan.__post_init__ beside the page-multiple check (both there, where page_tokens and recipe.context are available), or move both into plan()'s pre-flight section next to the --prefill-chunk-size block. Either way, one flag, one home.
Settle-by-test: the new test at tests/cli/test_planning.py:234-242 already drives both errors through planning.plan(...), so moving them cannot silently drop a case — the tests pin the behaviour, not the location.
Nits
3. prepared_context / effective_context duplicate Plan.context — ignition/planning.py:366-375, :696
366 def context(self) -> int:
367 """The longest sequence one request may reach."""
368 return min(self.recipe.context, self.tokens)
369
370 @property
371 def prepared_context(self) -> int:
372 """The context the prepared core serves per request; the recipe max when no target is set."""
373 if self.context_target is None:
374 return self.recipe.context
375 return min(self.recipe.context, self.context_target, self.tokens)
The same three-way min is written twice; the context_target is None early return exists only to reproduce recipe.context (which min(recipe.context, tokens) may not equal when the pool is smaller than the recipe max — hence the extra branch rather than a plain fold). Then, because neither property alone is the true served ceiling when a cap is set, plan() needs a reconciling min:
696 effective_context = min(result.context, result.prepared_context)
That min is provably a no-op: with a target, prepared_context = min(recipe.context, target, tokens) <= context; without one, prepared_context = recipe.context >= context. So the code carries two overlapping definitions plus a redundant reduction for a quantity that could be one expression.
This also makes the no-op claim structural rather than fixture-dependent: the test asserts stock_plan.prepared_context == recipe.context (tests/cli/test_planning.py:220), which holds here only because the fixture's pool exceeds the 262144 recipe max — the very definition of prepared_context returning the recipe max regardless of pool size is what the early return buys.
Fix: write prepared_context as min(self.context, self.context_target) when a target is set and self.context otherwise (or keep the docstring's "recipe max" semantic explicit and document the difference from context at the property). Drop effective_context in favour of result.prepared_context at :697, which is already the served ceiling. After that, prepared_context == context on the no-op path and the chunk check reads one name.
4. to_dict()["context"] reports the uncapped limit beside the cap — ignition/planning.py:432
432 "context": self.context, "context_target": self.context_target, "checkpoint_context": self.recipe.context,
The existing pair is checkpoint_context (the recipe's declared maximum) and context (the effective served limit). After this PR the exported core serves prepared_context, yet context still reports min(recipe.context, tokens), so a consumer of the plan JSON reads a limit the core will reject; only the sibling context_target reveals the discrepancy, and only if the consumer knows to combine the three. The new test deliberately pins the current shape (tests/cli/test_planning.py:247: assert d["context"] == capped.context # stock pool-bound value).
Fix: either fold the cap into context (keeping checkpoint_context as the recipe max, as today), or add "prepared_context": self.prepared_context to to_dict() so the served ceiling is named directly, or state in the key's vicinity that context is pool-bound and prepared_context is the served ceiling.
Checked and consistent with precedent (no finding)
ignition/preparation/bootstrap.py:58("context": plan.prepared_contextincommon_preparation_kwargs) is the correct seam: bootstrap.py:24-65 is the single place a plan setting becomesBasePreparationConfig, and every sibling kwarg there is plan-derived the same way. This is what makes the cap reachmax_sequence_tokens, which was the blocking objection in PR #454 ("Preparation passesplan.recipe.contextto every recipe… so a core exported with--context Nstill serves the recipe's full context").- Threading style —
derive(..., context=None)(ignition/cli/preparation.py:56) →planning.plan(..., context=context)(:68) →fit(..., context=context)(planning.py:676) →Plan(context_target=context)(planning.py:537) — matches howrow_shard_prefill/online_mxfp8_scopeare threaded through the same functions, and the parameter is keyword-only with aNonedefault like its neighbours. - All four entry points forward it:
_prepare(serve.py:289),debug_serve(serve.py:472),_export_hosts(serve.py:206) andbench(bench.py:177). No parser-accepts-but-drops gap remains. - Error text follows the house form
UsageError(f"--flag {value}: …")(cf. planning.py:470-471, :503-504), and the chunk-vs-context error split at planning.py:697-700 preserves the stock message for an explicit--prefill-chunk-sizewhile offering a fix for the default chunk; the_shortfall/optionsmachinery (:703-731) is correctly untouched — the cap is not a capacity remedy. - docs/cli-design.md — the new table row matches the table's shape and copies the sibling
--mixed-prefillrow's "Command line only; a core's catalog is fixed at export" clause; the two derived-owner edits attach the cap to the existing "Context limit" rows rather than adding new owners. No wording finding from this lens. - No duplicated mechanism: nothing else in
ignition/caps a prepared context; grep forrequest_context/prepared_context/context_targetreturns only this PR's sites (plus unrelatedheliostest helpers). The nearest existing lever is the runtime--kv-cache-limit context|concurrency, which bounds loaded KV history at serve time and needs no re-export — genuinely distinct, so this is not a duplicate of that flag and PR #454's second objection should not be re-raised on duplication grounds. - Flag grouping (
ignition/cli/__init__.py:167-170, in thecapacity and compressiongroup beside--prefill-chunk-size) is reasonable: both are per-core prepared capacities. Bench inheriting it is coherent now that planning.py:248 comparesrequired_contextagainstprepared_context, and docs/cli-design.md:446 states "Command line only", the same clause its neighbours use. - Tests: the PR's new test (tests/cli/test_planning.py:211-265) covers the no-op path, clamp, both validations,
to_dict()["context_target"], the manifest key/scope and the absent key when unset — following the--row-shard-prefillprecedent in the same file. It does not cover the printed plan line or the bench record (finding 1), nor would a test distinguish the two validation homes (finding 2).
Open questions
- Should the printed plan line show the prepared context only when capped, or always (as
concurrency/imagesare)? Precedent supports either; a maintainer preference decides. - Is
to_dict()["context"]deliberately kept pool-bound (as the new test asserts), or should it become the served ceiling? Only a maintainer can settle whether external consumers depend on the current meaning. - No
Configurationhome exists for the cap (it never reads throughConfiguration, unlike--prefill-chunk-size/--max-concurrency). docs/cli-design.md:446 says "Command line only", which plausibly makes this intentional; if a[preparation] request_contextkey were wanted, that would be a further finding, but the docs row records the decision.
Recommendation
Fix finding 1 (two one-line additions following row_shard_prefill), fold finding 2's two checks into one home, and take the nits as optional cleanup — the prepared_context fold in particular makes the to_dict() question in nit 4 fall out naturally. Nothing here blocks the feature: the seam, the threading, the recording in the plan/manifest, and the tests all follow repository precedent.