Repository navigation
Python: Preserve provider error responses in hosting - #9665
Roger Barreto (rogerbarreto) wants to merge 4 commits into
Conversation
Use structured provider body codes and messages instead of inferring error titles from HTTP status when rendering response.failed events.
There was a problem hiding this comment.
🟡 Changes recommended
Rendered exception text can bypass sanitization, dependency bounds permit import failures, and non-string fields can suppress valid provider fallbacks.
3 open issues
What changed in this PR
This PR centralizes provider-error extraction for both Python Responses hosting integrations, preserving provider-defined codes and messages while aiming to retain the sanitization introduced in #9460.
Changes:
- Adds a shared classifier for structured provider errors and framework exception wrappers.
- Integrates provider details into failed-response serialization, including arbitrary error codes.
- Adds regression tests, documents error disclosure behavior, and raises the hosting-responses core dependency minimum.
| File | Description |
|---|---|
python/packages/hosting-responses/tests/hosting_responses/test_parsing.py |
Tests streamed provider failures and exception wrappers. |
python/packages/hosting-responses/README.md |
Documents provider-error preservation and disclosure ownership. |
python/packages/hosting-responses/pyproject.toml |
Raises the core dependency minimum. |
python/packages/hosting-responses/agent_framework_hosting_responses/_parsing.py |
Applies shared extraction and preserves arbitrary serialized codes. |
python/packages/foundry_hosting/tests/test_responses.py |
Tests provider details in terminal failure events. |
python/packages/foundry_hosting/README.md |
Documents error-field precedence and disclosure ownership. |
python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py |
Integrates extraction while retaining vetted validation messages. |
python/packages/core/tests/core/test_exceptions.py |
Adds extraction, fallback, and wrapper-boundary tests. |
python/packages/core/agent_framework/exceptions.py |
Implements shared provider-error extraction. |
Review effort: Balanced
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): 659a0e2deafc
Model: gpt-5.6-sol
Overview
The PR centralizes provider-error extraction and applies it consistently to both Responses hosting paths, with useful tests for framework wrappers, cycles, unsupported statuses, and ordinary exception sanitization. However, the declared core floor does not contain the new helper, and the generic hosting path deliberately emits error codes outside the Responses schema. The classifier also trusts HTTP-shaped local exceptions and can itself raise while handling an error, leaving meaningful disclosure and terminal-stream risks.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
4 verified findings remained after source verification (2 high, 2 medium) across 3 files. Details are attached to the affected lines below.
Affected areas: python/packages/core/agent_framework/exceptions.py, python/packages/hosting-responses/agent_framework_hosting_responses/_parsing.py, python/packages/hosting-responses/pyproject.toml
Attach provider-neutral error details when connectors translate SDK failures so hosting never inspects provider exception bodies.
Reuse the original SDK exception already carried by ChatClientException and keep provider-specific handling out of core and connectors.
|
/review |
There was a problem hiding this comment.
MAF Automated Review — Iteration 2
Result: Findings reported
Scope: 2 net-new commit(s): 86bd846b9def, 0cbec8e8d90a
Model: gpt-5.6-sol
Overview
The change narrows provider-error disclosure to the SDK exception carried by ChatClientException, retains sanitized fallbacks, and adds coverage for standard cause chains and primitive provider fields. Property access and malformed effective code/message values fail closed. One residual serialization gap can still replace the intended terminal failure event with a second exception when a provider body contains a non-JSON value.
Reviewed the supplied incremental change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/hosting-responses/agent_framework_hosting_responses/_parsing.py
Fail closed to the sanitized terminal error when a provider body contains non-JSON values or cycles.


Motivation & Context
Provider HTTP errors can contain structured error titles, messages, and correlation fields that callers need for diagnostics and handling. The Python Responses hosting paths previously replaced these details with generic classifications or messages, losing distinctions such as
DeploymentNotFoundandmissing_required_parameter.This change preserves the original SDK error already carried by
ChatClientExceptionwhen converting chat-client failures intoresponse.failed, while retaining the existing generic sanitization for unexpected local failures.Description & Review Guide
agent-framework-hosting-responsesandagent-framework-foundry-hosting; core and connector packages are unchanged.ChatClientExceptionboundary through its existing__cause__/inner_exceptionreference.code,message,status_code, and body fields without interpreting the provider body or inferring classifications from HTTP status.type,param, and Projectsrequest_idinresponse.failed.response.failedreflects the original provider SDK error already carried down-stack.ChatClientExceptionboundary is the correct trust boundary.Related Issue
N/A - internally tracked reliability correction. The originating report is not tracked in a public GitHub issue. The adjacent generic sanitization work in #9460 is already merged and is preserved by this change.
AI Assistance
AI assistance details: Implementation, tests, documentation, live contract validation, 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 the title prefix in sync automatically.