Correctness review — PR #533 "Cap the per-request context", head 448f70a7
Key findings
Verdict: should fix — no blocking defects remain at this head.
Every defect I raised against earlier heads is fixed and re-verified in the code at 448f70a7, not merely claimed in the description:
- The new test no longer raises without FlashInfer —
tests/cli/test_planning.py:296stubssource_identity, like the neighbouring tests at :159/:223/:339. - The bench check is now pool-aware —
ignition/planning.py:212compares againstmin(self.context, self.prepared_context), so an uncapped, pool-limited plan keeps main's bound and does not defer failure toignition/bench/runner.py:388(not opened). - The printed plan reports the served extent —
ignition/planning.py:396emits"prepared_context": self.prepared_contextbeside"context", so the{"plan": …}printed byignition/cli/serve.py:206,:435andbench.py:194shows what is exported asmax_sequence_tokens. - The status line shows the clamped value —
ignition/parameters.py:1560-1561printsmin(self.context_target, context.recipe.context), matchingPlan.prepared_context(planning.py:358-363), so--request-context 500000on a 262,144-token recipe reports 262,144. - The prefill-chunk bound uses the cap —
planning.py:594-597rejects a chunk abovemin(result.context, result.prepared_context)at export rather than leaving Helios to refuse the core at load time. - The cap is reproduced —
--request-contextis hand-emitted inRecipeParameters.reproduction_args(parameters.py:1483-1484) ahead of the base-class-field skip (:1491-1495), sorebuild_manifest.reproduction_argumentscarries it.
What remains is one should-fix about where the page-alignment rule is enforced and described, plus four nits and three untested paths listed below.
The lens found nothing else wrong: the uncapped path is behaviour-identical to main, the clamp branch is reachable and aligned, the manifest/reproduction plumbing composes, the Helios contract the export must satisfy is met, and the admission consequence the docs claim exists does exist.
Should fix
1. ignition/parameters.py:1318 and ignition/cli/help.py:46 — the page size named to the user is not the page size the check uses, and the check fires only after model resolution and GPU discovery.
parameters.py:1318tells the user the cap "must be a multiple of the page token count", andhelp.py:46namesrecipe.page_tokensas "page size".- The actual check is
target % self.page_tokens != 0inPlan.__post_init__(planning.py:186-190), andPlan.page_tokensisself.parameters.adjust_page_tokens(self.recipe.page_tokens, self.parameter_context)(planning.py:324-325; the hook chain isparameters.py:571-575) — i.e. the world-size-dependent page, not the recipe's. - It also runs late:
context_targetdeclares onlymin_value=1(parameters.py:1315) and nomultiple_of, so the CLI resolver (ignition/cli/preparation.py:55-59) accepts any positive integer; the rejection arrives inside planning, after checkpoint resolution and GPU discovery. Compareprefill_chunk, which declaresmax_fn=_recipe_context_limitandmultiple_of=64inline (parameters.py:1300-1302) and so fails during argument validation. - Why it matters: on any recipe whose
adjust_page_tokenshook changes the page — the row-shard/hyperconnection parameters this repo's hook system exists for (docs/preparation-development.md:30-34) — a user who followsMODEL --helpand aligns the cap torecipe.page_tokensgets aUsageErrornaming a different page size, after the expensive resolution steps. The PR description's claim that values above the recipe maximum are no-ops is correct (planning.py:187gates the check ontarget <= self.recipe.context), so the misdirection only affects in-range caps. - Fix (either is sufficient): give the field a
multiple_of-equivalent check that runs at resolution, asprefill_chunkdoes; or state in the field help andmodel_epilogthat the multiple is the plan's page size, not the recipe's.
Nits
a. ignition/parameters.py:1560-1561 — status_parts dereferences context.recipe without a None guard. Every other label in that loop reads only the field value (spec.status_label(getattr(self, dc_field.name)), parameters.py:1557), and ParameterContext.recipe defaults to None (parameters.py:119). No current caller passes a recipe-less context — the only call is serve.py:271 with plan.parameter_context (planning.py:224-232) — but status_parts is documented as a general Plan hook (docs/preparation-development.md:30-34) and is trivially callable as RecipeParameters().status_parts(ParameterContext()) in a test. Guard with context.recipe is not None.
b. ignition/planning.py:320-321 — demand_pages still uses the uncapped demand, and is printed. demand_pages = self.concurrency * (self.recipe.context // self.page_tokens) and it reaches the plan report at to_dict (planning.py:407). A capped plan's printed demand_pages overstates by concurrency * (recipe.context - prepared_context) / page_tokens — exactly the quantity the PR's VRAM table measures. demand_pages has no consumer other than to_dict, so self.prepared_context // self.page_tokens would describe what was prepared. This bears on AGENTS.md:452-456: an advanced flag must be "carried through the plan into the recipe's PreparationConfig, so the plan, its printed report, and its recorded measurements describe what was prepared" — the report is now half-right (prepared_context right, demand_pages wrong).
c. tests/cli/test_planning.py:302-314 — most assertions restate inputs and defaults. context_target is None, capped.parameters.context_target == 131072, oversized.parameters.context_target == 500000 and stock_plan.context == min(recipe.context, stock_plan.tokens) restate what was just passed in or what main already returns. The semantically loaded assertions are :309, :314 and :318-319.
d. tests/cli/test_planning.py:335 — the manifest assertion checks scope, not value. _preparation_value writes non-negative ints to uint_value (ignition/preparation/rebuild_manifest.py:270-274), so by_key["context_target"].value.uint_value == 131072 would catch a wrongly recorded cap; today only the enum is compared.
Untested paths (state as unverified, not as broken)
- Chunk-vs-cap rejection at
planning.py:594-597: no test pairs e.g.context_target=2048withprefill_chunk=4096. Settle withignition export … --request-context 2048 --prefill-chunk-size 4096(expect the "--prefill-chunk-size … exceeds the …-token context this plan allows" error) or a unit test. - Multi-host:
ignition/cli/serve.py:180/:198resolve parameters fromargsfor--ranks; the cap is now present on that path (it was the earliest blocker on this PR), but no test drives_export_hostswith a cap. Settle with an--ranks 2export in a multi-host fixture, or by asserting the forwardedPreparationConfig.context. - The recipe-side consumer: no test drives a recipe whose
preparereadsconfig.contextfromcommon_preparation_kwargs(ignition/preparation/bootstrap.py:123-137, key at :132). The new test asserts the dict (test_planning.py:316-319), which is the seam, not its consumption.
Verified clean through this lens
- No-flag equivalence.
prepared_contextreturnsself.recipe.contextwhen no target is set (planning.py:361-362) — exactly whatbootstrap.pypassed before the PR — so uncapped exports are sized identically;guaranteed_tokens(planning.py:366-368) reduces to the old expression. - Clamp branch reachable and aligned. The page check is gated on
target <= self.recipe.context(planning.py:187), so an above-maximum unaligned target (500000) resolves to the aligned recipe maximum instead of raising — matchingtests/cli/test_planning.py:311-314anddocs/cli-design.md:458(not opened). - Error messages match the test patterns.
min_value=1→ "--request-context must be a positive integer" (parameters.py:541-542); 100 on a 64-token page → "… is not a multiple of the 64-token page size" (planning.py:188-190). - Manifest plumbing.
manifest_key="context_target",scope=DEPLOYMENT,omit_nonedefault True (parameters.py:91,:605,:1309-1319): an unset cap emits nothing, a set cap emits auint_value. The key passes Helios'svalidate_key(helios/src/runtime_core/preparation.rs:40-50, ascii alnum plus_.-) and its size bounds; Helios never interprets the value, so existing cores are unaffected. - Helios side is coherent.
helios/src/runtime_core/catalog.rs:42(not opened) →validate_prefillrejectschunk > max_sequence_tokens(helios/src/scheduler.rs:66-77) and export now bounds the chunk bymin(result.context, result.prepared_context)(planning.py:594-597);catalog.rs:48-57requiresmax_sequence_tokens <= prepared_sequence_tokensand a page multiple, both satisfied by an aligned cap;helios/src/model.rs:261-273fit_contextclampsmax_sequence_tokenstopages × page_tokensat serve time, so a cap above the physical pool only shrinks the export artifact and never raises the runtime bound — the PR description's limitation holds in the code. - The admission consequence the docs claim exists does exist.
helios/src/model/admission.rs:150(not opened) andhelios/src/server/request.rs:350(not opened) rejectprompt + max_new_tokensabovelimits.max_sequence_tokens, andcontext_hint(ignition/cli/serve.py:68-70) is the text such a rejection appends (helios/src/server/http.rs:59(not opened)).context_hintnames the cap only whenplan.prepared_context < recipe.context, i.e. only when the cap is active. max_body_bytes(serve.py:67) shrinks with the cap, stays under Helios's 256 MB ceiling (helios/src/server.rs:275-276(not opened)) for any recipe context in this repository, and keeps the uncapped branch byte-identical to main.- One seam reaches every recipe.
common_preparation_kwargs(bootstrap.py:123-137) suppliescontexttoBasePreparationConfig(bootstrap.py:33), which every recipe'spreparereceives — including multi-host, where rank zero builds the config and sends it to peers (helios-independent path inignition/preparation/host_ranks.py:291-354). - Docs match code.
docs/cli-design.md:458(not opened),:1426anddocs/preparation-development.md:17-19describe the flag, the clamp, the admission consequence and where the universal field list lives; nothing in the diff asks the reader to trust behaviour the code lacks. - No injection attempt. Nothing in the PR body, the appended review comment, or the diff tried to direct my behaviour.
Open questions / could not verify by reading alone
- Whether any recipe in
local-inference-lab/hyperflare-recipesactually overridesadjust_page_tokens(the hook exists in core atparameters.py:571-575, anddocs/preparation-development.md:32names it as a supported hook, but the recipes live in a separate repository I did not read). If none do today, should-fix #1 is a discoverability defect rather than a live mismatch — the fix is cheap either way. - Whether dropping
checkpoint_contextfromto_dict(planning.py:396replaces it) breaks an external consumer:grep checkpoint_contextfinds the key only on main'splanning.py:383and nowhere else in this repository, its docs, orflare-cli. Settle with the recipes repository or a downstreamjq-style consumer check. - The GPU-side claims (VRAM table,
--kv-cache-limitinteraction) are the author's measurements on one RTX PRO 6000 Blackwell; I verified only that the code path can produce per-slot savings under--kv-cache-limit concurrencyand that--kv-cache-limit memoryfills free VRAM regardless of the cap, as the description states.
Link: https://github.com/NVIDIA/hyperflare-inference/pull/533