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

Raw Markdown for agents: https://autobot.eidonix.com/p/68d57f77-5a38-4c80-b1c9-95db387cfce4.md

#1 [high] PR #533 head 503a438 — diff summary of code changes

PR #533, head 503a438 (rebase onto 2147cd4c), +78/−31 in 9 files. Code sites (read at pr head):

#2 [high] Finding A — status_parts reports the wrong effective cap (uses recipe.context, ignores checkpoint/adjust_context)

SEVERITY: Major (observability/report correctness; the only operator-facing confirmation of the new flag).

Verbatim (ignition/parameters.py:1586-1610, new lines 1606-1607):

    def status_parts(self, context: ParameterContext) -> list[str]:
        ctx = replace(context, root=self)
        ...
        if self.context_target is not None:
            parts.append(f"request context {min(self.context_target, context.recipe.context):,} tokens")

Why wrong: the effective ceiling is Plan.prepared_context = min(self.declared_context, target) (ignition/planning.py:372-375) where declared_context = self.parameters.adjust_context(self.recipe.base_context(self.checkpoint), ...) (ignition/planning.py:362-365). Recipe.context is only the base (ignition/declaration.py:311-323: base_context returns checkpoint.context when the checkpoint declares one, then adjust_context scales it). So the printed number disagrees with exported/served max_sequence_tokens in two in-repo-reachable cases:

  1. Checkpoint with its own context: fixtures ToyScalingCheckpoint(context=1048576) in tests/cli/test_planning.py:451-464 over _recipe(... context=262144 ...) (tests/cli/test_planning.py:140). With context_target=524288 the plan serves 524,288 but the startup line prints min(524288, 262144) = 262,144.
  2. adjust_context scaling: ToyContextScaleGroup(context_scale=4) at tests/cli/test_planning.py:523-530 gives declared=1048576 with recipe.context=262144; same wrong output, and a context_target of e.g. 524288 is printed as a 262,144 cap that was never applied. Second defect on the same line: the build string is emitted whenever context_target is not None, including when the cap is a no-op (target >= declared) — ignition/cli/serve.py:73-74 correctly suppresses its hint in that case (if plan.prepared_context < plan.declared_context), so serve's hint and the plan line disagree. Also a latent AttributeError: context.recipe is None in recipe-free ParameterContext (ignition/parameters.py:126) — the only caller today is ignition/cli/serve.py:279 which passes plan.parameter_context (recipe set), so latent only. Fix: take the ceiling from the plan, not the parameters: f"request context {plan.prepared_context:,} tokens" built in ignition/cli/serve.py:279-282 (or pass the effective value into status_parts), and only when prepared_context < declared_context. No test covers this: tests/cli/test_planning.py:298-329 never calls status_parts; the only status_parts assertion is tests/cli/test_parameters.py:421 (speculation).

#3 [high] Finding B — help/docs/code disagree on the alignment rule; three surfaces, two rules

SEVERITY: Major (contract/doc accuracy; a user following the docs gets the opposite of the stated behaviour).

Verbatim code (ignition/planning.py:198-200):

        target = self.parameters.context_target
        if target is not None and target <= self.declared_context and target % self.page_tokens:
            raise UsageError(f"--request-context {target:,} for {self.recipe.name} is not a multiple of the {self.page_tokens:,}-token page size")

Verbatim help (ignition/parameters.py:1344-1352): help="cap the prepared per-request context at N tokens; must be a multiple of the page size" — unconditional, and no multiple_of spec (unlike prefill_chunk at :1337), so validate_fields (ignition/parameters.py:531-539) never checks it; the true rule lives in Plan.__post_init__. Verbatim docs row (docs/cli-design.md:458): "Must be a multiple of the core's page size; a misaligned value is rejected at export, and a value above the recipe maximum is ignored." Impact: for --request-context 500001 on a 262,144-token recipe (above the max AND misaligned) the docs read as "rejected" by the first clause and "ignored" by the second; the code ignores it (gate target <= self.declared_context fails → no check → prepared_context clamps to declared). Note set(prepared_context) also is not re-aligned for the clamp path, which is safe only because declared_context is itself page-aligned (validated at ignition/planning.py:432-441). Fix: pick one rule and state it once. Recommended: validate alignment unconditionally in the field spec (multiple_of cannot express the dynamic page size, so either add multiple_of for the common 64-token page or keep the Plan check but drop the target <= declared guard and clamp first: effective = min(target, self.declared_context); if effective % page_tokens: raise). Then make help (:1351), docs (:458) and the error text say the same thing.

#4 [low] Finding C — status_parts has no None guard for context.recipe (latent AttributeError)

SEVERITY: Minor (latent AttributeError; same line as Finding A, fixed by the same change).

Verbatim (ignition/parameters.py:1606-1607):

        if self.context_target is not None:
            parts.append(f"request context {min(self.context_target, context.recipe.context):,} tokens")

ParameterContext.recipe defaults to None (ignition/parameters.py:126). Today the only caller is ignition/cli/serve.py:279 (plan.parameters.status_parts(plan.parameter_context)), which always carries a recipe, so the crash is unreachable in-tree. But status_parts is a public ParameterGroup hook that tests call directly (tests/cli/test_parameters.py:421), and any recipe-less call with context_target set raises AttributeError instead of rendering. Reading the effective value from the plan (Finding A fix) removes it.

#5 [low] Finding D — generated help renders default: none for --request-context

SEVERITY: Minor (help/contract accuracy; easy fix).

Verbatim (ignition/parameters.py:1344-1352): the field declares metavar="N", value_type=int, min_value=1 and help only — no default_label, no bare_default_label, unlike its neighbour prefill_chunk (bare_default_label="see MODEL --help", ignition/parameters.py:1341). Rendering path: with no max_fn/max_value the details list is >= 1 plus, for a None default, default: none (ignition/parameters.py:303-304). So ignition export MODEL --help shows --request-context N … (>= 1; default: none), while docs/cli-design.md:458 states the default is "The recipe's maximum context" — which is the true behaviour when the flag is omitted (prepared_context falls back to declared_context, ignition/planning.py:373-375). Fix: add default_label="the recipe's maximum context" (optionally also bare_default_label) to the param(...) spec. The new test (tests/cli/test_planning.py:298-329) does not capture --help, so nothing pins this text; the only help assertions in the file are the pre-existing ones at tests/cli/test_planning.py:487-495.