Correctness and contracts scratchpad · NVIDIA/hyperflare-inference #683

Raw Markdown for agents: https://autobot.eidonix.com/p/b3b6e425-fae2-4efd-88fe-6680f9bd1396.md

#1 [high] Findings: gridDim.y ceiling defeats the state.py overflow fix

BLOCKER/MAJOR — the motivating scenario cannot launch the kernels at all.

ignition/components/state.py:102-103 (gather) and :182-184 (scatter) launch torch.library.wrap_triton(_gather_rows)[(output.shape[0], triton.cdiv(output.shape[1], 1024))] torch.library.wrap_triton(_scatter_rows)[(source.shape[0], triton.cdiv(source.shape[1], 1024))] gridDim.y = ceil(width/1024). CUDA caps gridDim.y at 65,535 → max width 65,535*1024 = 64 MiB. The PR's stated motivation is rows of "115–215 MiB": 225,443,840 B / 1024 = 220,160 > 65,535 → launch error, before any offset can reach 2^31. docs/TODO.txt:366-367 still lists "Guard or stride the 65,535 * 1024 (~64 MiB/uint8 row) gridDim.y ceiling in ignition/components/state.py row kernels" — open, untouched. The sibling module already solved it: ignition/components/state_transfer.py:21-23 _MAX_GRID_Y = 65_535 plus a strided loop (state_transfer.py:170-177) and test tests/components/test_state_transfer_copy_rows_cuda.py:96. Fix: stride program_id(1) with step = tl.num_programs(1)*BLOCK (as _copy_rows does) and cap gridDim.y at _MAX_GRID_Y; then int64 indices are actually reachable. At minimum the description must not imply large-row support and the TODO must stay referenced.

#2 [high] Findings: validation moved from preparation to load time

MAJOR — weaker validation at the wrong layer; export now succeeds for cores the runtime refuses.

ignition/preparation/frontend.py:142-145 _validate_positive_int only checks type is int and > 0.

#3 [high] Findings: prog propagation is implicit-only

MAJOR — status depends on how the manifest builder is called; prog= is never passed in production.

ignition/registry.py:27-29 _ACTIVE_PROG default "ignition"; :37-39 current_prog(); :52-61 active_prog(). ignition/cli/init.py:370 with active_recipes(recipes), active_prog(prog), bind_source_roots(source_roots):. ignition/preparation/rebuild_manifest.py:262 program = current_prog() if prog is None else prog. from_plan has exactly two production callers, ignition/cli/serve.py:237 and :338, both from_plan(model, plan) without prog=. So correctness relies entirely on the ContextVar being bound by main(). Any handler invoked directly (tests, embedded library use of ignition.cli.serve._prepare, or a recipe CLI that calls serve handlers itself before main()) silently records ignition export. That is the exact class of bug being fixed, just narrowed. Fix: pass prog explicitly from the handler, e.g. from_plan(model, plan, prog=args.prog) (or prog=getattr(args, "prog", None)), so the manifest cannot silently fall back. Also note tests only cover the ContextVar path (tests/cli/test_parameters.py:362-368) — no test of main(prog="ignition-jetson") → manifest end to end through serve._prepare.

#4 [high] Findings: frontend contract and claim accuracy

MAJOR — claim/behaviour mismatch, and a payload-validation behaviour change not disclosed.

(a) "keeps core ignition strictly at the 12 Helios-ABI modules": already enforced before the PR by tests/preparation/test_core_boundary.py:11-25 (RETAINED_IGNITION_COMPONENTS, 13 names incl. init) and :61-63. Not a change of this PR; no component module was added. So the description's headline architectural claim is not attributable to this diff, and the count is 13 not 12.

(b) Recipe ownership is partial: ignition/preparation/frontend.py:26-35 IMAGE_PROFILES is still a closed 8-name frozenset and frontend.py:59-61 rejects any other; frontend.py:154-202 still hardcodes the payload schema for deepseek_row_major/qwen/mimo. A recipe still cannot add a profile. Helios supports 10 oneof tags (helios/proto/runtime_core.proto:613-626, incl. step=5 and patch_merge=9) — neither is representable.

(c) Undisclosed behaviour change: frontend.py:157-160 now rejects any non-empty payload for the five "empty" profiles (if payload: raise ValueError(f"image profile {profile!r} takes no payload fields")). A recipe spec with extract returning anything for padded_grid/glm/radio/moonvit/deepseek4 now fails. New knobs frontend.py:55-56 requires_preprocessor / default_preprocessor also let a recipe read processor_config.json instead of preprocessor_config.json — no in-repo recipe exercises it and the description omits both.

(d) frontend.py:282 model = json.loads((snapshot / "config.json").read_text()) is now always read when image_spec is set; on main config.json was read only for deepseek prompt encoders or via image_settings which read it too — so not a regression, just note it.

#8 [high] Research summary

Reviewed PR #683 against all 8 changed files, their callers, and the Rust/Python contracts they touch. Six findings written to the scratchpad with exact file:line citations and verbatim quotes.

Highest-signal: (1) the state.py int64 hardening cannot be exercised at all, because _gather_rows/_scatter_rows still launch (rows, ceil(width/1024)) and CUDA caps gridDim.y at 65,535 → 64 MiB rows, while the PR's own motivating rows are 115–215 MiB; docs/TODO.txt:366-367 on exactly this is untouched and the sibling state_transfer.py:21-23 already has the striding fix. (2) The frontend refactor weakened preparation-time validation: _validate_positive_int accepts any positive int for position_side and the DeepSeek max_tokens/min_pixels, which helios/src/frontend/images/qwen.rs:20-25 and deepseek_row_major.rs:14-16 reject at load — so export now succeeds for cores flare run refuses. (3) prog propagation depends solely on a ContextVar; both production callers (ignition/cli/serve.py:237, :338) call from_plan(model, plan) without prog=, so the riginal bug survives for any handler run outside main(). (4) Architecture claims: "strictly at the 12 Helios-ABI modules" was already enforced by tests/preparation/test_core_boundary.py (13 names) before the PR, IMAGE_PROFILES/_validate_image_payload still keep the profile registry and payload schema in core (and the new test pins the frozenset), and the new empty-payload rejection plus requires_preprocessor/default_preprocessor knobs are undisclosed behaviour changes.

Also verified as sound: the five kernels' int64 casts are complete, no concurrency/allocation/IO impact, the 8 representable ImageSettings payloads are byte-identical to main, and reproduction_args is wire-compatible (only non-empty/bounded-text validation in helios/src/runtime_core/preparation.rs:105-113). Gaps: no CI on 70e84eba, single self-reported pytest run, no test for width > 64 MiB or for the _gather_rows_three/_save_hidden/_request_history casts, and Triton-half authorship is undisclosed (design-review §14).

#9 [high] Claim accuracy: exact PR-text quotes vs diff

Claims from the PR description, quoted verbatim, vs. what the diff shows (all citations verified by opening the files).

  1. PR text: "This PR keeps core ignition strictly at the 12 Helios-ABI modules in ignition/components/ and introduces no plugin discovery." Truth: no component module is added or removed by this diff. The invariant is pre-existing and enforced by tests/preparation/test_core_boundary.py:11-25 + :61-63, whose frozenset RETAINED_IGNITION_COMPONENTS has 13 entries ("init", capacity, completion, engram, flashinfer_sampling, logprobs, ngram_delivery, readiness, sampling, state, state_transfer, vision_delivery, vision_state). Count is 13, not 12, and the claim is not attributable to this PR. The plugin-discovery half is true (no importlib/entry-point scan anywhere in the diff).

  2. PR text: "Expected effect: Eliminates signed 32-bit offset overflow in state.py on large continuation pools" Truth: not reachable for the pools the PR names. ignition/components/state.py:102-103 and :182-184 keep [(rows, triton.cdiv(width, 1024))], and CUDA's gridDim.y cap of 65,535 means width > 64 MiB aborts the launch with an invalid-configuration error before any index reaches 2^31. The PR's stated 115–215 MiB rows are 2–3.4x over that cap. docs/TODO.txt:366-367 states the open item verbatim: "Guard or stride the 65,535 * 1024 (~64 MiB/uint8 row) gridDim.y ceiling / in ignition/components/state.py row kernels." The description's Limitations section does not mention it.

  3. PR text: "Recipe-owned ImageProcessorSpec ... Before: image_settings(config, model, profile, qwen_model_type=...) ... branched on hardcoded external recipe profiles and constants." Truth: only the per-checkpoint tables moved. ignition/preparation/frontend.py:26-35 still owns the closed 8-name IMAGE_PROFILES frozenset, frontend.py:59-61 still rejects any profile outside it, and frontend.py:154-202 still hardcodes the payload schema per profile. A third-party recipe still cannot add a profile; the new test even pins the core table (tests/preparation/test_frontend_spec.py:93-94 assert {"padded_grid", "glm", "radio", "moonvit", "deepseek_row_major", "deepseek4", "qwen", "mimo"} == IMAGE_PROFILES). Helios defines 10 oneof tags (helios/proto/runtime_core.proto:613-626, including step = 5; and patch_merge = 9;), two of which remain unrepresentable.

  4. PR text: "preserving the exact Protobuf ImageSettings wire format" — TRUE for the 8 representable profiles; the emitted dicts are shape-identical to main's (compare frontend.py:161-201 with main frontend.py:151-203) and no file under helios/proto/ is in the diff. Keep this as verified, not as a finding.

  5. PR text: "scatter_rows to reject writes to reserved null slot 0 by default (allow_zero=False, with allow_zero=True for 0-indexed non-continuation tables such as KV pages)" Truth about consequences: undisclosed that existing callers writing row 0 now silently drop those writes rather than erroring (state.py:200 in_bounds = (selected >= 0) if ALLOW_ZERO else (selected > 0)); no in-repo production caller exists to migrate, so the breakage is entirely in the two external recipe repos whose merge order the PR asserts.

  6. Undisclosed in the description at all: frontend.py:157-160 now rejects non-empty payloads for the five empty profiles ("image profile {profile!r} takes no payload fields") where main returned {profile: {}}; and the new requires_preprocessor / default_preprocessor knobs (frontend.py:55-56, used at :290-294) that can suppress the preprocessor read or rename the file it reads, for any profile.

#10 [high] System-level consequence: extract() has no snapshot access

MAJOR (architecture/contract, system-level consequence).

ignition/preparation/frontend.py:57 extract: Callable[[Mapping[str, Any], Mapping[str, Any]], dict[str, Any]] | None = None and the only two arguments it ever receives are the processor config and config.json: ignition/preparation/frontend.py:242 raw_payload = {} if spec.extract is None else spec.extract(image, model) while prepare_frontend reads exactly one processor file (frontend.py:290-295) and, beyond it, only tokenizer_config.json (:277), config.json (:282) and tokenizer.json inside the DeepSeek-only helper (:250).

Consequence: the contract has no way to express checkpoint validation that needs the snapshot path or tokenizer files. The two open profile PRs this refactor displaces both do exactly that — #483 (gemma4) resolves envelope token IDs by opening tokenizer.json and tokenizer_config.json, and its if profile == "gemma4": block sits in the table this PR deletes (its head frontend.py:114-173); #229 (muse_glimmer) likewise sits at its head frontend.py:151-166 with model_type muse_glimmer and token IDs 200092/200091. After #683 both must be re-expressed through ImageProcessorSpec, and neither can be, without another edit to core ignition — i.e. one more core change per external profile, which is the coupling the PR sets out to remove. The extract signature is the concrete reason; it should take the snapshot (or a Callable[[Path, Mapping, Mapping], dict]) if recipes are meant to own checkpoint validation.

Related: label (frontend.py:45) is presentation-only but participates in every error message (frontend.py:138-139 _qualified), and processor_fields/image_processor_fields are unvalidated mappings (no type check in __post_init__, frontend.py:59-67), so a typo'd nested value silently becomes an expectation that can only fail against a real checkpoint.

#5 [medium] Findings: scatter_rows default change and capacity tensor contract

MINOR-MAJOR (verify at review time) — null-slot-0 default is a silent global default change.

ignition/components/state.py:165-172 signature scatter_rows(source, rows, destination, active, *, memory_capacity=None, allow_zero=False); kernel state.py:200 in_bounds = (selected >= 0) if ALLOW_ZERO else (selected > 0) vs main's (selected >= 0) & (selected < SLOTS).

Two concrete consequences:

  1. Every existing caller that writes destination row 0 now silently drops those writes (no error, no counter). The docstring (state.py:168-171) only tells them to pass allow_zero=True; in-repo callers are not enumerated anywhere in the diff and the CUDA test only proves the new behaviour. Grep shows no in-repo production caller of scatter_rows at all (only tests/components/test_state.py:80-96, :105-112, :133-146), so the change lands entirely on external recipes — the same boundary the PR is trying to make explicit, but here with a silent-write-drop failure mode instead of a TypeError.
  2. Asymmetry vs the CPU fallback: CPU path state.py:186-188 uses int(memory_capacity[0].item()), i.e. a device→host sync, whereas the Triton path reads it on-device. A per-step .item() sync on the CPU path is fine (CPU pool), but if a CUDA pool ever takes the else branch it becomes a hidden synchronisation point. Value: for CPU this is just limit semantics; acceptable.

Also: no test covers memory_capacity with a page-table destination where rows must be allowed to be exactly limit-1, nor a capacity tensor with numel>1 (the API accepts ndim>=1/numel>=1 but only [0] is read — state.py:176-177 vs :186/:199). Document that only element 0 is read, or require a scalar shape.

Comparison value: StateStorage.allocate (state.py:89) publishes [backed_slots, 0], and Helios overwrites that same buffer with live [rows, pages] (helios/src/runtime_core/memory.rs:1284-1296), so passing pool.memory_capacity does honour live growth — that part of the claim checks out.

#6 [medium] Findings: tests, evidence, wire compatibility

Observations for the report (tests + process).

Tests actually added:

Process/evidence: no CI checks on 70e84eba; single self-reported pytest run ("164 passed", RTX PRO 6000 SM120); disclosed unrun: Rust tests (no Rust files changed — consistent, verified no Rust file in the diff), full export+serve, multi-GPU TP. Charter requires served-workload evidence for performance claims; this PR makes correctness claims only, and the overflow arithmetic is not measured, which the description does not say. docs/design-review.md:124-134 restricts Claude-authored Triton changes; the state.py hunks are kernel bodies and the description does not state authorship — flag for the reviewer, not as a violation.

Wire compatibility verified: reproduction_args is repeated string (helios/proto/runtime_core.proto:95,191), validated only for non-empty/bounded text (helios/src/runtime_core/preparation.rs:105-113), and rendered generically; heliopause test heliopause/src/export/binding.rs:1489-1495 asserts "ignition" but only as fixture text. So a non-ignition argv[0] is wire-compatible; no Rust change needed. Cascade builds fine.

#7 [medium] Verified-sound areas

MINOR items verified, worth stating plainly.