Subtractive scratchpad · NVIDIA/hyperflare-inference #533

Raw Markdown for agents: https://autobot.eidonix.com/p/933c44f5-675d-4691-a2ac-fea6311c98a7.md

#1 [high] Blocking: the flag re-implements runtime --kv-cache-limit, and the stated memory payoff comes from the runtime flag

PR 533 adds --request-context N on export/debug-serve/bench, threaded derive()→plan()→fit()→Plan.context_target, plus Plan.prepared_context, used only by ignition/preparation/bootstrap.py:58.

What already exists:

Only delta the flag adds over --kv-cache-limit: it lowers the exported max_sequence_tokens so a single request longer than N is rejected. That is one datum (ignition/preparation/bootstrap.py:58 "context": plan.prepared_context → BasePreparationConfig.context, bootstrap.py:33) and is the entire payload of the PR.

Cost of the present shape (diff +35/−15):

Charter/AGENTS hooks: AGENTS.md:165-169 "Every contribution must address ... a demonstrated defect, a measured performance or memory problem"; charter "Look for the smallest footprint in shared code, or a way to solve it without new code at all."

#2 [high] Should fix: prepared_context duplicates Plan.context; smaller version is one line

ignition/planning.py:368-373 (new):

@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 (planning.py:363-366) is min(self.recipe.context, self.tokens). So min(recipe.context, N, tokens) == min(self.context, N) exactly. Smaller version (2 lines saved):

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

And the call site at planning.py:694 effective_context = min(result.context, result.prepared_context) is then redundant: with no target it is result.context, with a target it is already ≤ result.context. It can read effective_context = result.prepared_context if result.context_target is not None else result.context (same length, so no direct saving) — but with the shortened property the whole second property could be dropped and the two users (bootstrap.py:58 and planning.py:694) could read min(result.context, result.context_target or result.context); net ~4 lines.

#6 [high] Research summary

Reviewed PR #533 ("Cap the per-request context target", +35/−15 across 7 files) through the subtraction lens, against AGENTS.md, docs/design-review.md, the charter, and the maintainer's earlier review of the same change in closed PR #454.

Findings, ranked by lines saved:

  1. Blocking (~15 of the 35 added lines, plus the doc prose). The flag is a re-implementation of a runtime setting the PR's own evidence is measured with. flare run --kv-cache-limit concurrency|context|memory (docs/cli-design.md:738, :828-833; docs/model-preparation.md:396-402; page_ceiling, helios/src/runtime_core/memory.rs:284-331) already bounds the shared KV pool to one prepared context per active request, at core load, without re-export. The description's table is explicitly produced with --kv-cache-limit concurrency, so the measured pool = concurrency × prepared-context VRAM scaling is the pre-existing flag's documented behaviour. The one genuine delta is a lower exported max_sequence_tokens, i.e. one datum reaching one consumer (ignition/preparation/bootstrap.py:58). Maintainer yatesdr asked in #454 for "a concrete workload that --max-concurrency and --kv-cache-limit cannot serve"; this resubmission keeps the same shape and the same memory argument.

  2. Should fix (~6 lines). ignition/planning.py:692-701 turns the stock 3-line --prefill-chunk-size check into a 9-line branch with two messages; the generic message already names both numbers, so one message carrying the effective context replaces it. No test asserts either new string.

  3. Should fix (~4 lines). Plan.prepared_context (planning.py:368-373) duplicates Plan.context: min(recipe.context, N, tokens) is exactly min(self.context, N), so the five-line body collapses to two, and the extra min(...) at planning.py:694 disappears.

  4. Should fix (~2 doc lines + half of one row). docs/cli-design.md:446 repeats what the PR's own other two doc edits (:1443, :1493) already state, and repeats the runtime KV-limit semantics; it also advertises a "memory-constrained multi-model deployment", which AGENTS.md:171-175 lists as unapproved scope.

  5. Nit (~2 lines). derive()'s new context parameter (ignition/cli/preparation.py:56, :68) is a pure pass-through — all three callers pass the flag or nothing. Separately, Plan.to_dict() never records the new setting, so the printed plan and bench configuration cannot show what was prepared (AGENTS.md:452-456), and no test covers any of the new behaviour.

Smallest version: a single Plan field, one plan()/fit() keyword, one line in bootstrap.py and one docs row — roughly 15 of the 35 added lines removable, and the VM point that the flag's memory argument is already served by --kv-cache-limit.

#9 [high] Should fix: the new test block repeats its own assertions and the manifest helper's generic behaviour (~13 of +57 lines)

tests/cli/test_planning.py:211-265 is the new test (57 added lines, the largest single hunk in the PR: pr_files shows tests/cli/test_planning.py +57/-0). Candidates that prove nothing new:

  1. Clamp case duplicates the valid case. :224-227 asserts capped.prepared_context == min(recipe.context, 131072, capped.tokens); :230-232 asserts the same expression for 500000. With the property collapsed to min(self.context, self.context_target) there is no separate branch, so one case suffices. ~4 lines.

  2. context=0 and context=-1 hit one branch. planning.py:461-462 validates context <= 0 in a single check; two pytest.raises blocks (:235-238) exercise the same line. ~2 lines.

  3. d["context"] == capped.context (:247) restates :227. ~1 line.

  4. The "no context_target when unset" block (:259-265, 7 lines) re-proves from_plan's generic skip. rebuild_manifest.py:350-352 add() returns early on value is None for every parameter; the generic behaviour is already covered by the sibling tests' decode loop (tests/cli/test_planning.py:92-106). Also reproduction_arguments gating is the same is not None pattern used by every other flag (:266-319). ~6 lines.

  5. Wrong field asserted. :257 asserts by_key["context_target"].value.int64_value == 131072, but _preparation_value (rebuild_manifest.py:332-333) emits {'uint_value': value} for any non-negative int, so the oneof sets uint_value and int64_value reads 0. As written the assertion fails; the sibling pattern to copy is tests/preparation/test_native_publication.py:78 (uint_value=1). One line, wrong direction (a fix, not a deletion) — but it shows this block was not run.

Net: ~13 of the 57 added test lines carry no distinct behaviour. The test's own header comment (:212) and section comments (:217, :223, :229, :234, :240, :244, :249, :259) restate the assertions below them — another ~8 lines if the blocks are merged.

#11 [high] Report (updated, run at head de1b5b5) — verdict: make it smaller first; ~45 of 98 added lines removable

PR 533, head de1b5b5, base main: 9 files, +98/−18 (pr_files). That splits as +41/−18 in code and docs and +57/−0 in tests — superseding the "+35/−15 across 7 files" figure of entry #8.

Ranked findings (all previously recorded, plus the new test finding #9):

  1. Blocking (~28 lines) — the flag re-implements runtime --kv-cache-limit. Drop --request-context, Plan.context_target, the context= keyword on plan()/fit()/derive(), the <= 0 check, prepared_context and the chunk-branch rewrite; only ignition/preparation/bootstrap.py:58 survives as a no-op change. Evidence: the PR's own table is measured with --kv-cache-limit concurrency (docs/cli-design.md:738, :828-833; page_ceiling helios/src/runtime_core/memory.rs:284-331), and #454's maintainer asked for "a concrete workload that --max-concurrency and --kv-cache-limit cannot serve". (entry #1, wiring inventory in #10)
  2. Should fix (~13 lines) — tests/cli/test_planning.py:211-265 (+57) repeats itself: duplicate clamp case, duplicate 0/-1 rejections, a re-proved generic add()-skips-None path, plus one assertion on int64_value that cannot pass. (entry #9)
  3. Should fix (~6 lines) — planning.py:692-701 turns the stock 3-line chunk check into a 9-line two-message branch. (entry #3)
  4. Should fix (~4 lines) — prepared_context duplicates Plan.context: min(recipe.context, N, tokens) == min(self.context, N), and the extra min at :696 goes. (entry #2)
  5. Should fix (~3 doc lines) — docs/cli-design.md:446 repeats :1443 and :1493 (this PR's own other edits) and the KV-limit section; the removed prose also cites the multi-model hosting scope AGENTS.md:171-174 rejects. (entry #4)
  6. Nit (~2 lines) — derive()'s context parameter is a pure pass-through; to_dict() records context_target but not the effective prepared_context the boot config actually uses (planning.py:432 vs bootstrap.py:58). (entry #5)

Total removable: ~30 code lines of the 41, ~13 of the 57 test lines, ~2-3 of the 5 doc lines — roughly 45 of the 98 added lines, 70 of them if the flag goes entirely with the runtime argument.

Left behind: ignition/cli/serve.py:68-69 (max_body_bytes from recipe.context, context_hint still "limited by the checkpoint"), ignition/cli/help.py:38 (--prefill-chunk-size: 64..{recipe.context}), ignition/bench/runner.py:388 (validates against layout.context, i.e. the pool-bound value, while the new bench path caps preparation).

File-by-file: entry #7 (unchanged; bootstrap.py:58 is the sole load-bearing hunk).

#12 [high] Research summary

Reviewed PR #533 at head de1b5b5 through the subtraction lens, against AGENTS.md, docs/design-review.md (not opened), the charter, and the maintainer's earlier review of the same change in closed PR #454.

The head moved since my last pass, so counts are corrected: 9 files, +98/−18 — +41/−18 in code and docs, +57/−0 in tests (not the "+35/−15 across 7 files" I reported before).

Findings, ranked by lines saved (all in the scratchpad, entries #1-#5, #9-#11):

  1. Blocking, ~28 lines — the flag re-implements runtime --kv-cache-limit. The PR's own VRAM table is measured with --kv-cache-limit concurrency (an existing runtime flag applied at core load, docs/cli-design.md:738, :828-833; page_ceiling in helios/src/runtime_core/memory.rs:284-331), and #454's maintainer asked for a workload that flag cannot serve. The only genuine delta is one integer reaching ignition/preparation/bootstrap.py:58.
  2. Should fix, ~13 of the 57 test lines (new this pass) — tests/cli/test_planning.py:211-265 repeats itself: the clamp case re-asserts the same min() as the valid case, 0 and -1 hit one <= 0 branch, and the seven-line "no context_target when unset" block re-proves from_plan's generic add()-skips-None rule. Also, :257 asserts value.int64_value while _preparation_value (rebuild_manifest.py:332-333) emits uint_value for a non-negative int — that assertion cannot pass.
  3. Should fix, ~6 lines — planning.py:692-701 turns the stock three-line prefill-chunk error into a nine-line two-message branch; one message naming the effective context suffices.
  4. Should fix, ~4 lines — prepared_context (planning.py:370-375) duplicates Plan.context: min(recipe.context, N, tokens) is min(self.context, N), which also makes the extra min at :696 dead.
  5. Should fix, ~3 doc lines — docs/cli-design.md:446 states what the PR's own other two edits (:1443, :1493) already state, and its prose advertises the multi-model hosting scope AGENTS.md:171-174 rejects.
  6. Nit, ~2 lines — derive()'s context keyword is a pure pass-through, and to_dict() records context_target but not the effective prepared_context the boot config actually uses.

Total removable: roughly 45 of the 98 added lines (about 30 of the 41 code lines, 13 of the 57 test lines, 2-3 of the 5 doc lines) — about 70 if the flag is dropped altogether and the runtime --kv-cache-limit carries the argument. Left behind: ignition/cli/serve.py:68-69 (max_body_bytes and context_hint still sized/worded from the recipe max), ignition/cli/help.py:38, and ignition/bench/runner.py:388.

#13 [high] Correction: earlier notes #5/#8 said "no test covers the new behaviour" — false at head de1b5b5

Stale claims that the final report must not repeat (the head moved from the commit I reviewed to de1b5b5):

  1. "No test asserts any of the new behaviour" (entry #5, item 4; entry #6; entry #8 "Open questions"). False at de1b5b5: tests/cli/test_planning.py:211-265 adds test_request_context_target_prepared_context_and_manifest (+57 lines) covering the no-op path, the clamp, both validations, to_dict() and the manifest keys. grep -n "prepared_context\|context_target\|request_context" tests/ now returns tests/cli/test_planning.py:211-265 only. The test's own problem is the opposite one — it repeats itself (entry #9) — and :257 asserts int64_value where _preparation_value (rebuild_manifest.py:332-333) emits uint_value, so that line cannot pass.

  2. "+35/−15 across 7 files" (entries #1, #6, #7, #8). Actual at de1b5b5 (pr_files): 9 files, +98/−18 — docs/cli-design.md +3/−2, ignition/cli/init.py +4/−0, ignition/cli/bench.py +2/−1, ignition/cli/preparation.py +2/−2, ignition/cli/serve.py +3/−3, ignition/planning.py +23/−9, ignition/preparation/bootstrap.py +1/−1, ignition/preparation/rebuild_manifest.py +3/−0, tests/cli/test_planning.py +57/−0. Code+docs = +41/−18; tests = +57/−0.

  3. Unchanged and still true: ignition export M --ranks 2 --request-context N does now forward the flag (cli/serve.py:206), so the autobot blocker "multi-host never passes context" is fixed at this head; Plan.__post_init__ does now validate the page multiple (planning.py:289-290, reflecting Helios' catalog.rs:50-57 requirement); to_dict()/reproduction_arguments/from_plan all record the setting (planning.py:432, rebuild_manifest.py:264-265, :390). So the "left behind" list shrinks to serve.py:68-69, cli/help.py:38 and bench/runner.py:388.

#3 [medium] Should fix: the two-message prefill-chunk branch adds 6 lines to say what the existing 3-line error says

ignition/planning.py:692-701 (PR adds the branch):

result = attempt()
if result is not None:
    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 "
                             f"default prefill chunk; pass --prefill-chunk-size (a multiple of 64) below "
                             f"{effective_context:,} or a larger --request-context")
        raise UsageError(f"--prefill-chunk-size {chunk:,} exceeds the {effective_context:,}-token context this plan allows")

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

The PR turns 3 lines into 9 and adds a two-message branch to say the same thing: the chunk is larger than the context this plan allows. The special case exists only because a recipe default chunk (4096) can now exceed a small --request-context, and the generic message already names both numbers, which is all a user needs to pick either remedy. The branch costs 6 lines plus a second error string that no test asserts (grep for "request-context"/"positive token count" in tests/ → no matches).

Smaller: keep one message, replace result.context with the prepared context: if chunk > min(result.context, result.prepared_context): raise UsageError(f"--prefill-chunk-size {chunk:,} exceeds the {min(result.context, result.prepared_context):,}-token context this plan allows") or bind it once in a local. Saves 6 lines of the 7 the hunk adds.

Note the sibling validation at planning.py:459-460 (if context is not None and context <= 0: raise UsageError(... --request-context ...)): it is a caller-guaranteed check. fit() also validates mla_compute_mode, speculation, etc., so per-argument validation is the house style, and it costs 2 lines; it is not worth a separate finding except as part of the total. However it is the only place --request-context 0 is caught, so it must stay if the flag stays.

#4 [medium] Should fix: the docs say the same thing three times, and advertise out-of-scope multi-model hosting

docs/cli-design.md:446 row, trimmed. Present row is 1 very long line that repeats three things the document already says:

  1. "a request that would exceed N is rejected by the engine's standard context ceiling" — already specified at docs/cli-design.md:1443 ("Context limit | The checkpoint maximum, capped by --request-context at export") and :1493 ("Context limit | The smaller of the prepared context ceiling, capped by --request-context, ..."). Those two table rows are the PR's other two doc edits (:1443, :1493) and say the same thing a third time.
  2. "since the per-request cache allocation is sized from the prepared context" — already true for every core and documented at :828-833.
  3. "Command line only; a core's catalog is fixed at export, so changing it requires re-export" — the same trailing sentence is already carried by --mixed-prefill (:447) and by --kv-cache-limit's note that the runtime flags need no re-export (:874-876).

Smaller, one row:

| --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 |

and drop the :1443 and :1493 edits (the flag then appears once, in the flag table). ~2 doc lines + roughly half the 446 row's prose. Note the prose also contradicts the change's own rationale: it advertises "a memory-constrained multi-model deployment", which AGENTS.md:171-175 lists as unapproved scope ("multi-model hosting and routing ... require an explicit maintainer decision").

#5 [medium] Nit: the new setting is invisible in the plan report, and derive()'s new parameter is a pure pass-through

  1. Plan.to_dict() (ignition/planning.py:389-442) does not include prepared_context or context_target, although every other plan setting is recorded there (context, checkpoint_context, prefill_chunk, mixed_prefill, ...). AGENTS.md:452-456 requires the plan, its printed report, and recorded measurements to describe what was prepared; the flag changes max_sequence_tokens yet the printed plan and the bench details["configuration"] = plan.to_dict() (ignition/cli/bench.py:237) cannot show it. Fixing this is an addition, so as a subtraction: if the flag is kept, drop the field and derive the value at the single consumer.

  2. Dead/one-sided flag surface: --request-context is added to _preparation_arguments (ignition/cli/init.py:136-170), which serves export, bench and debug-serve — but NOT flare run (docstring of _server_options at ignition/cli/serve.py:60-72 comments "Derive native server settings independently of preparation's physical KV backing", max_body_bytes still uses recipe.context, not the prepared context). So the docs' claim that a request beyond N "is rejected by the engine's standard context ceiling" holds only because the value reaches BasePreparationConfig.context; nothing in ignition's own debug-serve path re-reads it, and the benchmark's --contexts check at planning.py:248 (selection.required_context > self.context) still compares against the recipe max, not the prepared context. That is a behavioural gap, but for the subtraction lens: the flag is worth nothing without the reject path, so the smaller shape is one value on the plan plus the two consumers, not a new flag family threaded through bench.

  3. ignition/cli/preparation.py:56 adds context: int | None = None to derive() and forwards it at :68 — a pure pass-through parameter of the kind the file otherwise avoids only when one command differs (it does not here: all three callers pass args.request_context or nothing). If the flag goes, this parameter goes entirely (2 lines).

  4. No test asserts any of the new behaviour: grep of tests/ for request_context/prepared_context/context_target/--context → no matches (tests/cli/test_commands.py:80's old --context usage-error assertion the maintainer flagged in #454 is gone from main too). The historical #454 review asked for tests that fail without the change; the diff adds none, so as a subtraction there is nothing to trim here, but it means none of the new branches (the positive check, the two-message chunk branch) is protected.

#7 [medium] Per-file examination record: what each changed file contributes and where nothing can be cut

Diff is +35/−15 over 7 files (pr_files). Hunk inventory:

Net: 34 of 35 added lines exist to carry one integer to one consumer; ~15 can go without losing the behaviour the PR claims.

#10 [medium] Blast-radius note: prepared_context is read by only four places, so a field+two-line property is the whole mechanism

Verified consumer set for the PR's one datum (context_target / prepared_context), from a grep of prepared_context|context_target|request_context at the head commit:

So 4 of the 9 changed files (bench.py, preparation.py, serve.py, rebuild_manifest.py — 10 added lines) plus the two planning.py forwards exist only to carry one integer to bootstrap.py:58; the property that does the min() is a two-line replacement for the five-line body.

Also unchanged since the earlier pass: helios is untouched by this PR, so no runtime code becomes dead; docs/cli-design.md:69 (context_hint) and ignition/cli/serve.py:68-69 (max_body_bytes from recipe.context, hint text "limited by the checkpoint") still describe the pre-cap world, and ignition/cli/help.py:38 still advertises --prefill-chunk-size: 64..{recipe.context}.