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

Raw Markdown for agents: https://autobot.eidonix.com/p/4f66de19-7319-427c-8982-1c635d1a5641.md

Correctness, Contracts & System-Level Consequences review — PR #689 (helios/server: preserve typed error codes on HTTP request preparation failures), head 4695d84

Key findings

  1. Blocker — the docs edit contradicts the sentence it was inserted next to. docs/api.md:250-251 says over-context requests return HTTP 400 with invalid_request_error, while docs/api.md:257-261 (added by this PR) says typed 400s set error.code to context_length_exceeded/unsupported_feature/invalid_grammar/invalid_image. Over-context is the context_length_exceeded class (helios/src/server.rs:747 → helios/src/server/protocol/mod.rs:56). The paragraph also never names the 400s that keep invalid_request_error, so a client author cannot derive the rule from the only doc that documents these codes.
  2. Minor — typed preparation failures are now visible on the wire but invisible to the failure metric and the stderr failure log. failure_response (http.rs:26-31) deliberately omits log_failure/with_request_id (those remain in rejection, http.rs:32-41), and the only counter touched on this path is http_requests[metric] (http.rs:160). Not a regression, but the wire now advertises invalid_grammar/context_length_exceeded where operator metrics and logs say nothing.
  3. Minor — preparation_error's other arm reports every non-admission error as a client 400. http.rs:130 folds Error::Frontend(...) and Error::Execution(ExecutionError::State(...)) into Http(400, …). Identical to main's behavior (parity, not regression), but the arm is now the named "untyped bad requests" contract, so an internal frontend/worker failure during preparation would be reported to clients as invalid_request_error/400.
  4. Minor — test gap: the unit test exercises Capacity/Unavailable (http.rs:762-771) that preparation cannot produce, and capacity_hint — the other half of the newly shared failure_response helper — is never asserted on any path (phase_tests.rs:8461-8462, :8548-8554 only use/assert context_hint).
  5. Minor — claim/evidence hygiene: the reported test totals are byte-identical to the pre-4695d84 run (helios 1,880/84, flare 254/4, flare-cli 245/3) although this commit adds a 327-line test plus ~100 lines of assertions, and there are no CI checks at this head, so the numbers cannot be tied to this commit.

What I verified as sound (see §0) — the mechanical mapping, the status/message invariance, the x-request-id/logging contract boundary, the Anthropic envelope scoping, and the absence of any concurrency/allocation/lifetime change. The PR is, mechanically, a clean and correct fix for #446; the substantive problem is the contract text it adds, not the code path it changes.


0. Verified sound — no findings


1. Correctness, Safety & Platform Parity

No defect found in the changed control flow. The two items below are the closest things to correctness risks, and both are pre-existing behavior rather than regressions introduced here.

Finding 3 — Minor — the "untyped" arm reports internal errors as client 400s

helios/src/server/http.rs:124-132:

fn preparation_error(error: Error) -> PreparationError {
    match error {
        Error::Admission(AdmissionError::Invalid(_)) => {
            PreparationError::Http(StatusCode::BAD_REQUEST, error.to_string())
        }
        Error::Admission(_) => PreparationError::Failure(error),
        other => PreparationError::Http(StatusCode::BAD_REQUEST, other.to_string()),
    }
}

The other arm catches everything that is not an Error::Admission, including Error::Frontend(...) (e.g. frontend.render_chat in the preparation path) and Error::Execution(ExecutionError::State(...)) — impl From<String> for Error maps a bare string to Execution(ExecutionError::State(...)) (helios/src/error.rs:174-177), and error code _ => "server_error" with status 500 is only reachable through status/error_code for non-admission errors (server.rs:739, :753).

Impact: a genuinely broken frontend or worker discovered during preparation is reported to the client as HTTP 400 invalid_request_error forever, which is the wrong contract and hides server faults from the caller. This is parity with main, not a regression — main reached the same outcome through _ => e.admission_context(AdmissionError::Invalid) → status → 400. The PR simply names this arm as the intended "untyped bad requests" contract, which turns an accident into a specification.

Fix (cheap): add a comment at http.rs:130 stating the fold is deliberate and limited to request-shaped preparation errors, or narrow the arm to Error::Execution(ExecutionError::State(_)) so other classes fall through to Failure and render 500 via failure_response.

Finding 2 — Minor — wire-visible typed failures stay invisible to the failure metric and the stderr failure log

helios/src/server/http.rs:26-41:

fn failure_response(state: &HttpState, protocol: Protocol, failure: Error) -> Response {
    let mut body = protocol.failure(&failure);
    let (status, message) = rejection_details(state, failure);
    body["error"]["message"] = message.into();
    (status, Json(body)).into_response()
}
fn rejection(
    ...
    if state.log_to_stderr { log_failure(id, stage, &failure); }
    with_request_id(failure_response(state, protocol, failure), id)

On the preparation path the only accounting is state.model.metrics().http_requests[metric].fetch_add(1, Ordering::Relaxed) at http.rs:160; flare_requests_failed_total is never incremented and no failure_log line is emitted. Not a regression (the pre-change http::error path also logged and counted nothing) and the x-request-id docs contract argues against attaching a request id here — but the wire now advertises invalid_grammar and context_length_exceeded where the operator's metrics and stderr say nothing at all. Fix: state the scope explicitly in the PR description, or add the metric increment at the failure_response call site (http.rs:289-291), so the divergence is a recorded decision rather than an omission (the same-author #692 covers failure accounting).

Citation caveat: the flare_requests_failed_total counter's definition lives in a metrics module whose exact path/line I could not re-open at this head (helios/src/metrics.rs (not opened) is not that path); the finding as stated rests only on the verified http.rs:26-31, :32-41 and :160.


2. Unintended System-Level Consequences

None found, stated plainly. Preparation still runs on the blocking pool under one owned frontend_slots permit plus the ingress permit (http.rs:197-211); this change neither adds an await, a lock, or an allocation, nor reorders slot acquisition/release. size-1 extra ingress slots are still acquired inside the closure and released with the returned tuple (http.rs:248-263, :286-293), so there is no new partial-failure window: every ? in the closure drops _permit/_ingress/extra together, exactly as on main. Failure blast radius is unchanged — a typed preparation failure returns before enqueue, and the new wire test asserts zero queue admissions via receiver.try_recv().is_err() throughout (phase_tests.rs:8555, :8699, :8729, :8743-8761). Metrics scope is unchanged (see §0, span check on http.rs:160). No platform-parity dimension (Unix/Windows, encoding) is touched: decode_body's 415/413/400 paths (http.rs:84-118) are untouched and still route through PreparationError::Http → http::error.


3. Architecture, Contracts & Charter Compliance

Finding 1 — Blocker — the new docs sentence contradicts its own paragraph and omits the rule

docs/api.md:248-262:

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
invalid key returns 401 (`authentication_error`); …
…
`invalid_request_error`. Responses for requests that reach model submission

and, six lines later, the sentence this PR adds (docs/api.md:257-261):

return 500. 5xx errors use `server_error`, or `api_error` on Messages. On Chat
Completions, Completions, and Responses, typed HTTP 400 rejections set
`error.code` to `context_length_exceeded`, `unsupported_feature`,
`invalid_grammar`, or `invalid_image` while keeping `error.type` as
`invalid_request_error`.

"over-context requests return HTTP 400 (invalid_request_error)" is precisely the class whose code the added sentence changes to context_length_exceeded — verified: error_code → "context_length_exceeded" for AdmissionError::Context (server.rs:747), rendered by Protocol::failure (protocol/mod.rs:56), and asserted on the wire at phase_tests.rs:8547.

Impact: the PR's own contract statement is self-refuting for the single most common typed rejection (over-context), and the reader cannot derive the general rule, because the paragraph never says which 400s keep invalid_request_error — invalid JSON (http.rs:112-117), the AdmissionError::Invalid validation class, and untyped checks such as max_tokens: 0 — nor that 415 (unknown Content-Encoding, http.rs:94-99) also keeps it. docs/api.md is the only place these codes are documented, so there is no second source a client author could consult. Sibling #638 is the precedent that a wire-visible code change is documented in-PR in this same file.

Fix: split the sentence and name both halves; e.g. "Malformed and unsupported requests return HTTP 400 (invalid_request_error); a request whose prompt plus output limit exceeds the prepared context returns HTTP 400 with error.code = context_length_exceeded…", followed by one sentence enumerating the 400/415 cases that stay invalid_request_error. The protocol scoping in the added sentence is otherwise correct (Messages carries no code/param — protocol/mod.rs:44-50, :55-57) and should be kept.

Charter/layer note: the change is well placed — it removes an error-class flattening in the HTTP layer rather than adding a per-model branch or a flag; no new wire field, no default behavior change for untyped 400s, and no owner-signoff-gated surface (no captured-graph op contract, no recipe, no public Rust API) is touched. Nothing here needs AGENTS.md sign-off, and no performance claim is made that would require #210 evidence.


4. Tests & Claim Accuracy

Finding 4 — Minor — unreachable cases tested, and capacity_hint never asserted

helios/src/server/http.rs:762-771 (unit test):

        (
            Error::admission(AdmissionError::Capacity, "capacity full"),
            "capacity_exhausted",
            StatusCode::SERVICE_UNAVAILABLE,
        ),
        (
            Error::admission(AdmissionError::Unavailable, "runtime paused"),
            "server_unavailable",
            StatusCode::SERVICE_UNAVAILABLE,
        ),

and the wire test only ever configures/asserts the context hint (phase_tests.rs:8461-8462, :8548-8554):

            s.max_body_bytes = 4096;
            s.context_hint = context_hint.to_owned();

capacity_hint is selected only for Error::Admission(AdmissionError::Capacity(_)) (http.rs:63), and no preparation site constructs Capacity or Unavailable — those arise after preparation, at enqueue. So the two Failure variants this test exercises for status/error_code cannot occur on the path under test, while the one hint that failure_response newly shares and that is reachable (context_hint) is covered — leaving the helper's hint behavior half-proven and the unit test implying preparation coverage it does not have.

Impact: low (the unit test still validates the preparation_error mapping, which is the point), but it makes the PR description's claim of coverage across Capacity/Unavailable misleading. Fix: drop the unreachable Capacity/Unavailable rows (their rendering is already covered through rejection), or add one assertion driving capacity_hint through failure_response.

Finding 5 — Minor — reported test totals are unchanged by this commit and unattributable

The PR reports helios 1,880 passed / 84 ignored, flare 254 / 4, flare-cli 245 / 3 — identical to the pre-4695d84 run, despite this head adding a 327-line wire test (phase_tests.rs:8438-8763), a rewritten make_state helper (:8444-8465), and a rewritten unit test (http.rs:739-807). No CI checks exist at 4695d84, so nothing ties the numbers to this diff; two readings are possible (tests were replaced rather than added, or the numbers predate the commit) and neither is checkable from the branch.

Also: tests/server/test_protocols.py was not run. I verified the in-repo Python assertions only inspect error.type (e.g. tests/server/test_protocols.py:620) and code == "model_not_found" elsewhere, so no breakage is expected from changing only code on typed 400s — but that is reasoning from reading the assertions, not evidence from a run, and the PR description correctly flags the limitation.

Fix: re-run the three suites at 4695d84 and quote the new counts, and state explicitly that the Python suite is unrun.


Open questions

  1. Will the docs contradiction (Finding 1) be fixed in-PR? The PR already edits that exact paragraph, so the marginal cost is one sentence — and #638 is the precedent that wire-code changes get documented here.
  2. Why is the helios total identical before and after a commit that adds a 327-line test? Did 4695d84 replace tests rather than add them, and do the quoted numbers come from this head at all? No CI exists to settle it.
  3. Is the metric/log gap (Finding 2) intentionally deferred to same-author #692, or an omission this PR should state? Either answer is acceptable; silence on the record is the problem.
  4. Should the other arm at http.rs:130 be narrowed so genuine internal preparation faults return 500 server_error instead of a client 400? This is a deliberate-looking but unspecified contract that the PR now owns.

What could not be verified