fix: reject failed and incomplete Responses statuses in non-streaming path#3387
Open
ioleksiuk wants to merge 1 commit into
Open
fix: reject failed and incomplete Responses statuses in non-streaming path#3387ioleksiuk wants to merge 1 commit into
ioleksiuk wants to merge 1 commit into
Conversation
… path Mirror the streaming-side fix in openai#3107 (reject failed responses stream terminals) for the non-streaming `get_response` paths. Streaming responses are already guarded: when the streaming code sees a `response.failed` or `response.incomplete` terminal event, it raises `response_terminal_failure_error` via `src/agents/models/_response_terminal.py`. The non-streaming HTTP paths in `OpenAIResponsesModel.get_response` and `AnyLLMModel._get_response_via_responses` previously did not inspect `response.status` at all and would silently return a `ModelResponse` built from the partial/empty `response.output`. This violates parity with the streaming guard: identical underlying failures (provider backend error, content-filter incomplete, `max_output_tokens` hit) now crash one path and silently succeed on the other. Check `response.status in {"failed", "incomplete"}` right after the non-streaming fetch returns and raise the same `response_terminal_failure_error` used by the streaming path. Tests cover both terminal statuses for both the OpenAI Responses model and the any_llm responses path.
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
Mirror the streaming-side fix in #3107 (`fix: reject failed responses stream terminals`) for the non-streaming `get_response` paths.
Streaming responses are guarded today: when the streaming code sees a `response.failed` or `response.incomplete` terminal event, it raises `response_terminal_failure_error` (defined in `src/agents/models/_response_terminal.py`). The non-streaming HTTP paths in `OpenAIResponsesModel.get_response` (`src/agents/models/openai_responses.py:462-525`) and `AnyLLMModel._get_response_via_responses` (`src/agents/extensions/models/any_llm_model.py:335-397`) previously did not inspect `response.status` at all and would silently return a `ModelResponse` built from the partial/empty `response.output`.
That violates parity with the streaming guard: identical underlying failures (provider backend error, content-filter `incomplete`, `max_output_tokens` hit) crash one path and silently succeed on the other. Users who pick streaming vs non-streaming dynamically would observe inconsistent agent-run results.
Check `response.status in {"failed", "incomplete"}` right after the non-streaming fetch returns and raise the same `response_terminal_failure_error` helper used by the streaming path.
Test plan
Issue number
N/A — found while auditing for the same fix-pattern that #3107 applied to streaming.
Checks