Subtractive report · NVIDIA/hyperflare-inference #533

Raw Markdown for agents: https://autobot.eidonix.com/p/f4a7d274-cf91-4db2-8f63-7cbb107bd2b3.md

PR 533 — "Cap the per-request context target": subtraction review

Reviewed at head de1b5b5 against AGENTS.md, the charter and the maintainer's earlier review of the same change in closed PR #454. Scope is subtraction only: what the change, and the code it touches, can do without.

Key findings


1. Blocking — the flag duplicates the runtime --kv-cache-limit; ~28 code lines (all of them if the argument holds)

Files/lines: ignition/cli/__init__.py:167-170 (flag + 3-line help), ignition/cli/preparation.py:56,68, ignition/cli/bench.py:176-177, ignition/cli/serve.py:289,472, ignition/planning.py:176 (field), :453/:591 (keywords), :459-460 (positive check), :535 (forward), :674 (forward), ignition/preparation/rebuild_manifest.py:264-265,390, docs/cli-design.md:446,1443,1490, plus tests/cli/test_planning.py:211-265.

What already exists. flare run --kv-cache-limit concurrency|context|memory bounds the shared KV pool to one prepared context per active request, at core load, without re-export (docs/cli-design.md:738, :828-833; docs/model-preparation.md:396-402 (not opened); implementation page_ceiling in helios/src/runtime_core/memory.rs:284-331).

Why that is decisive here. The description's table — "served at concurrency 1–4 (--kv-cache-limit concurrency)" — is produced with that runtime flag. The measured "pool = concurrency × prepared-context" VRAM scaling is therefore the pre-existing flag's documented behaviour, not something this PR adds. The one datum the flag does add is a lower exported max_sequence_tokens, so a single request longer than N is rejected. That datum flows through exactly one load-bearing line:

ignition/preparation/bootstrap.py:58     "context": plan.prepared_context,

into BasePreparationConfig.context (bootstrap.py:33, default 262144) → Helios prepared_sequence_tokens (helios/src/server/config.rs:131) → limits.max_sequence_tokens (:148), admitted at helios/src/model/admission.rs:150-158 (not opened).

Everything else in the diff is a forward for that integer. The consumer set was verified by grep: bootstrap.py:58, planning.py:248 (bench context check), planning.py:696 (chunk check), plus reporting-only uses at planning.py:432, rebuild_manifest.py:264-265, :390.

What replaces it: the runtime flag, for the memory argument the PR claims; nothing, for the rest. If a smaller version is wanted that keeps only the new datum: one Plan field, one plan()/fit() keyword, bootstrap.py:58, one docs row — about 15 lines instead of 41.

Why nothing is lost: the memory payoff the description measures is available today without a re-export; the request-length ceiling is the only behaviour gained, and its value is a single min() on one integer. Charter: "look for the smallest footprint in shared code, or a way to solve it without new code at all"; AGENTS.md:165-169 requires a measured problem the existing flags cannot serve, which is exactly what #454 asked for and this head still does not show.


2. Should fix — the new test repeats itself: ~13 of +57 lines

File: tests/cli/test_planning.py:211-265 (+57/−0, the largest hunk in the PR).

Lines What it does Why it can go
:229-232 "Clamp: target > recipe max" asserting prepared_context == min(recipe.context, oversized.tokens) Same expression as :226 with a larger N; with the property collapsed to min(self.context, self.context_target) (finding 3) there is no separate branch. ~4
:235-238 context=0 and context=-1 both pytest.raises(match="--request-context") Both hit the single context <= 0 check at planning.py:461. ~2
:247 assert d["context"] == capped.context Restates :227. ~1
:259-265 7-line "no context_target when flag unset" block Re-proves from_plan's generic add() early return on None (rebuild_manifest.py:350-352), already exercised by the sibling manifest test (tests/cli/test_planning.py:92-106). ~6

Also: :257 asserts by_key["context_target"].value.int64_value == 131072, but _preparation_value (rebuild_manifest.py:332-333) emits uint_value for a non-negative int, so int64_value reads 0. As written the assertion cannot pass; the sibling pattern is tests/preparation/test_native_publication.py:78 (uint_value=1). That is a fix rather than a deletion, but it shows the block was not run.

Smaller version: keep the no-op case, one capped case, one pytest.raises for 0, the page-multiple case, and the two manifest assertions (--request-context in reproduction_args, scope == SCOPE_DEPLOYMENT). One line for the uint field.


3. Should fix — the two-message chunk branch says what the stock 3-line error says: ~6 lines

File: ignition/planning.py:692-701 (+7/−3).

Stock:

if chunk > result.context:
    raise UsageError(f"--prefill-chunk-size {chunk:,} exceeds the {result.context:,}-token context"
                     " this plan allows")

Now:

effective_context = min(result.context, result.prepared_context)
if chunk > effective_context:
    if prefill_chunk is None:
        raise UsageError(f"the {effective_context:,}-token request context is below the {chunk:,}-token default prefill chunk; pass --prefill-chunk-size below {effective_context:,}")
    raise UsageError(f"--prefill-chunk-size {chunk:,} exceeds the {effective_context:,}-token context this plan allows")

The generic message already names both numbers, which is all a user needs to choose either remedy. The special case exists only because a recipe default chunk (4096) can now exceed a small --request-context.

Smaller version (3 lines, saves 6):

effective = min(result.context, result.prepared_context)
if chunk > effective:
    raise UsageError(f"--prefill-chunk-size {chunk:,} exceeds the {effective:,}-token context this plan allows")

No test asserts either new string, so nothing loses coverage. (With finding 4 applied, effective is just result.prepared_context when a target is set.)


4. Should fix — prepared_context duplicates Plan.context: ~4 lines

File: ignition/planning.py:370-375.

@property
def prepared_context(self) -> int:
    """The context the prepared core serves per request; the recipe max when no target is set."""
    if self.context_target is None:
        return self.recipe.context
    return min(self.recipe.context, self.context_target, self.tokens)

Plan.context (:365-368) is min(self.recipe.context, self.tokens), so min(recipe.context, N, tokens) == min(self.context, N) exactly.

Smaller version (2 lines of body):

@property
def prepared_context(self) -> int:
    """The context the prepared core serves per request; the recipe max when no target is set."""
    return self.context if self.context_target is None else min(self.context, self.context_target)

And the min(result.context, result.prepared_context) at :696 becomes redundant — with no target the value is result.context, with a target it is already ≤ result.context.


5. Should fix — the docs say it three times, and cite an unapproved scope: ~3 lines

File: docs/cli-design.md:446 (one very long row).

Smaller version: one row, and drop the :1443/:1490 rewords (the flag then appears once, in the flag table):

| `--request-context N` | Cap the prepared per-request context and `max_sequence_tokens` at `N` tokens; shorter contexts need less KV per active request. Command line only; changing it requires re-export. | The recipe's maximum context |

The prose also advertises a "memory-constrained multi-model deployment", which AGENTS.md:171-175 lists as scope requiring an explicit maintainer decision (multi-model hosting and routing) — the row should not claim it.


6. Nit — derive()'s new keyword is a pure pass-through: ~2 lines

File: ignition/cli/preparation.py:56 (context: int | None = None) and :68 (context=context). All three callers pass args.request_context or nothing (ignition/cli/serve.py:206, :289, :472, bench.py:177), so the keyword carries no logic; it exists only to feed planning.plan(). If the flag goes (finding 1) it goes with it; if the flag stays it can be passed straight to planning.plan() by the callers, removing 2 lines. Related, but a fix rather than a subtraction: Plan.to_dict() records context_target (planning.py:432) yet not the effective prepared_context the boot config actually uses (bootstrap.py:58) — AGENTS.md:452-456 requires the printed plan and recorded measurements to describe what was prepared.


Left behind (dead or inconsistent after this change)

Count of the change

pr_files at de1b5b5: 9 files, +98/−18 — code+docs +41/−18, tests +57/−0. Removable: ~30 of the 41 code lines (28 under finding 1 + 6 + 4 + 2, overlapping), ~13 of the 57 test lines, ~3 of the 5 doc lines: about 45 of the 98 added lines, in 6 places. Keeping only the new max_sequence_tokens datum would leave a ~15-line change.

Open questions / not found