Repository navigation
Echo Responses tools and text.format and decode tool output is_error - #638
Open
flare-autobot wants to merge 1 commit into
Open
flare-autobot wants to merge 1 commit into
flare-autobot wants to merge 1 commit into
Conversation
Collaborator
Author
|
A case file has been opened for 638. Future reviews will auto-run 90 minutes after code updates are pushed.
|
Collaborator
Author
Autobot ReviewFull Review · Value Proposition · Case File Recommendation: Changes RequestedPR #638 cleanly fixes all three #450 defects in Helios's shared HTTP protocol layer with strong CPU test coverage, but should not merge until the unexplained red CI on
Walkthrough
Merge Risk: Low · up to
|
Clients using Helios's OpenAI Responses endpoint (`POST /v1/responses`) inspect
the returned response object's `tools` and `text.format` fields to confirm
active declarations and structured-output constraints across buffered JSON and
SSE lifecycle events, and pass `is_error: true` on `function_call_output` and
`custom_tool_call_output` items to signal failed tool executions to the model.
Previously, Helios hardcoded empty `tools` and default `text.format` on every
Responses payload, dropped `is_error` on Responses tool outputs, and returned a
WebSocket-only message on `GET /v1/responses`. Carrying normalized namespace
metadata on `inference::Tool`, validating and retaining the Responses
`text.format` object during protocol decoding, and feeding Responses tool-output
`is_error` into the shared `Part::ToolResult` representation keeps all protocol
handling in Helios's shared HTTP layer without touching model contracts,
scheduling, or GPU execution paths.
Before this change:
- `Encoder::response()` in `helios/src/server/protocol/encode.rs` hardcoded
`"tools": []` and `"text": {"format": {"type": "text"}}` for
`Protocol::Responses`.
- `decode()` in `helios/src/server/protocol/decode.rs` concatenated each
Responses tool namespace's `description` directly into `Tool.description`
(preventing lossless namespace echoing and adding a leading newline when a
namespace description was empty) and accepted duplicate namespace names in
one request.
- `responses_messages()` in `helios/src/server/protocol/decode.rs` hardcoded
`is_error: false` on `function_call_output` and `custom_tool_call_output`
items.
- `http::no_websocket()` in `helios/src/server/http.rs` returned HTTP 400 with
`"WebSockets are not supported; use POST /v1/responses with HTTP/SSE"`, and
`docs/api.md` did not state the `GET /v1/responses` status or the Responses
echo and `is_error` behavior.
After this change:
- `inference::Tool` (`helios/src/server/inference.rs`) stores an optional
normalized `namespace_description` (`None` when absent or empty). `decode()`
rejects duplicate Responses namespace names with HTTP 400, and
`request::template_inputs()` (`helios/src/server/request.rs`) prepends
nonempty namespace descriptions before custom-tool grammar instructions when
lowering tools to prompt templates (stopping the spurious leading `"\n"` for
explicitly empty `"description": ""` namespace wrappers).
- `decode()` parses Responses `text` and `text.format` in a single pass through
`responses_text_format()` returning `Result<Option<(Option<Constraint>, Value)>>`,
rejecting non-object `text` or `text.format`, unsupported format types,
invalid `json_schema` `schema` values (requiring a JSON object or boolean,
matching `helios/src/grammar.rs`), and non-string or non-boolean optional
`name`, `description`, and `strict` fields with HTTP 400. Mutual exclusion
with top-level `grammar` is checked before keeping `Decoded.text_format` as
`Option<Value>` (`None` when absent, `null`, or non-Responses, avoiding dead
allocations on Chat, Completions, and Messages requests). `http::generate()`
(`helios/src/server/http.rs`) passes `decoded.text_format` into
`Encoder::set_text_format()` before `encoder.start()`.
- `Encoder::new()` precomputes `responses_tools: Value` once via
`build_responses_tools(&tools)` when `protocol == Protocol::Responses`
(echoing standalone function and custom tools with unqualified `name`,
nullable `parameters` when undeclared, `strict`, and text/Lark/regex custom
formats, and grouping namespaced tools under their namespace wrapper), and
`Encoder::start()` reuses the built response object across `response.created`
and `response.in_progress`. `Encoder::response()` serializes `responses_tools`
and `text_format` (materializing `{"type":"text"}` only when `None`) across
buffered JSON responses and all Responses SSE lifecycle events
(`response.created`, `response.in_progress`, `response.completed`,
`response.incomplete`, and `response.failed`).
- `responses_messages()` decodes optional boolean `is_error` (defaulting to
`false` when omitted or `null` and rejecting non-booleans with HTTP 400) on
`function_call_output` and `custom_tool_call_output` items, reusing the
shared `Part::ToolResult` lowering used by Chat Completions and Anthropic
Messages across `Jinja`, `DeepseekV4`, `DeepseekV41`, and `TmlV0` prompt
encoders.
- `http::no_websocket()` returns HTTP 400 (`invalid_request_error`) with
`"GET /v1/responses and WebSocket transport are not supported; use POST /v1/responses with HTTP JSON or SSE"`,
and `docs/api.md` specifies these behaviors including duplicate namespace
rejection and empty namespace wrapper omission from `response.tools`.
Result: OpenAI Responses buffered responses and SSE lifecycle events echo
declared standalone, custom, and namespaced `tools` (precomputed once per
request) along with validated `text.format` objects; invalid `text.format` and
duplicate namespace requests fail with HTTP 400 before model queue admission;
Responses failed tool outputs lower identically to Chat Completions and
Anthropic Messages across all four prompt encoders; and `GET /v1/responses`
returns HTTP 400 with explicit HTTP JSON and SSE guidance. No Protobuf schema,
model core format, cache layout, scheduler, or CUDA graph contract changes;
existing exported cores load unchanged.
Evidence (Linux aarch64 with external frontend templates prepared via
`tests/frontend/prepare_templates.py`):
- `cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --target-dir flare-cli/target`:
1,816 passed, 0 failed, 83 ignored (1,754 lib + 62 integration, including
6 new tests covering tool round-trip and namespace rules, `text.format`
validation and `grammar` exclusion, `is_error` decoding and four-encoder
parity via a shared `tml_frontend` helper, `http::generate` buffered/SSE
lifecycle echoing, and `GET /v1/responses` HTTP 400 guidance).
- `cargo test --locked --release --manifest-path flare/Cargo.toml --target-dir flare-cli/target`:
245 passed, 0 failed, 4 ignored.
- `cargo test --locked --release --manifest-path flare-cli/Cargo.toml`:
227 passed, 0 failed, 3 ignored.
Unrun checks and limitations: Live OpenAI Python SDK v2 tests
(`tests/server/test_protocols.py` against a running native Flare server with
an exported GPU model core), pre-existing `#[ignore]` GPU/checkpoint Rust
tests, scheduling simulator, and formal lifecycle/Kani checks were not run.
Signed-off-by: yatesdr <6937857+yatesdr@users.noreply.github.com>
Design-Signed-Off-By: yatesdr; design-review=2e5b
yatesdr
force-pushed
the
fix/issue-450-responses-echo-and-tool-error
branch
from
November 30, 2026 13:23
f414393 to
7ba8c66
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #450
Why
Clients calling Helios's OpenAI Responses endpoint (
POST /v1/responses) readtoolsandtext.formatfrom returnedresponseobjects across buffered JSON replies and Server-Sent Events (SSE) lifecycle frames to confirm active tool declarations and structured-output constraints, and sendis_error: trueonfunction_call_outputandcustom_tool_call_outputitems to signal failed tool executions to the model. Onorigin/main, three defects broke those contracts:responseobject hardcoded"tools": []and"text": {"format": {"type": "text"}}even when the request declared tools, set"tool_choice": "required"or a named tool, or requestedjson_objectorjson_schemaoutput, emitting self-contradictory metadata and misreporting active structured-output constraints.function_call_outputandcustom_tool_call_output) decoded with a hardcodedis_error: false, unlike Chat Completions (/v1/chat/completions) and Anthropic Messages (/v1/messages). Failed tool outputs replayed through/v1/responsestherefore lost error signaling across Helios's prompt encoders (Jinja,DeepseekV4,DeepseekV41, andTmlV0).GET /v1/responsesreturned HTTP 400 with"WebSockets are not supported; use POST /v1/responses with HTTP/SSE", assuming a WebSocket upgrade even on plain HTTP GET requests and omitting HTTP JSON, whiledocs/api.mddid not specify the route-level HTTP 400 behavior or the Responses echo andis_errorrules.Carrying normalized namespace descriptions on
inference::Tool, validating and retainingtext.formatduring protocol decoding, and decodingis_errorinto the sharedPart::ToolResultrepresentation resolves all three defects inside Helios's shared HTTP protocol layer without altering model contracts, prefix-cache mechanics, scheduling, or CUDA graph execution.What changed
Before:
Encoder::response()(helios/src/server/protocol/encode.rs) hardcoded"tools": []and"text": {"format": {"type": "text"}}forProtocol::Responses.decode()(helios/src/server/protocol/decode.rs) flattened Responses"type": "namespace"tool wrappers by concatenating each namespace'sdescriptiondirectly intoTool.description(preventing lossless namespace echoing and adding a leading newline for empty descriptions) and accepted duplicate namespace names in one request.options()(helios/src/server/protocol/decode.rs) loweredbody["text"]["format"]intoinference::Constraint, discardingjson_schemametadata (name,description,strict) and deferring schema type validation until grammar compilation.responses_messages()(helios/src/server/protocol/decode.rs) setis_error: falseunconditionally onfunction_call_outputandcustom_tool_call_outputitems.http::no_websocket()(helios/src/server/http.rs) returned HTTP 400 with"WebSockets are not supported; use POST /v1/responses with HTTP/SSE", anddocs/api.mddid not document that GET response or the Responses echo andis_errorcontracts.After:
helios/src/server/inference.rs,helios/src/server/protocol/decode.rs,helios/src/server/request.rs):inference::Toolstoresnamespace_description: Option<String>with absent and empty descriptions normalized toNone.decode()rejects duplicate Responses namespace names in one request with HTTP 400. Empty"tools": []namespace wrappers produce zero callableToolentries and emit no entry inresponse["tools"].request::template_inputs()prepends nonemptynamespace_descriptionbefore custom-tool grammar instructions when lowering tools to prompt templates.text.formatvalidation (helios/src/server/protocol/mod.rs,helios/src/server/protocol/decode.rs,helios/src/server/http.rs):Decodedcarriestext_format: Option<Value>(Nonewhen omitted,null, or on non-Responses protocols, avoiding dead allocations on Chat, Completions, and Messages requests). Insideoptions(), a single-passresponses_text_format()helper returningResult<Option<(Option<Constraint>, Value)>>handlesProtocol::Responses, rejecting non-objecttextortext.format, unsupported format types, missing or invalidjson_schema.schemavalues (requiring a JSON object or boolean, matchinghelios/src/grammar.rs), and invalid optionalname,description, orstrictfields with HTTP 400. Mutual exclusion against top-levelgrammaris checked directly on the returned option.http::generate()callsencoder.set_text_format(decoded.text_format)beforeencoder.start().helios/src/server/protocol/encode.rs):Encoder::new()precomputesresponses_tools: Valueonce viabuild_responses_tools(&tools)whenprotocol == Protocol::Responses(andValue::Nullotherwise), andEncoder::start()reuses the built response object acrossresponse.createdandresponse.in_progressinstead of rebuilding it twice.Encoder::response()serializesself.responses_toolsandself.text_format(materializing{"type": "text"}in one place whenNone) across buffered HTTP JSON responses and all Responses SSE lifecycle events (response.created,response.in_progress,response.completed,response.incomplete, andresponse.failed). A sharedresponses_tool_entry()serializer emits unqualifiedtool.namefor both standalone and namespaced tools, preserving functionparameters(ornullwhen undeclared),strict, optional nonemptydescription, custom text/Lark/regexformat, and first-appearance namespace grouping.is_error(helios/src/server/protocol/decode.rs):responses_messages()decodes optional booleanis_errorviaflag(&item, "is_error", false)?for bothfunction_call_outputandcustom_tool_call_output(absent ornull->false, non-boolean -> HTTP 400), feeding the sharedPart::ToolResultlowering used by Chat Completions and Anthropic Messages acrossJinja,DeepseekV4,DeepseekV41, andTmlV0.GET /v1/responsesand API specification (helios/src/server/http.rs,docs/api.md):http::no_websocket()retains HTTP 400 (invalid_request_error) with"GET /v1/responses and WebSocket transport are not supported; use POST /v1/responses with HTTP JSON or SSE".docs/api.mdspecifies theGET /v1/responsesHTTP 400 behavior, duplicate namespace rejection and empty namespace wrapper omission inresponse.tools, Responsestools/text.formatechoing, and Responses tool-outputis_errordecoding.Compatibility and resource lifetimes: No Protobuf schema, model core format, cache layout, scheduler, or CUDA graph contract changes; existing exported cores load and serve unchanged. Non-error tool results and nonempty namespaced tool prompts render identically to before; explicitly empty
"description": ""namespace wrappers intentionally stop prependingmain's spurious leading"\n"to tool descriptions, and failed Responses tool outputs now render distinct error tokens so prefix caching naturally separates error and non-error trajectories. Per-request host storage forresponses_tools,text_format, andnamespace_descriptionis bounded by the HTTP body limit (max_body_bytes, 32 MiB default), serialized only on response lifecycle envelopes rather than per token delta, and dropped upon request completion or disconnect.Claimed benefit and result
toolsand validatedtext.formatobjects consistently withtool_choice; malformedtext/text.format, non-booleanis_error, and duplicate namespace requests fail with HTTP 400 before model admission; Responsesfunction_call_outputandcustom_tool_call_outputitems withis_error: truelower identically to Chat Completions and Anthropic Messages acrossJinja,DeepseekV4,DeepseekV41, andTmlV0(including multimodal outputs); andGET /v1/responsesreturns HTTP 400 with explicit HTTP JSON and SSE guidance matchingdocs/api.md.response.toolsandresponse.textfrom a running Flare process serving an exported core.Supporting evidence and material limitations
Executed on Linux aarch64 after rebasing onto
origin/main(8da73911, which includes#624fixing the Python CPU CI premises) with external frontend templates prepared viatests/frontend/prepare_templates.py(FLARE_TEST_TEMPLATE_DIR):cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --target-dir flare-cli/target: 1,816 passed, 0 failed, 83 pre-existing#[ignore]skipped (1,754 passed, 46 ignored insrc/lib.rs; 62 passed, 37 ignored across 14 integration test binaries and doctests). Six added tests cover the changed contracts:responses_tools_echo_and_round_trip_standalone_custom_and_namespaces(helios/src/server/protocol/tests.rs):decode -> encode -> decodeequality ofinference::Requestandrequest::template_inputsacross standalone function/custom tools, undeclared parameters,strict, text/Lark/regex formats, omitted/empty/nonempty namespace descriptions, nested custom tools, empty namespace wrappers, and duplicate namespace rejection.responses_text_format_validation_echo_and_grammar_exclusion(helios/src/server/protocol/tests.rs): HTTP 400 rejection for non-objecttext/text.format, invalidjson_schema.schema, invalidname/description/strict, andgrammarcombined with explicittext.format; acceptance of boolean schemas andgrammarwith omitted ornulltext.format.responses_tool_outputs_decode_is_error_and_match_chat_and_messages(helios/src/server/protocol/tests.rs) andresponses_tool_result_is_error_matches_chat_and_messages_across_prompt_encoders(helios/src/server/protocol/decode.rs, sharing a deduplicatedtml_frontendtest helper):is_errordecoding (true,false,null, omitted, non-boolean rejection) onfunction_call_outputandcustom_tool_call_outputfor text and multimodal (input_text+input_image) payloads, confirming prompt-rendering parity with Chat Completions and Anthropic Messages acrossJinja,DeepseekV4,DeepseekV41, andTmlV0(<|content_tool_error|>).responses_http_generate_echoes_tools_and_text_format_across_lifecycle(helios/src/server/runtime/phase_tests.rs): productionhttp::generatebuffered and streamed/v1/responsesrequests verifying pre-admission HTTP 400 rejection and echoedtoolsandtext.formaton buffered responses andresponse.created,response.in_progress,response.completed,response.incomplete, andresponse.failedSSE events.get_responses_returns_bad_request_with_http_json_and_sse_guidance(helios/src/server/http.rs): HTTP 400invalid_request_errorenvelope and updated guidance text fromhttp::no_websocket.cargo test --locked --release --manifest-path flare/Cargo.toml --target-dir flare-cli/target: 245 passed, 0 failed, 4 pre-existing#[ignore]skipped.cargo test --locked --release --manifest-path flare-cli/Cargo.toml: 227 passed, 0 failed, 3 pre-existing#[ignore]skipped.Unrun checks and material limitations:
FLARE_API_TEST_URL=http://127.0.0.1:8000 .venv/bin/python -m pytest tests/server/test_protocols.py -q) were not run because no native Flare server serving an exported model core on NVIDIA GPU hardware was exercised.#[ignore]Rust tests (83 inhelios, 4 inflare, 3 inflare-cli, covering GPU, checkpoint, and live-hardware paths) were skipped by default in CPU release runs.scripts/scheduling_sim/) and formal verification checks (verification/helios-lifecycle/check.py,cargo kani) were not run because no scheduler, cache, lifecycle, completion-vector, or rank-coordination code changed.Discord: flare-autobot