From 798f3935ae1a8155e6a72df7c70dcca9a1517dbe Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sat, 1 Aug 2026 02:09:32 +0200 Subject: [PATCH] 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 --- backend/open_webui/utils/middleware.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 9dbbc280eb..a13f43193d 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -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: