fix(translation): fail-closed on malformed Chat Completions success - #869
Open
leseb wants to merge 1 commit into
Open
fix(translation): fail-closed on malformed Chat Completions success#869leseb wants to merge 1 commit into
leseb wants to merge 1 commit into
Conversation
The Responses translator accepted any JSON object as a successful Chat
Completions response. A backend returning HTTP 200 with a malformed body
such as `{}` was translated into a fake successful Responses object
(`status: "completed"`, `error: null`, `output: []`), hiding the upstream
failure from the client.
Validate the minimum successful shape before translating: a non-empty
`choices` array, a first choice object, a supported `finish_reason`
(stop/length/tool_calls/content_filter), an assistant `message`, and at
least one translatable output (content, refusal, or a well-formed
function tool call). A `tool_calls` finish reason now requires function
tool calls. Malformed responses fail closed as HTTP 500 instead of
surfacing a counterfeit success.
Add unit coverage for each rejected shape, a filter-boundary test that
aborts after headers are sent, and an end-to-end regression asserting a
finite HTTP 200 `{}` becomes a 500.
Closes praxis-proxy#804
Signed-off-by: Sébastien Han <seb@redhat.com>
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.
Summary
The Responses translator accepted any HTTP 200 body as a successful Chat Completions response, so a malformed payload like
{}became a counterfeitcompletedResponses object (status: "completed",error: null,output: []) that silently hid the upstream failure. This change validates the minimum successful shape before translating — a non-emptychoicesarray, a first choice object, a supportedfinish_reason(stop/length/tool_calls/content_filter), an assistantmessage, and at least one translatable output (content, refusal, or a well-formed function call, withtool_callsfinish reasons requiring function calls) — so malformed responses now fail closed as HTTP 500 instead of a fake success. It is the smallest complete change: the check lives in the shared translator that every finite HTTP 200 path already calls, and well-formed responses are unaffected.Related issue
Closes #804
Validation
cargo test -p praxis-ai-apis -- translation responses_to_chat_completions(138 passed; 5 new/updated shape-rejection tests confirmed by exact name)cargo test -p praxis-tests-integration -- responses_to_chat_completions(7 passed, incl. newresponses_to_chat_completions_rejects_malformed_finite_successasserting a finite HTTP 200{}→ 500)make lint(clippy-D warnings, fmt, deps, docs, example, and README-sync checks all green)make buildChecklist
responses_to_chat_completionsexample config.)make lintREADME-sync checks — no doc changes needed.)Signed-off-bytrailer.Breaking changes
Narrow behavioral change on an error path: a backend returning HTTP 200 with a body that does not conform to the Chat Completions success schema previously produced a
completedResponses object with empty output; it now fails closed with HTTP 500. Well-formed responses are unaffected and no migration is required.