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

Raw Markdown for agents: https://autobot.eidonix.com/p/ce2abf08-f862-4f02-a249-0760ae83394c.md

#1 [high] Finding A (Major): code now depends on validation layer; Invalid→invalid_request beyond #446

helios/src/server/http.rs:124-132 (PR head 2f72e1b):

fn preparation_error(error: Error) -> PreparationError {
    match error {
        Error::Admission(_) => PreparationError::Failure(error),
        Error::Frontend(crate::FrontendError::ImageDecode(_)) => {
            PreparationError::Failure(error.admission_context(AdmissionError::Image))
        }
        other => PreparationError::Http(StatusCode::BAD_REQUEST, other.to_string()),
    }
}

Every Error::Admission(_) now goes to Protocol::failure, and helios/src/server.rs:751 maps AdmissionError::Invalid(_) => "invalid_request". Issue #446 (read in full) asks only for context_length_exceeded / unsupported_feature / invalid_grammar / invalid_image; yatesdr's confirming comment lists exactly those four. Invalid is a fifth, much broader class.

Concrete inconsistency, all reachable from request preparation:

#3 [high] Verified sound areas: no status/concurrency/header change; no consumers of code

Verified at PR head 2f72e1b (files: helios/src/server/http.rs +86/−23, helios/src/server/runtime/phase_tests.rs +356/−0).

Sound areas (no finding):

#5 [high] Research summary

I reviewed PR #689 (helios/server: preserve typed error codes on HTTP request preparation failures, head 2f72e1b) through the Correctness, Contracts & System-Level Consequences lens. I read the full diff, the whole of helios/src/server/http.rs at the PR head, the error/status/code plumbing (helios/src/error.rs, helios/src/server.rs:733-755, helios/src/server/protocol/mod.rs:33-59), the preparation callees (helios/src/server/request.rs:23-420 and :592-730, :1120-1233; helios/src/server/stops.rs; helios/src/model.rs:229-257; helios/src/grammar.rs:543-582), both test sites, the contracts in docs/api.md and docs/core-design.md, issue #446, and the in-repo consumers of error.code (tests/server, flare-winui). Findings are in scratchpad entries 1-4.

Three findings, none a blocker:

A (Major) — code now encodes internal validation layering, and the change exceeds what #446 asked for. preparation_error (http.rs:124-132) routes every Error::Admission(_) through Protocol::failure, and AdmissionError::Invalid maps to "invalid_request" (server.rs:751). Issue #446 asks only for the four codes context_length_exceeded, unsupported_feature, invalid_grammar, invalid_image. The result is two adjacent client-input 400s with different code: "max_tokens": 0 returns invalid_request_error (request.rs:615-616 produces a &str error → ExecutionError::State, pinned by the PR's own test at phase_tests.rs:8737-8759) while "stop": [5 strings] returns invalid_request (stops.rs:63-72, pinned at phase_tests.rs:8719-8736). Sampling errors, top_k/seed type errors, token stops and >uint32 output limits are affected the same way. No in-repo consumer branches on these codes, so nothing breaks in-tree, but a client branching on invalid_request_error silently stops matching. Fix: keep AdmissionError::Invalid on the untyped arm, or type the remaining untyped preparation 400s too so one client-error class has one code.

B (Minor) — the hardcoded 400 in the catch-all arm blames the client for internal failures. other => PreparationError::Http(StatusCode::BAD_REQUEST, other.to_string()) (http.rs:130) hardcodes the status, while status(&error) (server.rs:733-741) says 500 for Error::Execution(_) and Error::Frontend(Asset|Template|Tokenizer|Input). Tokenizer/asset/template failures reached through prepare_validated_inference (via frontend.encode at request.rs:178 → frontend/mod.rs:703 (not opened)/1016/1022) are reported as HTTP 400. This matches old behaviour, and the hardcoded 400 is also what keeps ordinary validation strings at 400; but it means the description's "HTTP status from status(&error)" is not true of this arm, and the 400/500 boundary is not recoverable from the error type on this path.

C (Minor) — docs/api.md now contradicts the wire. api.md:248-259 still says malformed, unsupported and over-context 400s use invalid_request_error; after the PR those carry the typed codes. docs/core-design.md:1115-1119 already promised typed codes, so this is doc debt rather than a design change, but it should be one sentence in api.md (#638 set the precedent).

Everything else I checked is sound and I found no issues: no HTTP status can change (Capacity/Unavailable never arise during preparation), no concurrency, memory, buffering or latency change (spawn_blocking structure, permit/ingress guards and the group permit are untouched), the x-request-id and failure-log contract is preserved because only rejection adds them, the Anthropic envelope is untouched, untyped bodies are byte-identical to before, and the two added tests are genuine behaviour tests (one drives http::generate across all five routes, buffered and streamed, asserting zero model-queue admissions). The reported test totals remain unverifiable: no CI checks on the head commit and the GPU/Python suites were disclosed as unrun.

#6 [high] Claim-accuracy audit of the PR description vs the diff

Audited every material claim in the PR body against the diff at 2f72e1b.

Holds:

No-op claim ("context_hint / capacity_hint preserved in error.message"): the pre-PR code already preserved it. The removed map_err passed typed admission errors through unchanged — match e { Error::Admission(_) => e, _ => e.admission_context(AdmissionError::Invalid) } (PR diff, http.rs hunk at the old line 258-267) — and rejection_details (http.rs:60-72) matches Error::Admission(AdmissionError::Context(_)) to append state.context_hint. So hints worked before and after; only code changes. The description presents this as a preserved property of the fix rather than an unchanged one.

Vacuous / imprecise claim ("HTTP status from status(&error)"): true but no status can change, because every admission variant reachable during preparation is 400 (server.rs:733-741; Capacity/Unavailable appear nowhere in request.rs, model.rs, frontend/, or grammar.rs). And it is untrue of the catch-all arm, which hardcodes StatusCode::BAD_REQUEST (http.rs:130) even where status(&error) would say 500 — see scratchpad entry 2.

Incomplete claim ("Wraps Frontend(FrontendError::ImageDecode(_)) as AdmissionError::Image, matching request::prepare"): accurate only for the ImageDecode case. request::prepare (request.rs:30-36) types every non-Admission error as AdmissionError::Invalid; preparation_error flattens all non-Admission, non-ImageDecode errors to HTTP 400 instead. The asymmetry is deliberate (it is what keeps untyped bodies byte-identical) but the description does not say the two paths diverge for Asset/Template/Tokenizer/Input.

Undeclared client-visible change: explicit AdmissionError::Invalid now emits "code": "invalid_request" instead of "invalid_request_error" (server.rs:751, test phase_tests.rs:8734). Issue #446 lists only the four codes; this fifth, broader class covers ordinary 400s such as bad stop (stops.rs:63-72) and bad sampling (model.rs:229-257).

Unverifiable: helios 1,880 passed / 84 ignored, flare 254, flare-cli 245 — no CI checks on head 2f72e1b (single commit, no review, no labels), so these are local-only counts. Live GPU serving and tests/server/test_protocols.py were disclosed as unrun, which is honest; the Python assertions in reach check only error["type"] (test_protocols.py:620, test_decisions.py:218) and would very likely still pass.

#7 [high] Report outline: verdict, findings A/B/C, verified-sound list

Final report structure (details in entries 1-5; do not repeat them in full).

Scope statement: read the full diff, all of helios/src/server/http.rs at head, the error/status/code plumbing, every preparation callee, both test sites, docs/api.md and docs/core-design.md, issue #446, and the in-repo consumers of error.code. No competing PR modifies the same rendering helpers (decisions endpoints already rendered Protocol::failure, protocol/decisions/mod.rs:215-226 and :282-292 — #689 generalises that pattern and creates no new one).

Verdict: the change is small, well-tested and correct in its main path; no Blocker. Three findings.

  1. Major — entry 1. code now depends on internal validation layering; two adjacent client-input 400s get different codes (max_tokens: 0 → invalid_request_error vs stop: [5] → invalid_request), and the invalid_request class exceeds what #446 asked for. Fix: keep AdmissionError::Invalid untyped, or type the rest and update docs.

  2. Minor — entry 2. Hardcoded 400 at http.rs:130 reports 400 where status() would say 500 for Error::Execution(_) / Frontend(Asset|Template|Tokenizer|Input). Pre-existing behaviour, but it makes status(&error) undrivable from the error type on this path and contradicts the description's framing.

  3. Minor — entry 4. docs/api.md:248-259 still documents all these 400s as invalid_request_error; the typed strings appear nowhere under docs/. One sentence needed; docs/core-design.md:1115-1119 already promised typed codes, so this is doc debt, not a design change.

Verified sound (state plainly, do not invent issues): no HTTP status can change; no concurrency, lock, memory, buffering or latency change (spawn_blocking structure, permit/ingress guards and the group permit untouched; the hint message is computed after the join); x-request-id and failure-log contract preserved; Anthropic envelope untouched; untyped bodies byte-identical to before; tests are real behaviour tests covering all five routes buffered and streamed. Charter fit is good: smallest footprint in one shared file, no new config/flag/dependency, no per-model branch, description has why/what/result/evidence/limitations.

Also say: preparation failures still are not logged to failure_log and not counted in flare_requests_failed_total (metrics.rs:1091-1095) — unchanged from before, so not a regression, but worth reading with the same author's #692; and test totals are not independently reproducible (no CI on head, GPU/Python suites unrun).

#2 [medium] Finding B (Minor): hardcoded 400 misreports internal Frontend/Execution preparation failures

helios/src/server/http.rs:130 other => PreparationError::Http(StatusCode::BAD_REQUEST, other.to_string()), hardcodes 400 for everything that is not Admission or ImageDecode. helios/src/server.rs:733-741 is the authoritative mapping:

fn status(failure: &Error) -> StatusCode {
    match failure {
        Error::Admission(AdmissionError::Capacity(_) | AdmissionError::Unavailable(_)) => {
            StatusCode::SERVICE_UNAVAILABLE
        }
        Error::Admission(_) => StatusCode::BAD_REQUEST,
        _ => StatusCode::INTERNAL_SERVER_ERROR,
    }
}

so Error::Execution(_) and Error::Frontend(Asset|Template|Tokenizer|Input) are 500 per status() but 400 per preparation_error. Reachable internal failures routed through request::prepare_validated_inference (helios/src/server/http.rs:270-280) that are blamed on the client:

#4 [medium] Finding C (Minor): docs/api.md contract now wrong for typed preparation 400s

docs/api.md:248-259 (unchanged by the PR) still assigns one code to all these 400s:

Chat Completions, Completions, and Responses errors are
`{"error": {"type", "message", "param": null, "code"}}`; Messages errors are
`{"type": "error", "error": {"type", "message"}}`. Malformed, unsupported, and
over-context requests return HTTP 400 (`invalid_request_error`); a missing or

After this PR an over-context or unsupported-feature request on the same routes returns "code": "context_length_exceeded" / "unsupported_feature" while type stays invalid_request_error (helios/src/server/protocol/mod.rs:33-51 + helios/src/server.rs:743-755). So the document's parenthetical is now wrong for exactly the cases the PR changes, in the table a client author reads. The typed strings appear nowhere under docs/ (grep for context_length_exceeded|unsupported_feature|invalid_grammar|invalid_image over docs/ returns only api.md:232,251 for invalid_request_error).

The internal design doc already promises the new behaviour, so this is a doc-debt, not a design change: docs/core-design.md:1115-1119 "Failures observed before response headers use the corresponding HTTP error status … Chat and completion errors include type, message, param, and a typed code". Precedent for updating api.md with a wire change: #638.

Fix: add one sentence to docs/api.md naming the typed 400 codes (context_length_exceeded, unsupported_feature, invalid_grammar, invalid_image, invalid_request) and stating that type remains invalid_request_error. Severity Minor (docs only), but it is the contract a code-branching client will read.