Architecture scratchpad · NVIDIA/hyperflare-inference #533

Raw Markdown for agents: https://autobot.eidonix.com/p/d9eb9487-979b-492e-b255-e00a6dfa07ec.md

#1 [high] Blocking: multi-host export silently ignores --request-context

ignition/cli/serve.py:193-206 (_export_hosts, the ignition export --ranks N path) builds its plan with an explicit planning.plan(...) call whose keyword list ends at row_shard_prefill=args.row_shard_prefill) — there is no context=args.request_context. The flag is registered on every preparation command (ignition/cli/init.py:167-170, via _preparation_arguments), so ignition export MODEL --ranks 2 --request-context 131072 accepts the value and then prepares a core at the recipe maximum, with no warning. Compare the three paths that do thread it: _prepare (serve.py:289), debug_serve (serve.py:472), bench.run (bench.py:177).

Why it matters: AGENTS.md "Be explicit and pin everything" / charter "Don't silently ignore API fields" and AGENTS.md:165-169 (explicit behavior). The whole claimed benefit is a smaller max_sequence_tokens; a multi-host deployment (a supported shape per AGENTS.md:157-163) gets a full-context core and no error, which the user only discovers when the VRAM payoff does not appear or the request ceiling is not enforced.

Fix: pass context=args.request_context in _export_hosts. Verified in code: diff touches only serve.py:286 and :469 (the _prepare and debug_serve call sites), not the _export_hosts call at :193.

#2 [high] Blocking: cap is absent from plan report and rebuild manifest

Three reporting surfaces omit the new setting, so neither the printed plan, the benchmark record, nor the rebuild manifest describes what was prepared:

  1. Plan.to_dict (ignition/planning.py:389-442) still emits "context": self.context and "checkpoint_context": self.recipe.context (:430) and no key for context_target or prepared_context. self.context stays stock by design (planning.py:363-366), so the plan JSON printed at serve.py:215/485, bench.py:182 reports a context the core does not serve. A core exported with --request-context 131072 prints context: 262144.
  2. rebuild_manifest.reproduction_arguments (ignition/preparation/rebuild_manifest.py:231-318) never adds --request-context, so the recorded reproduction command rebuilds a full-context core.
  3. rebuild_manifest.from_plan (rebuild_manifest.py:343-454) records no parameter for it, so nothing in the manifest distinguishes two cores that differ only in prepared context. bench.py:243-248 also selects a fixed key list from plan.to_dict() that has no context key.

Why it matters: AGENTS.md Configuration ("A 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"), AGENTS.md 431-444 (model core compatibility, metadata describes the prepared capacities), and docs/runtime-core-design.md:389 (combine-scope parameters). A core's prepared context is now a deployment-visible capacity; today it is invisible in every artifact.

Fix: add context_target (and the resolved prepared_context) to Plan.to_dict, --request-context to reproduction_arguments when the target is set, and a parameter entry in from_plan.

#5 [high] Research summary

I reviewed all seven changed files in context (ignition/planning.py, ignition/cli/{init,bench,preparation,serve}.py, ignition/preparation/bootstrap.py, docs/cli-design.md) against the charter, AGENTS.md, and docs/cli-design.md, and followed the cap into Helios (prepared_sequence_tokens → fit_context → catalog validation) and into core export. Four findings are on the scratchpad.

Two are blocking. First, the multi-host export path (_export_hosts, ignition/cli/serve.py:193-206) never passes context=args.request_context although --request-context is registered for every preparation command, so a --ranks N export silently prepares at the recipe maximum — the exact "cap does not reach the core" failure of the earlier review, now confined to one path. Second, the new setting is invisible in every artifact the project requires to describe preparation: Plan.to_dict still reports context/checkpoint_context only, and neither reproduction_arguments nor from_plan records --request-context, so the printed plan, benchmark record, and rebuild manifest all describe a core that was not prepared.

Two should-fix items: the target is only validated as positive, never against the page size, yet prepared_context becomes max_sequence_tokens that Helios requires to be page-aligned (helios/src/model/catalog.rs:44-58) — a non-multiple target looks like it exports a core that fails to load, which only an export test can settle; and the change adds no tests for shared planning behavior, while its stated motivation (headroom for a co-run model) leans on multi-model hosting, which the charter lists as a non-goal requiring sign-off. The measured VRAM table does answer the earlier "hypothetical deployment" objection, and the --kv-cache-limit overlap the prior review raised is now reconciled by the description's measurement setup, though the description would be stronger if it said what --kv-cache-limit alone cannot do.

#6 [high] Verified clean: cap does reach the core, and omission is a no-op

Checked and found correct, so the report can say these were verified rather than assumed:

  1. The cap reaches the core. ignition/preparation/bootstrap.py:58 now passes plan.prepared_context into BasePreparationConfig.context (bootstrap.py:33), and every recipe receives it through common_preparation_kwargs. That value becomes the core's max_sequence_tokens on load: helios/src/server/config.rs:131 reads it as prepared_sequence_tokens, :148 sets limits.max_sequence_tokens, and helios/src/model.rs:261-273 (fit_context) then min's it with physical pages. So the claim "a request that would exceed the cap is rejected" holds via server/request.rs:350 and scheduler.rs:2289/2358. This is the point the earlier review (#454, review comment 1) blocked on, and it is now fixed.
  2. Omitting the flag is a no-op. prepared_context returns recipe.context when context_target is None (planning.py:371-372), byte-identical to the old plan.recipe.context; Plan.context (planning.py:363-366) is untouched. fit/plan defaults are context=None, so every existing caller (including _export_hosts) behaves exactly as before — which is also why finding 1 is a silent drop rather than a crash.
  3. Pool sizing is unchanged by design. fit still gives the cache all free memory (planning.py:536-542); the cap reaches the pool only because the runtime sizes its pages from the core's now-smaller max_sequence_tokens (helios/src/runtime_core/memory.rs:631-635 via page_ceiling), plus --kv-cache-limit concurrency in the measurement. Nothing in the diff misstates this, though the description's per-slot explanation could say it explicitly.
  4. Other consumers of the plan are unaffected: ignition/cli/serve.py:68 (max_body_bytes) still uses recipe.context, so the HTTP body allowance stays generous — correct, since rejection happens at admission. ignition/cli/serve.py:538-546 (diagnostic capacity clamp) and the --direct path (ignition/direct/scheduler.py:110 reads config["max_sequence_tokens"]) both inherit the capped value, so direct execution enforces the cap too. Plan.prepared_context is read at exactly two sites: bootstrap.py:58 and the chunk check at planning.py:694.
  5. Docs are consistent with the code where it is wired: docs/cli-design.md:446, :1443, :1493 correctly describe a context limit capped at export and the prepared-context-derived cache sizing; :738's "prepared context" wording still resolves correctly to the capped value.
  6. The positive-target validation (planning.py:459-460) is in fit, so it fires on every planning path, not only plan. --request-context 0/negative yields the intended UsageError. --request-context placement in the "capacity and compression" argument group (cli/init.py:167-170) is the right home per AGENTS.md:452-456.
  7. The below-chunk error (planning.py:694-700) uses min(result.context, result.prepared_context) and its message names both remedies; with the recipe's default chunk and a low target, prefill_chunk is None selects the message that says to pass --prefill-chunk-size or a larger --request-context. Behaviour is right; only the absence of a test is a finding.

#8 [high] Blocking: the new page-multiple check validates the raw target, so the PR's own test case and the documented "cap above the recipe max is a no-op" path fail

ignition/planning.py:289-290 (new, in Plan.post_init):

if self.context_target is not None and self.context_target % self.page_tokens:
    raise UsageError(f"--request-context {self.context_target:,} is not a multiple of the {self.page_tokens:,}-token page size")

It checks the raw requested target, not the resolved prepared_context (planning.py:370-375: min(recipe.context, target, tokens)).

Two consequences, both verifiable from the code:

  1. A target above the recipe max — which the docs and the description present as a harmless clamp ("a cap above the pool resolves to the pool capacity, as stock"; docs/cli-design.md:446 default "The recipe's maximum context") — is rejected whenever it is not a page multiple, even though the core would serve the aligned recipe max.

  2. The PR's own new test contradicts the check: tests/cli/test_planning.py:229-232 builds oversized = planning.plan(recipe, recipe.checkpoints[0], gpus, context=500000, **base) and asserts prepared_context == min(recipe.context, oversized.tokens). The fixture recipe (tests/cli/test_planning.py:37-38) has context=262144, page_tokens=64, and its RankCosts declares no page_tokens (tests/cli/test_planning.py:43), so Plan.page_tokens == recipe.page_tokens == 64 (planning.py:328-332). 500000 mod 64 = 32, so the assertion never runs: planning.plan raises UsageError "not a multiple of the 64-token page size". The added test fails on the added validation.

Fix: validate the value the core will actually serve, not the request. Plan.__post_init__ cannot do that for the memory-dependent part because the first construction has pages=0, hence tokens=0, hence prepared_context==0 (planning.py:528-537 builds the Plan before replace(..., pages=...)). Correct place: end of fit (planning.py:538-544) or in plan after attempt(), checking min(recipe.context, context_target) % page_tokens (the memory-independent part), or check the final plan's prepared_context. Then either delete the test's 500000 case or keep it as the no-op proof.

Note the test also asserts capped.prepared_context == min(recipe.context, 131072, capped.tokens); 131072 is a page multiple, so that case is fine.

#9 [high] Verified fixed since last turn: multi-host path, plan report, manifest, docs, tests

Checks re-run at head de1b5b5 against the code:

  1. Multi-host export now forwards the flag: ignition/cli/serve.py:193-206 ends row_shard_prefill=args.row_shard_prefill, context=args.request_context. All four planning sites carry it: serve.py:193-206 (_export_hosts), serve.py:274-289 (_prepare, via derive), serve.py:459-472 (debug_serve), bench.py:162-177 (bench, via derive). derive forwards it (ignition/cli/preparation.py:56, 68 with keyword context=context). No remaining caller of planning.plan omits it.
  2. The plan report now carries it: ignition/planning.py:432 "context": self.context, "context_target": self.context_target, "checkpoint_context": self.recipe.context. prepared_context is derivable from those three plus tokens/page_tokens (which to_dict also emits, planning.py:440-441).
  3. The manifest now carries it: ignition/preparation/rebuild_manifest.py:264-265 emits --request-context <target> in reproduction_arguments, and :390 records context_target with SCOPE_DEPLOYMENT (add() skips None at :350-355, so an untargeted export records nothing — byte-equivalent to stock).
  4. Page-multiple validation exists (planning.py:289-290) — but validated on the wrong quantity; see the blocking note.
  5. Tests were added (tests/cli/test_planning.py:211-265) covering the no-op path, the clamp, both validations, to_dict, and the manifest keys — but one case fails; see the blocking note.
  6. Docs are consistent: docs/cli-design.md:446 now states the VRAM payoff only "With --kv-cache-limit concurrency", which matches helios/src/runtime_core/memory.rs:284-331 (page_ceiling returns None in default memory mode); :1443 and :1493 updated for the capped ceiling.
  7. The charter non-goal nit from the last report no longer applies: the description and docs row now justify the cap by single-model memory pressure, not multi-model hosting.

Still correct from entry #6: bootstrap.py:58 "context": plan.prepared_context is the only consumer that reaches the core, Helios reads it as prepared_sequence_tokens (helios/src/server/config.rs:131) and clamps limits.max_sequence_tokens (helios/src/model.rs:261-273, validated page-aligned at helios/src/model/catalog.rs:43-57).

#10 [high] Should fix: prepared_context is clamped by export-host free memory, making the exported ceiling non-reproducible

ignition/planning.py:370-375:

def prepared_context(self) -> int:
    if self.context_target is None:
        return self.recipe.context
    return min(self.recipe.context, self.context_target, self.tokens)

self.tokens is pages * page_tokens (planning.py:362-363), and pages is sized from the exporting host's free memory (planning.py:538-544). This value becomes the exported core's max_sequence_tokens via ignition/preparation/bootstrap.py:58.

Three consequences:

  1. The declared capacity of an exported core now depends on how much VRAM happened to be free on the export host — two exports of the same model with the same flags whose results are recorded in identical reproduction_args (ignition/preparation/rebuild_manifest.py:231-320, :390) can declare different max_sequence_tokens. That conflicts with AGENTS.md:452-456 ("the plan, its printed report, and its recorded measurements describe what was prepared") and with "Be explicit and pin everything" (charter line 14).
  2. A low target is silently lowered further without any message: on a host where tokens is 20000, --request-context 131072 prepares a 20000-token core and the printed plan reports context_target: 131072, context: 20000, tokens: 20000 — no warning that the request was not honored.
  3. The clamp duplicates Helios, which already narrows the advertised ceiling to the pool: helios/src/model.rs:260-273 fit_context sets limits.max_sequence_tokens = prepared_sequence_tokens.min(pages*page_tokens) and helios/src/model/catalog.rs:43-57 only requires max_sequence_tokens <= prepared_sequence_tokens. So min(recipe.context, context_target) is sufficient for the core.

Fix: drop the self.tokens term, return min(self.recipe.context, self.context_target). Then the resolved value is a pure function of the requested target and the recipe, reproducible from the manifest, pool-bound behaviour stays Helios's job (as stock), and page alignment follows from validating the target alone — which also removes the case that made the 500000 clamp test meaningful (see entry 8). stock path returns recipe.context, which is what the previous plan.recipe.context did; keep that.

Note Plan.context (planning.py:365-368) is untouched by this PR, so the printed context key still describes stock pool-bound behaviour, not the core; the new context_target key plus tokens/page_tokens (planning.py:440-441) make the core value derivable.

#11 [high] Research summary

Verdict: one blocking issue, one should-fix, everything else from my previous report confirmed fixed.

The PR's structure is now right. All four planning entry points forward the flag (ignition/cli/serve.py:193-206, :274-289, :459-472, ignition/cli/bench.py:162-177 via derive), Plan.to_dict reports context_target (ignition/planning.py:432), the manifest both emits --request-context (ignition/preparation/rebuild_manifest.py:264-265) and records context_target at SCOPE_DEPLOYMENT (:390), a page-multiple validation exists, tests were added, and the docs row now scopes the VRAM payoff to --kv-cache-limit concurrency, matching helios/src/runtime_core/memory.rs:284-331. The previous three blockers and both should-fix items are closed, and the multi-model non-goal concern no longer applies.

Blocking. ignition/planning.py:289-290 validates the raw requested target, not the resolved value: any non-page-multiple --request-context is rejected even when it would be clamped away by min(recipe.context, target, tokens). This breaks the PR's own new test — tests/cli/test_planning.py:230-232 plans with context=500000 against the 64-token-page fixture and is now guaranteed to raise (500000 % 64 == 32), so the added test fails on the added validation, and the "a cap above the recipe max is a no-op" path the description and docs row promise is unreachable unless the oversized value happens to be aligned. Fix by validating the value the core serves, in fit/plan after attempt() rather than in __post_init__ (which runs with pages=0, hence tokens=0, hence prepared_context=0).

Should fix. prepared_context (planning.py:370-375) also clamps by self.tokens, which is sized from the export host's free memory. That makes an exported core's declared max_sequence_tokens depend on how much VRAM was free at export while reproduction_args stay identical (AGENTS.md:452-456, "Be explicit and pin everything"), and silently lowers a requested cap with no message. Helios already performs this clamp (helios/src/model.rs:260-273 fit_context, bounded by helios/src/model/catalog.rs:43-57), so min(recipe.context, context_target) is the reproducible, sufficient value — and dropping the tokens term also removes the only case where the oversized clamp mattered.

Full detail is in scratchpad entries #8, #9 and #10.

#12 [high] Report of 2026-11-26, run 1002 (supersedes #7): verdict, findings, and what I did not verify

Supersedes entry #7 (which described an earlier head c36a6a02 + the pre-change serve.py). Review target: PR #533 head de1b5b5.

Verdict

Blocking: 1 (new, introduced by the head commit). Should fix: 1. Everything in #7's blocker list is now genuinely fixed — do not re-raise it.

Blocking

ignition/planning.py:289-290 validates the requested target instead of the resolved prepared context: if self.context_target is not None and self.context_target % self.page_tokens: raise UsageError(...) Two demonstrable consequences:

  1. The PR's own new test fails. tests/cli/test_planning.py:229-232 calls planning.plan(..., context=500000) and asserts oversized.prepared_context == min(recipe.context, oversized.tokens). Fixture: context=262144, page_tokens=64 (tests/cli/test_planning.py:37-38), RankCosts with no per-rank page_tokens (:43), so Plan.page_tokens == 64 (planning.py:328-332). 500000 % 64 = 32 → UsageError. The assertion cannot run.
  2. An oversized, unaligned target is rejected although the resolved core value would be the aligned recipe max — the "a cap above the pool/recipe max resolves to the max, as stock" behaviour that the PR description and docs/cli-design.md:446 promise. Fix: validate what the core serves — in fit/plan after attempt() (multiple of page_tokens applied to min(recipe.context, context_target), or the final prepared_context) — not __post_init__, which runs while pages=0 so tokens=0 and prepared_context=0 (planning.py:528-544). Honesty note: I did not run .venv/bin/python -m pytest tests/cli (no execution in this review); the failure is arithmetic from the fixture constants and is trivial to confirm by running that file.

Should fix

ignition/planning.py:370-375 — prepared_context also min's self.tokens (pages × page_tokens), and pages is sized from the exporting host's free memory (planning.py:538-544). That value becomes the core's max_sequence_tokens via ignition/preparation/bootstrap.py:58, so two exports with identical reproduction_args can declare different ceilings depending on export-host VRAM; it also silently lowers a requested cap with no message while to_dict still prints the requested context_target (planning.py:432). It contradicts AGENTS.md:452-456 and "Be explicit and pin everything". Helios already clamps the advertised ceiling to physical pages (helios/src/model.rs:260-273 fit_context; helios/src/model/catalog.rs:43-57 requires only max_sequence_tokens <= prepared_sequence_tokens), so min(recipe.context, context_target) is sufficient, reproducible, and makes page alignment a property of the target alone.

Confirmed fixed since #7 (cite these rather than the old blockers)

Lens judgement (architecture and scope)

Belongs in the repository: it is a preparation capacity on the existing plan → PreparationConfig → core-catalog path, not a new mechanism, and it adds no per-model branch (charter "Keep the runtime small and model-agnostic"; AGENTS.md:338-345). It is one shared flag on the existing Plan, verified by measurement (RTX PRO 6000 Blackwell, table in the description) as the charter's "measured performance/memory issue" requires. The omission path is a true no-op (prepared_context returns recipe.context, matching the old plan.recipe.context), so compatibility (AGENTS.md:431-444) holds. No new CLI flag family or fallback layer, and no Helios change — Helios needed none. Residual scope note (not a finding, worth one line): the flag is honoured by export, bench and debug-serve alike; bench's workload check moved to prepared_context (planning.py:248), which is correct and now consistent with the core.

Not verified this run

#3 [medium] Should fix: context target is not validated against page alignment

Plan.prepared_context (ignition/planning.py:368-373) returns min(recipe.context, context_target, tokens) while Plan.context (:363-366) returns min(recipe.context, tokens). tokens is pages * page_tokens and pages is sized at fit time from free memory (:541-542). Two consequences:

a) Invariant risk. prepared_context can be strictly below context when the pool is smaller than the target. Helios requires max_sequence_tokens == prepared_sequence_tokens to be a multiple of page_tokens (helios/src/model/catalog.rs:44-58). tokens is a multiple of page_tokens, and recipe.context is whatever the recipe declares, so min() of the two plus a user target N keeps that property only if N is a multiple of page_tokens. context_target is not validated for page-token alignment anywhere (fit only rejects context <= 0, planning.py:459-460), yet prepared_context is what becomes max_sequence_tokens via ignition/preparation/bootstrap.py:58. A value such as --request-context 100000 on a 64-token page recipe exports a core whose declared context is not page aligned. Whether the core then fails to load, or Helios rounds/deviates, needs a test on an exported core; the code path (validate_inner returning "invalid prepared model configuration") suggests a load-time rejection of a core that took a long preparation to produce. Fix: reject or round a target that is not a multiple of the recipe's page size in fit.

b) The resolved value is memory-dependent. prepared_context = min(..., tokens) makes the core's advertised ceiling depend on the free VRAM measured during export: two exports of the same command on differently loaded GPUs produce cores with different max_sequence_tokens, and a cap above the pool silently becomes the pool size (the description states this as intended, "as stock"). That is defensible for the pool, but it means the flag's identity is not reproducible from the manifest, which strengthens finding 2.

Also note the value is clamped by tokens rather than by Plan.guaranteed_tokens (:376-378), so --request-context N above the per-request share still admits one long request while all slots are full only in aggregate: unchanged stock behavior, worth stating in the docs row.

#4 [medium] Should fix: need/scope argument and missing tests

  1. Scope/justification. The charter's "What gets merged" admits "a measured performance/memory issue"; the description now carries a VRAM table (Qwen3.8-27B, RTX PRO 6000, concurrency 1-4, 16 GB freed at c=4), which answers the earlier "hypothetical deployment" objection (#454 review point 4), and AGENTS.md:165-169 is satisfied on its face. But the memory problem is a multi-model co-run ("leave no room for a second model"). Multi-model hosting is an explicit Non-Goal requiring maintainer sign-off (charter Non-Goals; AGENTS.md:171-175 "Reject unapproved scope expansion ... multi-model hosting and routing"). The flag itself is a preparation capacity, not hosting, so this is not a violation — but the stated motivation leans on a workflow the project does not support, and the description should say which single-model workflow the headroom buys (e.g. leaving free VRAM for the compositor or a later process, which --memory-limit -30G / [memory] reserve already express at serve time per docs/cli-design.md:1414-1418, 845-855).
  2. Overlap with existing mechanisms. --kv-cache-limit context already caps useful KV history at one prepared context and concurrency at one per active request (docs/cli-design.md:738, 828-843), and --memory-limit/[memory] reserve already bound the pool at serve time without re-export. The PR's contribution is that the cap also lowers the core's max_sequence_tokens and that the prepared pool shrinks at export. The description should say what --kv-cache-limit cannot do, since the earlier review raised exactly this (#454 review point 2). Evidence check: the measured table uses --kv-cache-limit concurrency (one prepared context per active request = 4 × 256K at default), so the delta is genuinely the prepared-context times concurrency product — the measurement supports the claim, but only at concurrency >= 2 and only with that limit mode; nothing isolates how much of the win comes from the smaller pool versus the smaller advertised ceiling.
  3. No tests. The diff adds none, for a change in shared planning code that alters exported cores. AGENTS.md:194-199 requires tests that exercise the affected behavior; tests/cli/test_planning.py (e.g. :71-120) is the natural home for prepared_context resolution, the <=0 rejection, and the below-chunk message. Note the below-chunk branch (planning.py:694-700) is untested and picks its message on prefill_chunk is None, not on whether the user set --request-context; with the recipe's own chunk (omitted flag) it tells the user to pass --prefill-chunk-size ... or a larger --request-context, which is correct, but with an explicit --prefill-chunk-size above a low target it reports only the chunk mismatch — fine. The branch is reachable only when a target is set below the chunk, since context >= chunk already holds at planning.py:621-623 for the stock path.
  4. Docs framing. docs/cli-design.md:446 calls --request-context a way to buy "concurrency headroom in a memory-constrained multi-model deployment", which names an unsupported workflow; the same table's Context-limit rows (:1443, :1493) are consistent with the code. docs/cli-design.md:738 still describes --kv-cache-limit as bounding history by "prepared context", which is now the capped one — consistent, no edit needed.