From 0e5eb45c095f83d700050d84ffed85d4d4c6d0e2 Mon Sep 17 00:00:00 2001 From: G30 <50341825+silentoplayz@users.noreply.github.com> Date: Fri, 27 Nov 2026 08:23:50 -0500 Subject: [PATCH] fix: keep a reply's text when its model connection drops partway through (#35143) --- backend/open_webui/utils/middleware.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index c0ef5437b9..38c6005415 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -6857,6 +6857,19 @@ async def streaming_chat_response_handler(response, ctx): except (asyncio.CancelledError, Exception): pass raise # re-raise CancelledError for proper propagation + except Exception: + if save_to_chat: + failed_output = full_output() + for item in failed_output: + if item.get('status') == 'in_progress': + item['status'] = 'incomplete' + await Chats.upsert_message_to_chat_by_id_and_message_id( + metadata['chat_id'], + metadata['message_id'], + {'output': failed_output}, + ) + await clear_response_stream(request.app.state.redis, response_stream_task_id) + raise if response.background is not None: await response.background()