Repository navigation
fix(server): accept text response_format on the disaggregated router - #2869
Conversation
The router's chat and completion guards rejected any request carrying
`response_format`, including `{"type": "text"}`, which asks for no
constraint and runs unconstrained on single node. Gate both guards on
`response_format_requests_constraint`, the predicate
`validate_chat_tool_inputs` already uses, so only values that request
a constraint are rejected. Schema requests keep the same 400 and
message.
New tests drive both router handlers with `{"type": "text"}` and show
the request gets past the guard. docs/CONTINUOUS_BATCHING.md states
the new rule.
|
|
The router guards now accept `{"type": "text"}`, but only a `json_schema` body and the text acceptance were tested, so a change to the shared predicate could let a structured-output request through as a 200 with unconstrained output.
Add route-level tests for both fronts covering every value that must be refused (schema, `json_object`, unknown types, case variants, non-objects, and objects with a missing or non-string `type`), the accepted `null` and text forms, a forced `tool_choice` on each side of the boundary, and the invariant that a value the router accepts never compiles a constraint on single node.
Correct the predicate doc, which claimed the structured-output builder reports every other shape. It reads a missing or non-string `type` as text, and the router deliberately fails closed on those because they may be a schema request with a typo. Update the `route_completion` parity note to match the guard.
|
Hardening review, pushed as No defects found. Added 4 boundary tests and corrected 2 comments. One difference is kept on purpose: Security and performance: no new input surface. Validation on GB10: 80 focused tests pass, and router, prefill and decode ran end to end on Merge gate: first-time-contributor workflow runs wait for approval and were not started, so by maintainer decision the gate ran on GB10 against one tree integrating #2888, #2872, #2869, #2871 and #2870 on |
Summary
On the disaggregated router,
/v1/chat/completionsand/v1/completionsreject any request that carriesresponse_format, including{"type": "text"}, which asks for no constraint. Single node serves that value unconstrained (extract_json_schema_from_response_formatreturnsOk(None)), so the same request returns 200 on a single node and 400 behind the router.Both guards test
response_format.is_some(), which is wider than their own comment ("a request that explicitly asked for structured output"). This PR gates them onresponse_format_requests_constraint, the predicatevalidate_chat_tool_inputsalready uses for the same question (#1581), and makes itpub(crate). Schema requests are still rejected with the same message, so the #979 criterion that ajson_schemarequest no longer returns 200 with unconstrained output still holds.Related issues
Refs #981
Type of change
fix— bug fixTest plan
cargo fmt --all -- --checkcargo clippy -p mlxcel --lib --tests --profile test-fast --features metal,accelerate -- -D warnings: clean. The full--workspace --all-targetsrun was not done.cargo test --profile test-fast --features metal,accelerate --lib -- --test-threads=1 server::router_front::tests:: server::routes::chat::tests::tools_(macOS 26.5.1, Apple M5 Pro): 51 passed.cargo test --workspace --profile test-fast --features metal,accelerate --no-fail-fast -- --test-threads=1: not run.cargo deny check: not run; no dependency change.The new chat test renders with a template that raises once it is reached, the same signal
router_chat_forwards_forced_tool_choice_instead_of_rejecting_ituses. The completion test relies on the thinking-budget check that runs right after the guard, and asserts nothing was handed off (next_idunchanged).response_formaton the routernull{"type":"text"}{"type":"text"}with a forcedtool_choice(chat){"type":"json_schema", ...}{"type":"json_object"}, non-object{},{"type": null}Notes for reviewers
{}and{"type": null}are still rejected, while single node reads a missingtypeas text. This keeps the shared predicate's existing meaning (native/completionalso rejects{}). Matchingextract_json_schema_from_response_formatexactly would mean gating on!matches!(extract_json_schema_from_response_format(rf), Ok(None))instead, at the cost of a second predicate for the same question.{"type": "text"}before fix(server): enforce disaggregated router chat guards (#979) #981. In the same function, a forcedtool_choiceis kept accepted because rejecting it "would refuse a request the router accepted before"; the same reasoning applies here.PrefillRequestFrame(fix: Enforce response_format, MAX_TOOLS, and tool_choice guards on the disaggregated router chat front #979 option 2) is out of scope.Checklist
docs/:docs/CONTINUOUS_BATCHING.md, the router scope and limitations list.response_format_requests_constraintis a server helper, and its doc now names the router caller..envfiles committed.