From 883c7434fb6196d01b12de9f8ce19bd9f0797cd6 Mon Sep 17 00:00:00 2001 From: G30 <50341825+silentoplayz@users.noreply.github.com> Date: Fri, 21 Aug 2026 18:51:21 -0400 Subject: [PATCH] fix: tolerate reasoning items without started_at when closing them at stream end (#28872) --- backend/open_webui/utils/middleware.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index b9921e382d..e713fad15e 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -5262,9 +5262,10 @@ async def streaming_chat_response_handler(response, ctx): reasoning_item = output[-1] if reasoning_item.get('ended_at') is None: reasoning_item['ended_at'] = time.time() - reasoning_item['duration'] = int( - reasoning_item['ended_at'] - reasoning_item['started_at'] - ) + if reasoning_item.get('started_at') is not None: + reasoning_item['duration'] = int( + reasoning_item['ended_at'] - reasoning_item['started_at'] + ) reasoning_item['status'] = 'completed' if response_tool_calls: