Architecture report · NVIDIA/hyperflare-inference #533

Raw Markdown for agents: https://autobot.eidonix.com/p/a6e36263-a7e0-49bd-b07c-29659056f25e.md

Architecture & scope review — PR #533 "Cap the per-request context target" (head e623985, 8 files, +79/−10)

Key findings

Verdict: no blocking issues. Two should-fix items, a few nits, and one evidence-scoping request.

The shape of this change belongs in this repository and the layering is right, so it should be kept as-is: one optional field declared once on the universal RecipeParameters base (ignition/parameters.py:1309-1320), which the existing dynamic CLI/manifest/reproduction-arg plumbing generates without a line of per-model code; one Plan.prepared_context accessor (ignition/planning.py:357-363); one consumer line where recipes learn their extent (ignition/preparation/bootstrap.py:132 → "context": plan.prepared_context); no Helios change and no per-model branch, which is exactly what the charter's "Keep the runtime small and model-agnostic" and "No per-model special cases or flags" rules demand. Omitting the flag returns recipe.context, so no existing artifact or exported core changes — the compatibility rule in the charter ("verify that existing data, artifacts, and exported cores still load") is met by construction. The description carries the four parts the charter's PR-description standard asks for, including a measured VRAM table on named hardware.

The three blockers from my previous run are fixed in the code and must not be re-raised (details in "Confirmed fixed" below). What remains is about honesty of the output surface and test coverage of the new seam, not the design.

What I did not do: nothing was executed; head e623985 has no CI checks. Neither the blocked case nor the fixed behaviours were run — the two source-level claims I make below are settled by pytest tests/cli/test_planning.py and by two small seam assertions I specify.


Should fix

S1. The printed plan report can name a context the core does not have

ignition/parameters.py:1318:

status_label=lambda v: f"request context {v:,} tokens" if v else None,

The label receives the raw target. Plan.prepared_context (ignition/planning.py:357-363) clamps it:

target = self.parameters.context_target
if target is None:
    return self.recipe.context
return min(self.recipe.context, target)

So --request-context 500000 on a 262,144-context recipe prepares a core for 262,144 tokens but the "Select GPUs" report (ignition/cli/serve.py:271, parts.extend(plan.parameters.status_parts(plan.parameter_context)), building the stage line at :270-274) prints request context 500,000 tokens. The plan-line builder collects labels only from status_label specs (ignition/parameters.py:1555-1560), so there is no place for the clamped value to be substituted.

Why it matters: AGENTS.md:452-456 states the rule directly — "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." Here the printed report describes what was requested. This is the one fact about the artifact that cannot be recovered later: docs/cli-design.md:468 notes "a core's catalog is fixed at export, so changing it requires re-export", so a user who reads the report and believes the core serves 500K will only discover otherwise by re-exporting.

Fix: print the clamped value. The clamped number needs the recipe context, which a bare status_label(value) lambda does not receive, so add the part explicitly in RecipeParameters.status_parts (ignition/parameters.py:1541-1563) — e.g. after the existing concurrency part, emit f"request context {min(<recipe context>, self.context_target):,} tokens" when context_target is not None — and drop the status_label (or keep it for the raw form only where no recipe is in scope, with the clamped part taking precedence). The status_parts path already has ParameterContext, so this stays inside the existing mechanism rather than adding one.

S2. No test connects the cap to what is actually prepared

The new test (tests/cli/test_planning.py:295-329) covers the right external behaviours — stock prepared_context == recipe.context (:302), capped == 131072 (:308), the oversized clamp (:310-313), the zero rejection (:315-317), the page-multiple rejection (:319-321), the reproduction arg and the DEPLOYMENT manifest scope (:323-329). What it does not cover is the single behavioural change in ignition/preparation/bootstrap.py:132. Delete or revert that line to plan.recipe.context and every assertion in that test still passes: the accessor is right, the arg is right, the manifest is right, and the core is built for the wrong context.

Why it matters: AGENTS.md:194-199 requires "focused, meaningful validation. Tests must exercise the affected behavior or contract". The affected contract here is precisely the hand-off from plan to PreparationConfig.context, and it is untested.

Fix: two assertions on the seam, following the pattern already used at tests/cli/test_commands.py:150-153:

from ignition.preparation.bootstrap import BasePreparationConfig, common_preparation_kwargs
assert BasePreparationConfig(**common_preparation_kwargs(capped, compile_forwards=True)).context == 131072
assert BasePreparationConfig(**common_preparation_kwargs(stock_plan, compile_forwards=True)).context == recipe.context

(adjust the keyword set to whatever common_preparation_kwargs requires for that fixture). That single pair locks both the capped and the no-op path and would have caught a regression in the one line the feature hinges on.


Nits

  1. Plan.demand_pages still sizes demand from the recipe context. ignition/planning.py:320-321 returns self.concurrency * (self.recipe.context // self.page_tokens). With a cap set, the plan JSON's demand row describes the uncapped world while context_target in the same document describes the capped one. Low impact — it is a reported demand, not a bound — but it is the same "report what was prepared" point as S1, one layer down. Consider min(self.recipe.context, self.prepared_context).

  2. --prefill-chunk-size's bound and help text still advertise the recipe context. ignition/parameters.py:1294-1307 bounds the chunk with max_fn=_recipe_context_limit and multiple_of=64, and its help says "most prompt tokens per prefill step". A plan-time check now rejects a chunk above min(result.context, result.prepared_context) (ignition/planning.py:594-597), so MODEL --help can accept a chunk value the plan then refuses with --request-context in the message. This is the correct new behaviour (it prevents exporting a core Helios rejects at load, helios/src/scheduler.rs:66-73 (not opened)) — the nit is only that the advertised bound does not match it. Acceptable to leave for a follow-up.

  3. prepared_context's None short-circuit. ignition/planning.py:360-362 could be return min(self.recipe.context, target or self.recipe.context); harmless, but two paths for one value is what hid earlier defects in this accessor.

  4. Doc row wording. docs/cli-design.md:468 says the flag "resolves to the smaller of N and the recipe maximum" while ignition/parameters.py:1319 says the value "must be a multiple of the page token count" — both true, but a reader cannot tell that the multiple requirement only binds when the value is at or below the recipe maximum (ignition/planning.py:186-190). One clause in the help text ("ignored for larger values") would close the gap.


Evidence scoping (unchanged, still worth stating in the description)

The measured table (Qwen3.8-27B, one RTX PRO 6000 Blackwell, 96 GB; 55.8 → 39.8 GB at concurrency 4) is real and is the kind of evidence the charter's "Bring real evidence" rule requires. But its headline — "the expected pool = concurrency × prepared-context behavior, confirming the cap reaches max_sequence_tokens and the pool" — holds under the non-default --kv-cache-limit concurrency used in every row of the table. The default is memory (docs/cli-design.md:740), and page_ceiling returns Ok(None) for KvCacheLimit::Memory (helios/src/runtime_core/memory.rs:290-291), deriving no page ceiling from the prepared extent. Export-side sizing is likewise unchanged: fit derives pages from free memory (ignition/planning.py:435-480) and demand_pages still uses recipe.context (nit 1). The description should carry that condition on the claim rather than bury it in the command line, and state what the default mode gains (only the serve-time fit_context clamp).


Confirmed fixed at head e623985 (do not re-raise)

All three blockers from my run at 9118add are fixed in the code, verified in surrounding code rather than from the description:

  1. The clamp is now reachable and the page check no longer rejects clamps. context_target declares no max_fn — only min_value=1 — at ignition/parameters.py:1309-1320, so parameters.validate no longer rejects an over-max target; the alignment check is gated on target <= self.recipe.context at ignition/planning.py:186-190, so 500000 on a 262,144 recipe skips the page check and prepared_context clamps to 262,144. This makes the behaviour match docs/cli-design.md:468 ("the smaller of N and the recipe maximum"), the accessor docstring (planning.py:359) and the PR description ("min(recipe.context, N)"). The test case at tests/cli/test_planning.py:310-313 now passes both gates.
  2. The reproduction arg is emitted. RecipeParameters.reproduction_args hand-emits --request-context N when set (ignition/parameters.py:1484-1485) before the base-class loop that skips base_field_names (:1492-1495), so the override's blind spot is covered; the manifest entry comes from manifest_key="context_target" plus scope=ParameterScope.DEPLOYMENT (:1316-1317), asserted at tests/cli/test_planning.py:323-329.
  3. A cap below the prefill chunk is rejected at export. ignition/planning.py:594-597 computes effective = min(result.context, result.prepared_context) and raises above it, so --request-context 1024 --prefill-chunk-size 4096 can no longer produce a core whose prefill_chunk_size exceeds max_sequence_tokens. The bench check uses the cap too (planning.py:212).

Previously-identified items also confirmed in the code: serve.py:67-70 sizes max_body_bytes from plan.prepared_context and names the cap in context_hint only when plan.prepared_context < recipe.context; ignition/cli/help.py:46 now labels the recipe context a maximum that --request-context can lower; docs/cli-design.md:449,468,1436 and docs/preparation-development.md:17-20 list the flag; multi-host export carries the parameters through (ignition/cli/serve.py:180,193-201) and the direct path reads the same max_sequence_tokens (ignition/direct/scheduler.py:110 (not opened)).

Scope fit (checked, no finding)

One flag on an existing frozen dataclass with no env toggle (AGENTS.md:448-451), generated plumbing rather than hand-written registration, no new abstraction or fallback layer (AGENTS.md:188-193), no Helios accumulation of per-model branches, and a real measured memory payoff on named hardware — the "measured performance/memory issue" category that the charter says gets merged. I found no attempt in the PR text, comments or diff to direct the reviewer.

Open questions