PR #689: helios/server: preserve typed error codes on HTTP request preparation failures

Raw Markdown for agents: https://autobot.eidonix.com/api/v1/cases/fb1c34cd-2ca4-4c66-9f70-2ce19b460585

Opened by a workflow run, Dec 2, 2026 4:06 PM EST. decide malicious: all_clear (100%): No malicious content found

explore

Author: jcartu (Joshua Cartu, GitHub association CONTRIBUTOR; 3 merged / 3 closed / 10 open PRs in 180 days, merged helios/src work includes #418, #416, FP32 parameter binding; Discord: jcartu) Motivation: Requests rejected during preparation (over-long context, unsupported feature, bad grammar, bad image) returned the generic code: "invalid_request_error" even though the server already knows a specific code for each, because preparation errors were flattened to (status, message) and re-rendered through Protocol::error. This PR keeps the typed error across the spawn_blocking boundary and renders it through the same Protocol::failure path already used after admission, fixing issue #446. Scale: +442 / −23 lines in 2 files (helios/src/server/http.rs, helios/src/server/runtime/phase_tests.rs) Proposal:

Full report · Notes

Value Proposition

Value Proposition — PR #689, "helios/server: preserve typed error codes on HTTP request preparation failures"

Charter alignment — strong. #689 makes the ingress preparation path obey an already-documented contract: docs/core-design.md:1115-1119 states pre-header failures use the corresponding HTTP status and that "Chat and completion errors include type, message, param, and a typed code". It does so at the shared rendering layer — private helpers in a single file (failure_response, PreparationError, preparation_error), no per-model branches, no new flags, aliases, defaults, config or dependencies, so none of the charter's "keep the runtime small / no magic defaults" rules are brushed. It also closes the last straggler: the decisions endpoints already rendered Protocol::failure from inside spawn_blocking. The description carries the charter's four required parts plus disclosed limitations, and the fix targets the root cause (rendering through the untyped http::error path) rather than swallowing the error.

Novelty & status — additive. Not obsolete: no commit on main since the branch point (c513e46) touches http.rs or phase_tests.rs. Not superseded: related_items yields only issue #446, and no other open or closed PR modifies the error-rendering helpers. Neighbours #691/#692 touch the same generate preamble but are complementary in intent (textual conflicts only). The problem is independently confirmed by yatesdr, an area owner with 49 commits in helios/src — the strongest external signal in the dossier, though the issue is only ~11 days old with one comment and no reactions.

Value vs maintenance cost. Cost is low: +442/−23 across two files, no public Rust API change, and because every reachable preparation admission variant already maps to HTTP 400 (server.rs:733-741), no status code or client retry behaviour moves. Only error.code changes on OpenAI-shaped routes; /v1/messages and /v1/messages/count_tokens envelopes are unchanged. The new tests are CPU/axum-level, and .github/workflows/native-serving.yml runs exactly that helios test invocation, so the branch-local-only totals become reproducible on merge. Benefit is narrow but legitimate: SDK clients that branch on code get the documented strings. No prompt-injection or instruction-directing content was found in the reviewed material.

What must change before merge:

  1. Scope creep, undeclared wire change. AdmissionError::Invalid now renders "invalid_request" instead of "invalid_request_error" — a fifth, broader class of 400s (bad stop, bad sampling params) that #446 does not request. Drop it or justify it explicitly; it is the one edit that changes behaviour for ordinary client mistakes.
  2. Undeclared asymmetry. Only FrontendError::ImageDecode is typed; Asset/Template/Tokenizer/Input still flatten to invalid_request_error, while request::prepare types them Invalid. State which contract is intended.
  3. Docs parity. docs/api.md:248-259 lists only invalid_request_error; sibling PR #638 set the precedent of documenting its own wire change.

Verdict: Worth it with changes.

Full report Decide Value: yes (100%): This change is worth reviewing: it provides value to the project in line with its charter.

Classify intake

Selected: triage:review, bug, area:api

Threshold: 65%

Triage

Priority

Type

Area

Model

Apply Labels (Intake)

Applied: +triage:review, +bug, +area:api

Subtraction and simplicity

Subtraction/Simplicity/Conventions review of PR #689.

Verdict: the production change in helios/src/server/http.rs is already lean — failure_response (http.rs:26-31) is an extraction that removes duplication, rejection (http.rs:32-41) collapses to three delegating lines, PreparationError replaces the old rejection_details(…AdmissionError::Invalid) hack, and there are no flags, config knobs, new deps, or dead public API.

Findings:

  1. phase_tests.rs:8452-8480 hand-rebuilds a full HttpState literal field-for-field instead of mutating the shared http_state_for helper (defined :4273-4295); the repo pattern is one line, :5086-5087 Arc::get_mut(&mut state).unwrap().thinking_token_budget = Some(2);. Three Arc::get_mut assignments (images, context_hint, max_body_bytes = 4096) remove ~28 lines and stop a copy of every field from rotting as sibling PRs #691/#692 add fields.
  2. Three sections of the new wire test share an identical six-line loop body (phase_tests.rs:8632-8638, 8689-8695, 8711-8717), differing only in the expected code string and one boolean. Folding into one for (expected_code, with_images, path, payload) table removes ~100 lines and keeps coverage.
  3. http.rs:127-129's FrontendError::ImageDecode arm cannot fire from the only call path: every image site is already re-typed to AdmissionError::Image at request.rs:1141, 1194, 1196, 1208, 1230. It is a narrower duplicate of request.rs:30-36 and the exact place to delete the Asset/Template/Tokenizer/Input asymmetry; drop it plus the unit-test row at http.rs:758-761.
  4. Optional: http.rs:212-213's .map_err(|(status, message)| PreparationError::Http(status, message)) is a hand-written From; an impl makes it decode_body(...)?.

Not findings: the failure_response/rejection split correctly keeps log_failure + x-request-id post-submission only; rejection_details is reused, not duplicated; the unit test is good. No structural AGENTS.md violations (no helios/AGENTS.md exists).

Open: whether maintainers prefer deleting the ImageDecode arm or typing all FrontendError variants during preparation; whether the AdmissionError::Invalid → invalid_request delta is in scope; whether docs/api.md:248-259 (not opened) should list the typed 400 codes. No CI on head 2f72e1b, so test totals are unverified.

Full report · Notes

Correctness and contracts

Reviewed PR #689 (helios/server: preserve typed error codes on HTTP request preparation failures, head 2f72e1b) through the Correctness, Contracts & System-Level Consequences lens. 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/docs/core-design.md, issue #446, and the in-repo consumers of error.code.

Verdict: no Blocker. The main path is correct, small, and genuinely tested. Three findings:

A (Major) — code now encodes internal validation layering, and the change exceeds #446's scope. preparation_error (http.rs:124-132) sends every Error::Admission(_) through Protocol::failure, and AdmissionError::Invalid → "invalid_request" (server.rs:751). #446 asks only for the four codes context_length_exceeded/unsupported_feature/invalid_grammar/invalid_image. Result: two adjacent client-input 400s get different codes — "max_tokens": 0 → invalid_request_error (request.rs:615-616, a &str error = ExecutionError::State, pinned by the PR's own test phase_tests.rs:8737-8759) while "stop": [5 strings] → invalid_request (stops.rs:63-72, pinned at phase_tests.rs:8719-8736). Sampling, top_k/seed, token stops and >uint32 output limits are affected the same way. Fix: keep AdmissionError::Invalid on the untyped arm, or type the rest too.

B (Minor) — other => PreparationError::Http(StatusCode::BAD_REQUEST, …) (http.rs:130) hardcodes 400 where status() (server.rs:733-741) says 500 for Error::Execution/Frontend(Asset|Template|Tokenizer|Input); tokenizer failures via frontend.encode (request.rs:178) are blamed on the client. Pre-existing, but makes the description's "status from status(&error)" untrue of this arm.

C (Minor) — docs/api.md:248-259 still documents all these 400s as invalid_request_error; the typed strings appear nowhere under docs/. One sentence needed (#638 precedent); core-design.md:1115-1119 already promised typed codes.

Verified sound: no HTTP status can change (Capacity/Unavailable never arise in preparation); no concurrency, lock, memory, buffering or latency change; x-request-id and failure-log contract preserved; Anthropic envelope untouched; untyped bodies byte-identical. Description's "hints preserved" is a no-op; test totals unverifiable (no CI on head, GPU/Python suites unrun).

Full report · Notes

Final review

Recommendation: Changes Requested

PR #689 cleanly fixes the core #446 defect by carrying typed Error values across http::generate's spawn_blocking boundary and rendering them through the shared Protocol::failure + rejection_details path without altering x-request-id, failure logging, HTTP status codes, or concurrency/permit lifetimes. Before merging, resolve the wire-level error.code split introduced by routing AdmissionError::Invalid to "invalid_request" while adjacent validation checks on the exact same fields still emit "invalid_request_error", and trim the unreachable FrontendError::ImageDecode branch and duplicated HttpState struct literal in the new test.

Merge Risk

Level: Low

Walkthrough

Pre-merge Checks

Blockers

None.

Should Fix

  1. Unintended error.code split across ordinary 400 validation errors (helios/src/server/http.rs:124-132, helios/src/server.rs:751, helios/src/server/runtime/phase_tests.rs:8719-8759):
    • Routing all Error::Admission(_) variants through PreparationError::Failure causes AdmissionError::Invalid to emit "code": "invalid_request" (helios/src/server.rs:751), while sibling validation errors raised via Error::from(&str) (mapped to ExecutionError::State at helios/src/error.rs:174-183) hit the catch-all arm and emit "code": "invalid_request_error".
    • This splits adjacent checks on the exact same request fields across two different wire error.code values based solely on internal Rust error construction:
      • max_tokens > u32::MAX (helios/src/server/request.rs:609-614, AdmissionError::Invalid) emits "invalid_request", while max_tokens == 0 or max_tokens > i32::MAX (helios/src/server/request.rs:615-617, &str) emits "invalid_request_error".
      • Bad temperature/top_p/seed (helios/src/server/request.rs:709-727, helios/src/model.rs:229-256) emit "invalid_request", while non-integer top_k (helios/src/server/request.rs:684, &str) emits "invalid_request_error".
      • stop combined with structured output (helios/src/server/stops.rs:79-84) emits "invalid_request", while stop_token_ids combined with structured output (helios/src/server/request.rs:340-342) emits "invalid_request_error".
    • Issue #446 and its maintainer confirmation specifically target the four typed preparation codes (context_length_exceeded, unsupported_feature, invalid_grammar, invalid_image), not splitting general 400 validation errors, and phase_tests.rs:8719-8759 currently pins both sides of that accidental split.
    • Fix (choose one):
      • Preferred (minimal, matches #446 scope): Keep Error::Admission(AdmissionError::Invalid(_)) on the PreparationError::Http(StatusCode::BAD_REQUEST, ...) arm in preparation_error (helios/src/server/http.rs:124-132), so general invalid-request 400s stay uniformly "invalid_request_error" and only specific typed admission errors (Context, Feature, Grammar, Image, plus Capacity/Unavailable) emit distinct codes; update http.rs:762-765 and phase_tests.rs:8719-8736 accordingly.
      • Alternative (if "invalid_request" is desired for preparation 400s): Convert the remaining prepare_validated_inference client-input &str errors (at minimum the sibling output_limit, top_k, and structured-output stop checks) to AdmissionError::Invalid so one error class does not emit two codes.

Subtract / Simplify

  1. Delete the unreachable FrontendError::ImageDecode arm in preparation_error (helios/src/server/http.rs:127-129, 758-761):
    • FrontendError::ImageDecode is only constructed inside ImageProcessor decoding (helios/src/frontend/images/mod.rs and orientation.rs (not opened)). On http::generate's preparation path, the only image-decoding caller is describe_images (helios/src/server/request.rs:1120-1233), which already wraps check_batch, decode_encoded, describe_image, geometry, and check_budget with .map_err(|error| error.admission_context(AdmissionError::Image)) (request.rs:1141, 1194, 1196, 1208, 1230), and crate::model::prepare_image_inputs (helios/src/model/prompt.rs:37-141) never decodes image bytes.
    • Remove the dead Error::Frontend(crate::FrontendError::ImageDecode(_)) match arm at helios/src/server/http.rs:127-129 and its synthetic unit-test row at helios/src/server/http.rs:758-761.
  2. Replace the 21-field hand-rebuilt HttpState literal in phase_tests.rs:8452-8480 with Arc::get_mut on http_state_for:
    • make_state builds base = http_state_for(fixture, sender, None, &[]) and then copies all 21 fields of HttpState solely to override images, max_body_bytes, and context_hint, duplicating http_state_for (phase_tests.rs:4273-4295) and inviting merge conflicts with any PR adding an HttpState field.
    • Follow the existing pattern at helios/src/server/runtime/phase_tests.rs:5086-5087: mutate let mut state = http_state_for(fixture, sender, None, &[]); via let s = Arc::get_mut(&mut state).unwrap(); to set only max_body_bytes, context_hint, and images.

Nits

Dropped on verification

Full report

Classify triage

Selected: triage:review

Threshold: 65%

Triage

Apply labels

No label changes Decision to Test: no (99%): Testing will not add significant value as the code stands today. The code is either not yet ready to merge, or adequate testing has already been done to validate the contents of the code, or the available hardware is not suitable to test with. decide malicious: all_clear (100%): No malicious content found

explore

Author: jcartu (Joshua Cartu, GitHub association CONTRIBUTOR; not one of the charter's named priority contributors); Discord: jcartu Motivation: Request-preparation failures (bad grammar, oversized prompt, unsupported feature, bad image) were rendered through a generic error path, so clients always saw code: invalid_request_error even when the engine knew exactly what kind of failure it was. This PR makes those failures render through the same typed error path post-admission failures already use, fixing open bug #446. Scale: +440 / −26 in 3 files (head 4695d846: http.rs +107/−23, phase_tests.rs +327/−0, docs/api.md +6/−3) Proposal:

Full report · Notes

Classify intake

Selected: triage:review, bug, area:api

Threshold: 65%

Triage

Priority

Type

Area

Model

Apply Labels (Intake)

No label changes

Subtraction and simplicity

Reviewed PR #689 at head 4695d846 (+440/−26, 3 files) through the Subtraction, Simplicity & Conventions lens. The diff is largely lean and I would not block on it: the failure_response/rejection split is a genuine extraction, PreparationError is load-bearing for the two dispatch modes, the spawn_blocking closure keeps straight ? flow with only five map_err(preparation_error) sites, and no flags, config, fallbacks or dead code are added (the previously flagged FrontendError::ImageDecode arm is gone).

Findings ranked:

  1. Should-simplify — preparation_error (helios/src/server/http.rs:124-132) has two arms with byte-identical bodies; collapse to two arms keyed on the typed variants.
  2. Trim — the new unit test (http.rs:739-807) re-asserts the four codes the wire test covers end-to-end, includes Capacity/Unavailable cases preparation cannot reach (:762-771), and its untyped half (:785-806) only re-tests Protocol::error's existing mapping.
  3. Trim — send_raw (helios/src/server/runtime/phase_tests.rs:8467-8501) re-implements the build/generate/read helper that already exists as http_generation_request_observed (phase_tests.rs:4461-4490).
  4. Docs — the sentence added at docs/api.md:257-261 duplicates and contradicts the "over-context requests return HTTP 400 (invalid_request_error)" clause at :250-251; fold into one clause.
  5. Nit — assert_envelope's expected_type param (phase_tests.rs:8503) is "invalid_request_error" at all 17 call sites.

Caution: server.rs:751's "invalid_request" is still reachable via protocol/decisions/mod.rs:282-292; it is not dead code and must not be proposed for deletion. No AGENTS.md structural violation found (:188-193, :194-199).

Open questions: whether the trim of the unit test is wanted given no CI exists to back the counts; why the reported helios totals did not move after a commit that adds assertions.

Full report · Notes

Correctness and contracts

PR #689 mechanically fixes #446 correctly, but its new documentation sentence contradicts the paragraph it was added to.

Findings:

Verified sound: the mapping matches status/error_code exactly, only error.code changes on the wire, the x-request-id/logging contract boundary holds (phase_tests.rs:8492-8495), Messages envelope scoping is correct, and no lock/allocation/lifetime/ordering change touches the hot path or the metric span.

Open: whether the docs contradiction is fixed in-PR; why the helios count did not move; whether the internal-error 400 is acceptable.

Full report · Notes

Re-review

Recommendation: Ready To Merge

Commit 4695d84 resolves all four items from the prior review cleanly and introduces no regressions: AdmissionError::Invalid now stays on invalid_request_error alongside untyped HTTP 400 checks, the dead FrontendError::ImageDecode branch is gone, make_state reuses http_state_for, and docs/api.md documents the four typed HTTP 400 error.code values on OpenAI-shaped endpoints. The implementation fixes #446 at the right layer with exact parity on HTTP status codes, x-request-id/logging boundaries, Anthropic envelopes, and spawn_blocking permit lifetimes; confirm green CI on 4695d84 before merging.

Merge Risk

Level: Low

Walkthrough

Pre-merge Checks

Blockers

None.

Should Fix

None.

Subtract / Simplify

  1. Collapse duplicate PreparationError::Http arms (helios/src/server/http.rs:124-132, optional): Arms 1 and 3 of preparation_error construct the identical PreparationError::Http(StatusCode::BAD_REQUEST, ...) expression. They can be combined into two arms so the "all AdmissionError except Invalid" rule appears once:
    fn preparation_error(error: Error) -> PreparationError {
        match error {
            Error::Admission(kind) if !matches!(kind, AdmissionError::Invalid(_)) => {
                PreparationError::Failure(Error::Admission(kind))
            }
            other => PreparationError::Http(StatusCode::BAD_REQUEST, other.to_string()),
        }
    }
    

Nits

None.

Dropped on verification

Full report Decision to Test: no (56%): Testing will not add significant value as the code stands today. The code is either not yet ready to merge, or adequate testing has already been done to validate the contents of the code, or the available hardware is not suitable to test with.

Classify triage

Selected: triage:review

Threshold: 65%

Triage

Apply labels

No label changes