Repository navigation
helios/server: preserve typed error codes on HTTP request preparation failures - #689
Conversation
|
A case file has been opened for 689. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedPR #689 cleanly fixes the core #446 defect by carrying typed
Walkthrough
Merge Risk: Low · up to
|
… failures
In the Helios HTTP generation handler (`helios/src/server/http.rs`), request
preparation runs on a blocking worker before scheduler admission. Previously,
the preparation closure returned `Result<_, (StatusCode, String)>`, flattening
typed `Error::Admission` failures from protocol decoding (`protocol::decode`),
custom tool grammar compilation (`GrammarCompiler::compile_text`), strict tool
schema validation (`request::compile_strict_validators`), and inference
preparation (`request::prepare_validated_inference`, via `rejection_details`)
into plain `(StatusCode, String)` pairs. The handler then rendered those pairs
through `http::error` and `Protocol::error`, which always sets `error.code` to
the status-derived category (`"invalid_request_error"` for HTTP 400) rather than
the typed code returned by `error_code(&error)`. Preserving typed
`Error::Admission` variants across the `spawn_blocking` boundary and rendering
them through the same `Protocol::failure` plus `rejection_details` path used by
`rejection` aligns preparation rejections with post-admission rejections, while
keeping `AdmissionError::Invalid` on the `http::error` path so general
invalid-request 400s uniformly emit `"invalid_request_error"`.
Before this change, `http::generate` converted all errors inside its
`spawn_blocking` task into `(StatusCode, String)` and returned
`http::error(protocol, status, message)`. In `prepare_validated_inference`,
non-`Admission` errors were previously wrapped into `AdmissionError::Invalid`
solely so `rejection_details` would compute HTTP 400 (hints apply only to
`Context` and `Capacity`), and then flattened by `http::error` to
`"invalid_request_error"`. With this change:
- Added `PreparationError` (`Http(StatusCode, String)` and `Failure(Error)`) and
`preparation_error(Error) -> PreparationError` in `helios/src/server/http.rs`.
`Error::Admission(AdmissionError::Invalid(_))` and non-`Admission` errors map
to `PreparationError::Http(StatusCode::BAD_REQUEST, message)`, keeping general
400 validation errors uniformly on `"invalid_request_error"`. All other
`Error::Admission(_)` variants (`Context`, `Feature`, `Grammar`, `Image`,
`Capacity`, `Unavailable`) remain intact as `PreparationError::Failure`.
- Extracted `failure_response(&HttpState, Protocol, Error) -> Response` from
`rejection` so both typed preparation failures and post-submission rejections
render via `Protocol::failure(&failure)` and apply `rejection_details`
(`status(&failure)` and `context_hint` / `capacity_hint` message suffixes),
while only post-submission `rejection` attaches `x-request-id` and writes
`failure_log`.
- Updated `http::generate` to route `protocol::decode`,
`GrammarCompiler::compile_text`, `Request::generation_count`,
`request::compile_strict_validators`, and
`request::prepare_validated_inference` through `preparation_error`, dispatching
`PreparationError::Failure` to `failure_response` and `PreparationError::Http`
to `http::error`.
- Documented the typed HTTP 400 `error.code` values (`context_length_exceeded`,
`unsupported_feature`, `invalid_grammar`, `invalid_image`) for Chat
Completions, Completions, and Responses in `docs/api.md`.
- Added unit test
`preparation_error_preserves_typed_admission_errors_and_keeps_untyped_bad_requests`
in `helios/src/server/http.rs` and HTTP-wire test
`http_preparation_failures_preserve_typed_error_codes_and_protocol_envelopes`
in `helios/src/server/runtime/phase_tests.rs`.
Resulting behavior:
Typed request-preparation failures on Chat Completions (`/v1/chat/completions`),
Completions (`/v1/completions`), and Responses (`/v1/responses`) return their
typed `error.code` (`context_length_exceeded`, `unsupported_feature`,
`invalid_grammar`, `invalid_image`), `error.type` (`invalid_request_error`),
explicit `error.param: null`, and `status(&error)` with `context_hint` /
`capacity_hint` preserved in `error.message` for both `stream: false` and
`stream: true` requests. Anthropic Messages (`/v1/messages` and
`/v1/messages/count_tokens`) keeps its `{"type": "error", "error": {"type",
"message"}}` envelope without `code` or `param` fields and preserves
`context_hint`. General HTTP validation errors (invalid JSON, missing required
fields, `AdmissionError::Invalid` such as more than four stop sequences, untyped
preparation checks such as `max_tokens: 0`, unsupported `Content-Encoding`, and
oversized bodies) retain their HTTP status and `invalid_request_error` or
`request_too_large` codes.
Evidence and limitations:
- `cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server`
(with prepared template fixtures supplied via `FLARE_TEST_TEMPLATE_DIR`): 1,880
passed, 0 failed, 84 ignored (1,818 passed, 47 ignored in `flare-helios
--lib`; 62 passed, 37 ignored across integration test targets; ignored tests
require GPU hardware or local checkpoint snapshots). The unit test verifies
`preparation_error` across `Context`, `Feature`, `Grammar`, `Image`,
`Capacity`, `Unavailable`, `Invalid`, and untyped errors; the HTTP-wire test
exercises `http::generate` end-to-end across all four protocols and
`/v1/messages/count_tokens` for `context_length_exceeded`,
`unsupported_feature`, `invalid_grammar` (output schema, strict tool schema,
and custom tool grammar paths), `invalid_image`, general 400 validation
(`stop` count > 4 and `max_tokens: 0`), and HTTP 400/413/415 rejections while
asserting explicit `param: null` presence, absent `x-request-id`, and zero
model-queue admissions.
- `cargo test --locked --release --manifest-path flare/Cargo.toml`: 254 passed, 0
failed, 4 ignored (246 passed, 4 ignored in `flare --lib`; 7 passed in
`packed_canonical_download`; 1 passed in `reference_workflows`).
- `cargo test --locked --release --manifest-path flare-cli/Cargo.toml`: 245
passed, 0 failed, 3 ignored (219 passed, 3 ignored in `flare-cli --bin`; 9
passed in `cache_commands`; 6 passed in `cli`; 4 passed in `inspect`; 7 passed
in `unverified_payload`).
- Live GPU serving and the Python server integration tests
(`tests/server/test_protocols.py`) were not run because no GPU serving
instance was executed in this environment.
Signed-off-by: Joshua Cartu <jcartu@users.noreply.github.com>
Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
2f72e1b to
4695d84
Compare
|
@flare-autobot Addressed all four review items in commit
Re-verified release CPU test suites on
|
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Ready To MergeCommit
Walkthrough
Merge Risk: Low · up to
|
Fixes #446
Why
In the Helios HTTP generation handler (
helios/src/server/http.rs), request preparation runs in atokio::task::spawn_blockingclosure before scheduler admission. Previously, that closure returnedResult<_, (StatusCode, String)>, converting typedError::Admissionfailures from protocol decoding (protocol::decode), custom tool grammar compilation (GrammarCompiler::compile_text), strict tool schema validation (request::compile_strict_validators), and inference preparation (request::prepare_validated_inference, viarejection_details) into(StatusCode, String)pairs. The handler then rendered those pairs throughhttp::error->Protocol::error, which setserror.codefrom the HTTP status category ("invalid_request_error"for HTTP 400) instead of callingProtocol::failureto emiterror_code(&error). As a result, clients received"code": "invalid_request_error"on typed preparation rejections (context_length_exceeded,unsupported_feature,invalid_grammar,invalid_image), diverging from post-admission and streaming failures that already render throughProtocol::failure.Preserving typed
Error::Admissionvariants across thespawn_blockingboundary and rendering them through the sameProtocol::failure+rejection_detailspath used byrejectionaligns typed preparation errors with post-admission errors, while keepingAdmissionError::Invalidand untyped validation failures (decode_body, missing fields, general parameter checks, oversized generation groups, and ingress rate limits) uniformly onProtocol::error.What changed
Before this change,
http::generateconverted every preparation failure insidespawn_blockinginto(StatusCode, String)and returnedhttp::error(protocol, status, message). Inprepare_validated_inference, non-Admissionerrors were previously wrapped intoAdmissionError::Invalidsolely sorejection_detailswould compute HTTP 400 (hints apply only toContextandCapacity), and then flattened byhttp::errorto"invalid_request_error".With this change:
PreparationError(Http(StatusCode, String)andFailure(Error)) andpreparation_error(Error) -> PreparationErrorinhelios/src/server/http.rs:Error::Admission(AdmissionError::Invalid(_))and non-Admissionerrors toPreparationError::Http(StatusCode::BAD_REQUEST, message), keeping general invalid-request 400s uniformly on"invalid_request_error".Error::Admission(_)variants (Context,Feature,Grammar,Image,Capacity,Unavailable) unchanged asPreparationError::Failure.failure_response(&HttpState, Protocol, Error) -> Responsefromrejectioninhelios/src/server/http.rsso both typed preparation failures and post-submission rejections build their JSON body viaProtocol::failure(&failure)and applyrejection_details(status(&failure)pluscontext_hint/capacity_hintmessage suffixes). Only post-submissionrejectionattachesx-request-idand writesfailure_log, preserving thex-request-idand logging contract indocs/api.mdanddocs/core-design.md.http::generateto map errors fromprotocol::decode,GrammarCompiler::compile_text,Request::generation_count,request::compile_strict_validators, andrequest::prepare_validated_inferencethroughpreparation_error, dispatchingPreparationError::Failuretofailure_responseandPreparationError::Httptohttp::error.error.codevalues (context_length_exceeded,unsupported_feature,invalid_grammar,invalid_image) for Chat Completions, Completions, and Responses indocs/api.md.preparation_error_preserves_typed_admission_errors_and_keeps_untyped_bad_requestsinhelios/src/server/http.rsand HTTP-wire testhttp_preparation_failures_preserve_typed_error_codes_and_protocol_envelopesinhelios/src/server/runtime/phase_tests.rs.Claimed result
/v1/chat/completions), Completions (/v1/completions), and Responses (/v1/responses) return their typederror.code(context_length_exceeded,unsupported_feature,invalid_grammar,invalid_image),error.type(invalid_request_error), expliciterror.param: null, and HTTP status fromstatus(&error), withcontext_hint/capacity_hintpreserved inerror.messageand nox-request-idheader, for both buffered (stream: false) and streaming (stream: true) requests./v1/messagesand/v1/messages/count_tokens) keeps its{"type": "error", "error": {"type": ..., "message": ...}}envelope withoutcodeorparamfields while preservingcontext_hint.AdmissionError::Invalidsuch as more than four stop sequences, untyped preparation validation errors such asmax_tokens: 0, unsupportedContent-Encoding, and oversized bodies) retain their HTTP status codes (400, 413, 415) andinvalid_request_error/request_too_largeerror codes.Evidence and limitations
cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server(with prepared template fixtures supplied viaFLARE_TEST_TEMPLATE_DIR): 1,880 passed, 0 failed, 84 ignored (flare-helios --lib: 1,818 passed, 47 ignored; integration test binaries: 62 passed, 37 ignored; ignored tests require GPU hardware or local model checkpoint snapshots). The added tests verifypreparation_erroracrossContext,Feature,Grammar,Image,Capacity,Unavailable,Invalid, and untyped errors, and drivehttp::generateend-to-end across/v1/chat/completions,/v1/completions,/v1/responses,/v1/messages, and/v1/messages/count_tokensforcontext_length_exceeded(buffered andstream: true, withcontext_hint),unsupported_feature(bothprotocol::decodeand text-only image rejection inprepare_validated_inference),invalid_grammar(output schema, strict tool schema, and custom tool grammar paths),invalid_image(invalid base64 and corrupt PNG on a vision-enabledHttpState), general 400 validation (stopcount > 4 andmax_tokens: 0both emittinginvalid_request_error), and HTTP 400/413/415 rejections while asserting explicitparam: nullpresence, absentx-request-id, and zero model-queue admissions.cargo test --locked --release --manifest-path flare/Cargo.toml: 254 passed, 0 failed, 4 ignored (flare --lib: 246 passed, 4 ignored;packed_canonical_download: 7 passed;reference_workflows: 1 passed).cargo test --locked --release --manifest-path flare-cli/Cargo.toml: 245 passed, 0 failed, 3 ignored (flare-cli --bin: 219 passed, 3 ignored;cache_commands: 9 passed;cli: 6 passed;inspect: 4 passed;unverified_payload: 7 passed).tests/server/test_protocols.py) were not run because no GPU serving process was started in this environment.Discord: jcartu