Skip to content

Surface the error from a streamed Responses response.failed event#546

Open
PratikDhanave wants to merge 1 commit into
microsoft:mainfrom
PratikDhanave:fix-openai-responses-failed-event
Open

Surface the error from a streamed Responses response.failed event#546
PratikDhanave wants to merge 1 commit into
microsoft:mainfrom
PratikDhanave:fix-openai-responses-failed-event

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

Problem

In the OpenAI Responses streaming path, responsesProcessStreamingUpdate has cases for ResponseCompletedEvent, ResponseIncompleteEvent, and a top-level ResponseErrorEvent (which emits ErrorContent) — but no case for ResponseFailedEvent (response.failed). A failed response carries its error on the response object (Response.Error), so it falls through to the default branch, which emits an empty update:

default:
    u = createUpdate(message.RoleAssistant, nil)
    ...

The result: when a streamed response fails, the framework yields updates with a ResponseID but no error content and no error — the failure and its message (e.g. "Internal error") are silently dropped, so a failed response is indistinguishable from an empty successful one.

Fix

Add a case responses.ResponseFailedEvent that surfaces the error as ErrorContent built from Response.Error (message + code), mirroring the existing ResponseErrorEvent handling and the ResponseCompletedEvent metadata (id, createdAt, additional properties). Small, local, no exported signature changes.

Test

TestResponsesStreamingFailedResponseSurfacesError streams a response.failed event with error: {code, message} and asserts an ErrorContent carrying that message/code is emitted. Fails on main (got none), passes with the fix. The existing TestResponsesStreamingResponseWithFailedUpdate_HandlesCorrectly (which only checks ResponseID) still passes.

A response.failed streaming event carries its error on the response
object (Response.Error), but responsesProcessStreamingUpdate had no case
for ResponseFailedEvent, so it fell through to the default branch and
emitted an empty update — silently dropping the failure and its message.

Handle ResponseFailedEvent by emitting an ErrorContent built from
Response.Error (message + code), mirroring the existing ResponseErrorEvent
handling. Adds a streaming test asserting the error is surfaced; the
existing failed-update test (which only checks ResponseID) still passes.
Copilot AI review requested due to automatic review settings July 18, 2026 17:32
@PratikDhanave
PratikDhanave requested a review from a team as a code owner July 18, 2026 17:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the OpenAI Responses streaming pathway so that response.failed events surface the embedded response error (message/code) instead of producing an empty update, making streamed failures observable to consumers.

Changes:

  • Add handling for responses.ResponseFailedEvent to emit ErrorContent from Response.Error.
  • Add a regression test ensuring streamed response.failed yields ErrorContent with the expected message/code.
  • Minor formatting adjustment in NewResponsesAgent call site (gofmt-style).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
provider/openaiprovider/responses.go Adds response.failed event handling to propagate response error details into streamed updates.
provider/openaiprovider/responses_test.go Adds a streaming test verifying failed responses produce ErrorContent instead of an empty update.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1053 to +1058
if event.Response.Error.Message != "" {
u.Contents = []message.Content{&message.ErrorContent{
Message: event.Response.Error.Message,
ErrorCode: string(event.Response.Error.Code),
}}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants