Code review summary report · NVIDIA/hyperflare-inference #533

Raw Markdown for agents: https://autobot.eidonix.com/p/387b105d-9b94-465b-b1d3-343de9035bcc.md

FULL REPORT — PR #533 "Cap the per-request context target"

PR: https://github.com/NVIDIA/hyperflare-inference/pull/533 — author roobyz, base main, head 1a006c6, 7 files, +35/−15, no reviews, no CI checks. Supersedes closed PR #454 (same author, same title, CHANGES_REQUESTED by yatesdr 2026-11-23).

Verdict: Changes Requested. The design is right and the seam is now correct. ignition/preparation/bootstrap.py:58 changes "context": plan.recipe.context to plan.prepared_context, and common_preparation_kwargs (bootstrap.py:47-65) is the single funnel into BasePreparationConfig.context (bootstrap.py:33). That value reaches Helios as prepared_sequence_tokens (helios/src/server/config.rs:131) and limits.max_sequence_tokens (:148), enforced at admission (helios/src/server/request.rs:350 (not opened), scheduler.rs:2289 (not opened)/:2358) — which closes #454's blocking objection ("Preparation passes plan.recipe.context to every recipe"). The delta is a smaller prepared context and a smaller KV pool, not just a serve-time bound: --kv-cache-limit cannot lower the ceiling a core advertises, so the flag is genuinely distinct and should stay.

What remains is that the flag does not reach one path, is validated incompletely, and is recorded nowhere.

Key findings


Blockers

1. --request-context is silently ignored on the multi-host export path

File: ignition/cli/serve.py:193-206 (reached from export() at :153-156 when args.ranks > 1)

_export_hosts builds its own plan and its keyword list ends at row_shard_prefill=args.row_shard_prefill (:206). There is no context=args.request_context, although --request-context is registered by _preparation_arguments (ignition/cli/__init__.py:167-170), which export shares — the attribute exists on args, it is simply never read. plan() defaults context=None (planning.py:591), so context_target stays None, prepared_context returns recipe.context (:371-372), and bootstrap.py:58 hands the recipe maximum to the core.

The three other paths do thread it: _prepare (serve.py:289), debug_serve (serve.py:472), bench.run (bench.py:177). A search for request_context across ignition/ returns exactly those three sites plus planning.py itself.

Why it matters: ignition export MODEL --ranks 2 --rendezvous … --request-context 131072 parses, prints a plan, and prepares at the recipe maximum with no warning and no error. Multi-host is a supported shape (AGENTS.md:157-163) and is exactly where the pool is largest, so the user loses the entire benefit and cannot see it — the failure mode the charter names explicitly ("Don't silently ignore API fields … Never accept it and quietly drop it (#417)"). It also violates AGENTS.md:452-456, since the setting does not even reach the plan. The PR's own docs row (docs/cli-design.md:446) promises the cap applies at export with no multi-host carve-out, and _export_hosts already forwards --prefill-chunk-size, --mixed-prefill, --roce-ring, --dcp-size and the online-MXFP8 flags, so forwarding is the consistent fix.

Requested change: add context=args.request_context to the planning.plan(...) call at serve.py:206. One keyword.

Settle by test: a planning-level assertion that a one-host and a two-host plan of the same recipe yield the same prepared_context (or that common_preparation_kwargs(plan)["context"] honours the flag) keeps the three call sites from drifting again.

2. The cap is never required to be page-aligned, so the exported core can fail to load

Files: ignition/planning.py:369-373 (producer), :459-460 and :694-700 (the only validations), ignition/preparation/bootstrap.py:58 (consumer), helios/src/model/catalog.rs:50-57, :70 (rejection)

return min(self.recipe.context, self.context_target, self.tokens)

The only checks performed are positivity (planning.py:459-460) and the prefill-chunk comparison (:694-700). Nothing anywhere requires the result to be a multiple of page_tokens. Helios requires both the prepared length and limits.max_sequence_tokens to be exact multiples of the page size:

|| !config.prepared_sequence_tokens.is_multiple_of(page_tokens.max(1))
|| !config.limits.max_sequence_tokens.is_multiple_of(page_tokens)
...
    return Err("invalid prepared model configuration".into());   // :70

Why it matters: stock is safe only because recipe.context is a declared page multiple; a user value is the first unaligned input on this path, and every alignment check lives after export. ignition export MODEL --request-context 200000 with a 128-token page is 1562.5 pages: preparation, tuning and export all succeed, then flare run dies with a generic error that names neither the flag nor the page size. The charter's Code Review Standards require that "exported cores still load".

Requested change (smallest, one home): validate in Plan.__post_init__ (planning.py:212-289, where plan-field invariants already live) that context_target % self.page_tokens == 0 — reject with the nearest lower multiple, or floor the way guaranteed_tokens already floors (:378). Fold the <= 0 check from :459-460 into the same place so it cannot be bypassed by a direct Plan construction, and delete :459-460 (it is currently re-run once per candidate world size through plan()'s fitted() closure, :662-674, and again per shortfall probe, :707-724). Validate context_target, not prepared_context: page_tokens is 0 before fit's replace (:541).

Caveat: recipes live in the external hyperflare_recipes repository (AGENTS.md:381), so a recipe's prepare() could in principle re-round the value. Nothing in this repository does. One unaligned export on a 128-token-page recipe followed by flare run settles it.

3. The cap is absent from the plan report and the rebuild manifest

Files: ignition/planning.py:389-442; ignition/preparation/rebuild_manifest.py:231-318, :343-395; consumers ignition/cli/serve.py:215, :485, ignition/cli/bench.py:182, :243-248

Three reporting surfaces omit the new setting:

Why it matters: AGENTS.md:452-456 — a preparation setting is "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. This also makes the description's measurement table impossible to reproduce from a package, and it masks blocker 1 (an export that ignores the flag looks identical to one that honours it). Note the core's own catalog is correct — flare-cli/src/inspect.rs:263 (not opened)/:805/:993 read max_sequence_tokens from the core — so this is a report/manifest gap, not a core defect.

Requested change: add "prepared_context": self.prepared_context (and/or "context_target") beside "context" in to_dict; in reproduction_arguments emit --request-context str(plan.context_target) behind if plan.context_target is not None; in from_plan add add('request_context', SCOPE_DEPLOYMENT, plan.context_target) — its add() already skips None (:348-350), so uncapped packages stay byte-compatible. Scope is a maintainer call: the prepared context shapes the exported contract, which reads like SCOPE_COMBINE, but prefill_chunk also shapes it and is recorded SCOPE_DEPLOYMENT; follow that precedent unless told otherwise.

4. The VRAM benefit is stated unconditionally, but depends on the runtime --kv-cache-limit

Where: PR description ("Evidence", "Result") and docs/cli-design.md:446 (added by this PR); mechanism at helios/src/runtime_core/memory.rs:284-331

The claim under review: "capping the prepared per-request context with --request-context shrinks the KV pool and frees VRAM — at concurrency 4 the 131072 cap frees 16 GB vs the 256K default"; and the docs row's "Shortening the per-request context buys concurrency headroom … since the per-request cache allocation is sized from the prepared context."

page_ceiling shows the pool tracks the prepared context only under two of three modes:

if mode == KvCacheLimit::Memory {
    return Ok(None);          // no ceiling at all
}
let histories = if mode == KvCacheLimit::Concurrency { active } else { 1 };

The default is memory (docs/cli-design.md:738, :828: "--kv-cache-limit memory uses the remaining memory budget for KV"). The author's own evidence command includes --kv-cache-limit concurrency, so the table measures the cap conditioned on that flag — and under memory the pool is filled from free memory, bounded by the prepared virtual extent (memory.rs:403, :435), whose page maximum comes from recipe code outside this tree (AGENTS.md:379-381).

Why it matters: AGENTS.md:134-137 forbids publishing a claim whose rationale, benefit, evidence "or material limitations must be guessed". A reader will expect the export-side cap alone to free VRAM, will not see it on a default flare run, and the misstatement ships in docs/cli-design.md.

Requested change: state the condition in both places — "with --kv-cache-limit context or concurrency; the default memory sizes the pool from free memory regardless of the prepared context" — or add one default-mode measurement row.


Should Fix

5. Benchmark validation still measures against the uncapped context

Files: ignition/planning.py:248; ignition/bench/runner.py:388 (not opened); precedent ignition/cli/bench.py:115-116

if selection.required_context > self.context:
    raise UsageError("benchmark workload and output allowance exceed the prepared context")

self.context is untouched by this PR (planning.py:363-366), so with a cap set the check compares the workload against a context larger than the core serves, and the real failure lands in bench/runner.py:388 (not opened) ("benchmark case exceeds prepared capacities") — after the whole GPU preparation, autotuning and CUDA-graph capture. The PR already gets the analogous case right for the prefill chunk (:694-700), so this reads as an oversight.

Requested change: compare self.prepared_context (available there because bench sets benchmark_selection via replace at bench.py:178, after pages exist) and mention the cap in the message; or reject the flag in bench the way --mixed-prefill is rejected (bench.py:115-116). Either is smaller than what is there now; do not add a third mechanism.

6. Nothing in the tree tests any of this

Files: tests/cli/test_planning.py, tests/cli/test_commands.py (not opened)

The diff adds no tests and tests/ has no match for request_context, prepared_context or context_target. Untested new behaviour: the omitted-flag no-op, the pool clamp, the <= 0 rejection, the new alignment rule (blocker 2), both branches of the chunk error, and the one line at bootstrap.py:58 that makes the cap reach the core. The PR's loudest claim ("omitting the flag is a no-op") is currently prose only, and blocker 1 is exactly the class of bug one forwarding assertion would have caught. AGENTS.md:194-199 requires tests for affected behaviour.

Requested change: one case in tests/cli/test_planning.py on the existing fixture (_recipe at :22-54: context 262144, page_tokens 64, prefill_chunk 4096; _gpu at :57-59) covering: unset target → prepared_context == recipe.context; target 65536 → 65536; target above the pool → tokens; context=0 → UsageError; an unaligned target → the new rejection; common_preparation_kwargs(plan, ...)["context"] == plan.prepared_context; and to_dict/manifest/reproduction-arg keys, following the existing row_shard_prefill loop at :92-106. Plus one assertion that the multi-host path forwards the flag. Only the end-to-end VRAM claim needs the RTX PRO 6000; the arithmetic and the errors do not.

7. The justification argues from a charter non-goal

Where: PR description ("Why", "Result") and docs/cli-design.md:446

The description's "why" is "leave no room for a second model", the result closes with "the headroom a co-run needs", and the docs row says "in a memory-constrained multi-model deployment". AGENTS.md:171-175 lists multi-model hosting and routing as requiring an explicit maintainer decision before implementation, and none is cited. The code itself is fine — a preparation capacity is in scope — but the purpose is written from the one framing the project treats as needing separate sign-off.

Requested change: give the single-model rationale (a lower prepared context shrinks the KV pool, leaving more of the fixed budget for prefix-cache snapshots or a higher --max-concurrency on the same GPU), or cite the maintainer decision. Do not weaken the rule.

8. The new default-chunk error can recommend a remedy that cannot work

File: ignition/planning.py:692-701

effective_context can be pool-bound: result.context is min(recipe.context, tokens) (:363-366), so on a small GPU the number is set by page supply and the user may never have passed --request-context at all. The message then says "or a larger --request-context" — wrong twice: the user has no such setting to enlarge, and enlarging it cannot help because both prepared_context (:373) and context (:366) are clipped to tokens. The message also calls a pool-derived number "the … request context", naming a setting rather than the constraint.

Requested change (and it is shorter — see Subtract / Simplify): keep the default-versus-user-set split #454 asked for, but name the binding limit. Mention --request-context only when the target is what binds (result.prepared_context < result.tokens); when the pool binds, recommend --prefill-chunk-size (or more memory / fewer concurrent requests). Drop "(a multiple of 64)", which restates --prefill-chunk-size's own help (ignition/cli/__init__.py:163-166).

9. Description mechanics (one bullet; no code change)

Combine these into a single edit before merge:


Subtract / Simplify

Could remove ~7 of +35 added lines, plus roughly half of the new docs row. The feature body is already nearly minimal — one optional field, one accessor, one threaded keyword, one line in bootstrap.py. What is left is redundancy to delete.

  1. Collapse prepared_context onto context — ignition/planning.py:368-373 (~2 lines). min(recipe.context, target, tokens) is exactly min(self.context, target), since self.context is already min(recipe.context, tokens) (:363-366). Body becomes return self.recipe.context if self.context_target is None else min(self.context, self.context_target). Nothing lost: identical value for every input, including the omitted-flag case.
  2. Delete the dead min — ignition/planning.py:694 (~1 line). effective_context = min(result.context, result.prepared_context) can never select context: prepared_context <= context in both branches, and plan() otherwise only returns result (:692-701). Use the property in both arms so a reader need not prove an invariant.
  3. Shorten the two chunk messages — ignition/planning.py:696-700 (~2 lines). Keep the default/user-set split explicitly requested in #454, but drop "(a multiple of 64)" (restates cli/__init__.py:163-166) and the --request-context advice when the pool binds (should-fix 8).
  4. Shorten the help text — ignition/cli/__init__.py:167-170 (~1 line). "(the pool fills the free VRAM)" is conditional (blocker 4) and duplicates the docs. Suggested: "cap the prepared per-request context and max_sequence_tokens at N tokens; longer requests are rejected (default: the recipe's maximum context)".
  5. Collapse the docs row — docs/cli-design.md:446 (~half the line, plus the two rewords at :1443/:1493 can be dropped once the flag is documented in one place). The rationale sentence repeats the flag table, the KV-limit section (:828-833) and the two owner rows this PR also edits. One tabular line plus the existing "Command line only; … requires re-export" clause, with the --kv-cache-limit condition added from blocker 4.
  6. (minor) derive()'s new keyword is a pure pass-through — ignition/cli/preparation.py:56, :68 (~2 lines). All three callers pass args.request_context or nothing (bench.py:177, serve.py:289, serve.py:472); set it where it is used, or keep the hop only if the flag stays threaded through derive() for symmetry with row_shard_prefill.

Do not delete the flag. One lens argues --kv-cache-limit context|concurrency already bounds the pool (docs/cli-design.md:738, :828-833; memory.rs:284-331) and therefore asks for the whole feature to go. That is not the right call: the runtime flag bounds loaded KV history without a re-export, but it cannot lower the ceiling the core advertises, and #454's maintainer explicitly asked for the residual behaviour — serving must reject a request longer than the cap. Keep the flag; take the line savings above.

Left behind after the change (small, optional, listed for completeness): ignition/cli/serve.py:68-69 sizes max_body_bytes from recipe.context (correct — rejection happens at admission) but context_hint still says "context is limited by the checkpoint and available cache capacity"; ignition/cli/help.py:38 still advertises --prefill-chunk-size: 64..{recipe.context}, above the prepared context once a cap is set.


Nits (5)

  1. ignition/cli/__init__.py:167-170 — the help omits that N must be positive and no smaller than the prepared prefill chunk; both constraints currently surface only as UsageErrors (planning.py:459-460, :694-700).
  2. docs/cli-design.md:1443 — "The checkpoint maximum, capped by --request-context at export" layers a second term onto wording the neighbouring rows and the flag table render as "the recipe's maximum"; both terms are the recipe's declaration, so use one.
  3. ignition/cli/serve.py:68-69 — context_hint understates the new ceiling once a cap is set; a one-line reword.
  4. ignition/cli/help.py:38 — the advertised 64..recipe.context chunk range exceeds the prepared context under a cap.
  5. ignition/planning.py:373 — a target above the recipe maximum is silently clamped, while docs/cli-design.md:446 describes the flag as a cap below the maximum. The clamp becomes visible for free once blocker 3's effective value appears in the plan report.

Verified clean (checked, no finding)


Open questions for the maintainer (stated, not resolved here)

  1. Should bench honour the cap or reject the flag? Only a preference settles whether planning.py:248 moves to prepared_context or bench.py rejects --request-context like --mixed-prefill.
  2. What scope does the cap take in the rebuild manifest — SCOPE_DEPLOYMENT (like prefill_chunk) or SCOPE_COMBINE? It must be recorded either way.
  3. Should the plan report carry the requested target, the effective prepared context, or both? Both is clearest; either is defensible.
  4. Does any recipe re-round the prepared context before export? That is the only thing that would weaken blocker 2, and it lives in the external hyperflare_recipes repository (AGENTS.md:381). One unaligned export on a 128-token-page recipe plus flare run settles it.
  5. Could the runtime come to size the pool from the prepared context under --kv-cache-limit memory too? If so, blocker 4 changes from a documentation defect into a missing behaviour.
  6. Is multi-host deliberately out of scope for this flag? _export_hosts forwards every other preparation flag, and nothing in serve.py:163-215 or the docs says otherwise, so forwarding is the consistent fix — but a "yes, deferred" answer from a maintainer changes the fix to an explicit rejection.