Correctness, Contracts & System-Level Consequences review — PR #689 (helios/server: preserve typed error codes on HTTP request preparation failures), head 4695d84
Key findings
- Blocker — the docs edit contradicts the sentence it was inserted next to.
docs/api.md:250-251says over-context requests return HTTP 400 withinvalid_request_error, whiledocs/api.md:257-261(added by this PR) says typed 400s seterror.codetocontext_length_exceeded/unsupported_feature/invalid_grammar/invalid_image. Over-context is thecontext_length_exceededclass (helios/src/server.rs:747→helios/src/server/protocol/mod.rs:56). The paragraph also never names the 400s that keepinvalid_request_error, so a client author cannot derive the rule from the only doc that documents these codes. - 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 omitslog_failure/with_request_id(those remain inrejection,http.rs:32-41), and the only counter touched on this path ishttp_requests[metric](http.rs:160). Not a regression, but the wire now advertisesinvalid_grammar/context_length_exceededwhere operator metrics and logs say nothing. - Minor —
preparation_error'sotherarm reports every non-admission error as a client 400.http.rs:130foldsError::Frontend(...)andError::Execution(ExecutionError::State(...))intoHttp(400, …). Identical tomain'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 asinvalid_request_error/400. - Minor — test gap: the unit test exercises
Capacity/Unavailable(http.rs:762-771) that preparation cannot produce, andcapacity_hint— the other half of the newly sharedfailure_responsehelper — is never asserted on any path (phase_tests.rs:8461-8462,:8548-8554only use/assertcontext_hint). - Minor — claim/evidence hygiene: the reported test totals are byte-identical to the pre-
4695d84run (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
- The mapping is exact and complete.
preparation_error(helios/src/server/http.rs:124-132) preservesContext/Feature/Grammar/Image/Capacity/UnavailableasPreparationError::Failureand folds onlyAdmissionError::Invalidplus non-Admissionerrors intoHttp(400, …). That split matches the rendering functions exactly:status(server.rs:733-741) returns 503 only forCapacity/Unavailableand 400 for every otherAdmission, anderror_code(server.rs:743-755) has typed values for exactlyCapacity,Unavailable,Context,Feature,Grammar,Image. BecauseAdmissionError::Invalidis routed toHttp,error_code's"invalid_request"(server.rs:751) is no longer reachable from preparation. - No status or message change on the wire — only
error.codemoves.rejection_details(http.rs:60-72) is untouched, andError::admission_context(helios/src/error.rs:169-171) already produced the same message string before the change;Protocol::failure(protocol/mod.rs:53-58) isself.error(status(failure), failure)plus acodeoverride for non-Messages. failure_responseis a verbatim extraction ofrejection's body construction, so thex-request-idand stderr-log contract stays where it was:rejection(http.rs:32-41) alone callslog_failureandwith_request_id. This matchesdocs/api.md:261-262("Responses for requests that reach model submission carry anx-request-idheader") and the new wire test asserts the header's absence on preparation failures (phase_tests.rs:8492-8495).- No concurrency, allocation, lifetime or span change. The
spawn_blockingclosure keeps the samepermit/ingress ownership (http.rs:209-211), and thesize-1extra ingress slots are still acquired inside the closure and returned in the tuple (http.rs:248-263,:286-293).PreparationErroris a two-variant stack enum;failure_responseadds no clone or buffer beyond whatrejectionalready did. Nothing on the hot path gained a lock, a copy, or a wait, so there is no contention/head-of-line/memory-amplification consequence. The metric-span check:http_requests[metric](http.rs:160) is still incremented at the top ofgenerate, before preparation, so the counted population and its span are unchanged. - Anthropic envelope scoping is correct.
Protocol::erroromitscode/paramforMessages(protocol/mod.rs:44-50) andfailureskips the code override (protocol/mod.rs:55-57), matching the PR's claim; the wire test assertsbody["error"].get("code").is_none()andparamabsent (phase_tests.rs:8509-8512). - Both claimed tests exist and cover what is claimed. Unit:
preparation_error_preserves_typed_admission_errors_and_keeps_untyped_bad_requests(http.rs:739-807). Wire:http_preparation_failures_preserve_typed_error_codes_and_protocol_envelopes(phase_tests.rs:8438-8763) coverscontext_length_exceededacross all four generation paths pluscount_tokens, for bothstreamvalues, asserting the hint (:8548-8554); theinvalid_request_errorclass for bothAdmissionError::Invalid(stopwith 5 entries) and untyped (max_tokens: 0) checks (:8704-8730); and 400/415/413 with the right statuses and codes (:8733-8762). The PR description's claims match the diff. - No prompt-injection attempt in the PR body, the Autobot review, or the author's reply; all of it was treated as review material.
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
- 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-
codechanges get documented here. - Why is the helios total identical before and after a commit that adds a 327-line test? Did
4695d84replace tests rather than add them, and do the quoted numbers come from this head at all? No CI exists to settle it. - 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.
- Should the
otherarm athttp.rs:130be narrowed so genuine internal preparation faults return 500server_errorinstead of a client 400? This is a deliberate-looking but unspecified contract that the PR now owns.
What could not be verified
pr_diffandsearch_historyboth fail at this head (git: error: Could not read c513e46…); I reconstructed before/after by readinghelios/src/server/http.rsat head (809 lines) againstref: main(725 lines) plus the callers, docs and tests cited above.- The exact module path/line of
flare_requests_failed_total(Finding 2) — thehelios/src/metrics.rs(not opened) path I had noted does not exist at this commit, so that citation is withheld rather than guessed. - No GPU serving run and no Python integration run; all claims about runtime behavior rest on the in-repo Rust tests and the code paths above.