Skip to content

Python: [Bug]: OpenAI Responses SSE error codes are lost when wrapped in ChatClientException #9593

Description

Observed Behavior

Upgrading agent-framework-openai from 1.16.0 to 1.17.0 changes how the Responses adapter handles SSE type="error" events.

The SDK provides a structured ResponseErrorEvent with code, message, and param. The adapter now converts it into a plain RuntimeError, then wraps it in ChatClientException:

self._handle_request_error(
    RuntimeError(f"OpenAI streaming error: {error_details}")
)

After unwrapping inner_exception or __cause__, callers receive only the formatted string. The original event and its structured error code are no longer available.

This handling was introduced in #8886.

Applications that classify provider errors for bounded retries can no longer recognize transient SSE codes such as:

  • server_error
  • rate_limit_exceeded

In our reproduction, each error stopped after one request despite retries being enabled for that category. Structured error-code telemetry is also lost.

This report concerns flat SSE type="error" events, not HTTP error responses or response.failed events.

Expected Behavior

Raising an exception for an SSE error is reasonable, but callers should still be able to recover its structured provider metadata without parsing exception messages.

For example, retain a typed provider exception containing code, message, and param as ChatClientException.inner_exception, or expose the original event through a documented interface.

Please preserve this metadata for both streaming request paths and add regression coverage for server_error and rate_limit_exceeded.

Steps to Reproduce

This exercises the adapter conversion directly and makes no network request:

from agent_framework.exceptions import ChatClientException
from agent_framework.openai import OpenAIChatClient
from openai.types.responses import ResponseErrorEvent

client = OpenAIChatClient(
    model="example-model",
    api_key="not-used",
)

event = ResponseErrorEvent(
    type="error",
    sequence_number=1,
    code="server_error",
    message="Transient provider failure",
    param=None,
)

try:
    client._parse_chunk_from_openai(
        event,
        options={},
        function_call_ids={},
    )
except ChatClientException as exc:
    root = exc.inner_exception
    print(type(root).__name__)
    print(str(root))
    print(getattr(root, "code", None))

Actual output:

RuntimeError
OpenAI streaming error: server_error: Transient provider failure
None

Minimal Reproduction

see above

Error Messages and Stack Traces


Package Versions

agent-framework-openai 1.17.0

Python Version

3.14

Operating System

Linux

Regression

Yes

Additional Context

No response

Acknowledgements

  • I searched existing issues and did not find a duplicate.
  • I personally verified this behavior and the reproduction details are authentic.
  • I will wait for explicit maintainer agreement before starting implementation of a non-trivial change.

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 22, 2026
  2. added
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Oct 22, 2026
  3. github-actions commented on Oct 22, 2026

    @github-actions
    Contributor

    🤖 Automated triage reproduction notes (agent-authored — trust but verify)

    Agent analysis

    The bug is in python/packages/openai/agent_framework_openai/_chat_client.py::_parse_chunk_from_openai at lines 3938-3944, where flat ResponseErrorEvent values are converted into a text-only RuntimeError. It is triggered by type="error" events carrying codes such as server_error or rate_limit_exceeded. Minimal repro: construct either event, call _parse_chunk_from_openai directly, catch ChatClientException, and inspect the code on its cause.

    • Failing test: python/packages/openai/tests/openai/test_openai_chat_client.py::test_streaming_error_event_preserves_provider_error_code
    • Files examined: python/packages/openai/agent_framework_openai/_chat_client.py, python/packages/openai/tests/openai/test_openai_chat_client.py, python/packages/core/agent_framework/exceptions.py, python/packages/openai/pyproject.toml
    • Tests run: test_streaming_error_event_raises_chat_client_exception, test_streaming_error_event_preserves_provider_error_code
    • Reported version: 1.17.0
    • Current version: 1.17.0
  4. added
    agentsUsage: [Issues, PRs], Target: Single agent
    and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agentsUsage: [Issues, PRs], Target: Single agentpythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions