fix: keep streamed Responses output when response.completed reports an empty output array (#27800)

The `response.completed` handler replaced the accumulated output with the terminal event's `output` whenever that key was present, guarded only by `is not None`. An empty array satisfies that guard, so a provider that finishes the stream with `"output": []` wiped everything collected from `response.output_item.added`, `response.output_text.delta` and `response.output_item.done`.

The assistant message was then persisted with `output: []` and empty content, which shows up as a reply that renders correctly while streaming and disappears the moment the stream ends.

Fall back to the accumulated output when the terminal array is empty. A spec-compliant `response.completed` still wins, since a populated array is truthy, and when nothing was streamed the accumulated output is empty too, so the fallback cannot invent content.

Fixes #27789
This commit is contained in:
Classic298 2026-08-01 02:09:32 +02:00 committed by GitHub
parent ac8af4996c
commit 798f3935ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -775,7 +775,8 @@ def handle_responses_streaming_event(
response_data = data.get('response', {})
final_output = response_data.get('output')
new_output = final_output if final_output is not None else current_output
# Some providers send an empty output on response.completed despite having streamed items
new_output = final_output if final_output else current_output
# Ensure reasoning items are marked as completed in the final output
if new_output: