Repository navigation
Python: Surface failed OpenAI Responses as client exceptions - #9925
Sumedh Aerram (sumedh-aerram) wants to merge 1 commit into
Conversation
Failed Responses API objects and terminal stream snapshots discarded provider errors and returned empty success. Raise through the existing client exception path and clear failed background resume tokens before parsing.
|
Local validation on commit
Full-suite caveat: the first Cloud/service integration tests and the Windows/Linux/Python-version matrices were not run locally. Maintainer agreement and any CLA requirement remain separate from automated reproduction. Upstream fork-workflow runs currently require maintainer approval. Could a maintainer confirm the linked issue direction and approve those runs when appropriate? The CLA check is now successful. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the change to surface failed OpenAI responses as exceptions.
No open issues 🎉
What changed in this PR
This PR addresses #9921 by making failed OpenAI Responses raise ChatClientException instead of returning empty, normal-looking results, allowing applications to trigger retries or fallback.
Changes:
- Surface provider failure details through the existing exception path for non-streaming responses and streaming terminal snapshots.
- Clear continuation tokens before failed background polls raise.
- Add 18 regression cases covering create, structured-output, and resume paths, and document the failure contract.
| File | Description |
|---|---|
python/packages/openai/tests/openai/test_openai_chat_client.py |
Adds failure-handling regression cases and updates terminal-status expectations. |
python/packages/openai/README.md |
Documents exceptions, provider error details, and failed-poll token cleanup. |
python/packages/openai/AGENTS.md |
Records failure-handling and continuation-token requirements. |
python/packages/openai/agent_framework_openai/_chat_client.py |
Adds shared failed-response checks and clears failed-poll tokens before parsing. |
Review effort: Balanced
|
@microsoft-github-policy-service agree |
Motivation & Context
A failed Responses API generation currently returns an empty normal-looking response and drops the provider error. Applications using exceptions for retries or fallback therefore cannot distinguish the failure from an empty answer.
Description & Review Guide
ChatClientExceptionpath, retaining available provider code/message and exception chaining. Clear failed background-poll continuation tokens before parsing can raise. Add 18 regression cases and document the behavior.response.createdsnapshots, and token cleanup before a failed poll raises. Returning only error metadata was rejected because it would continue to bypass exception-based retry/fallback.Related Issue
Fixes #9921.
The issue has automated reproduction evidence. Explicit maintainer agreement has not yet been recorded; this draft presents the focused fix for confirmation of the failed-response error contract.
AI Assistance
AI assistance details: reproduction, implementation, tests, documentation, and PR description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.