From 7a201f131a3b7642bc71d22acd79aa6754d4f0b9 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Wed, 9 Sep 2026 20:44:06 +0200 Subject: [PATCH] fix: stop streaming the raw reasoning tag into the thinking panel When a model streams its reasoning inline as or text, the chunk that opens the block is forwarded to the browser as-is, so the literal tag sits at the top of the thinking panel for as long as the block is open, and the chunk that closes it lands in the answer with the closing tag still in it. Both only clean up when the response finishes and the final output replaces what the browser accumulated. Regressed in v0.11.1 with the per-chunk delta events; v0.10.2 resent the already cleaned output instead. The backend already strips the tags from its own output items in that same chunk. Now, whenever the tag scanner opens or closes an item, the cleaned output is resent whole (the same snapshot event the handler already sends at the end of a response) instead of the raw delta, so the thinking panel shows clean text from the first chunk and the answer never carries the closing tag. Chunks without a tag transition still stream as plain deltas, unchanged. Channel chats adopt that snapshot too, and the browser now applies text deltas to a code interpreter block's code so it keeps streaming after the tag. Fixes #29842 --- backend/open_webui/socket/main.py | 4 ++++ backend/open_webui/utils/middleware.py | 11 +++++++++++ src/lib/components/chat/Messages/structuredOutput.ts | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/backend/open_webui/socket/main.py b/backend/open_webui/socket/main.py index c3678f592d..69c24507b7 100644 --- a/backend/open_webui/socket/main.py +++ b/backend/open_webui/socket/main.py @@ -1,6 +1,7 @@ from __future__ import annotations import asyncio +import copy import logging import random import sys @@ -1006,6 +1007,9 @@ async def _make_channel_emitter(request_info): if not content and not output and not done: return + if isinstance(output, list): + state['output'] = copy.deepcopy(output) + now = time.time() if done or (now - state['last_emit_at']) >= THROTTLE_INTERVAL: state['last_emit_at'] = now diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index 8ab00a9185..f7aec88e5a 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -5447,6 +5447,8 @@ async def streaming_chat_response_handler(response, ctx): } ] + pre_tag_item_id = output[-1].get('id') + if DETECT_REASONING_TAGS: output, _ = tag_output_handler( 'reasoning', @@ -5488,6 +5490,15 @@ async def streaming_chat_response_handler(response, ctx): } delta_type = delta_event_type + # the raw chunk still carries the tag text: resend the cleaned output instead + if target_item.get('id') != pre_tag_item_id: + await flush_pending_delta_data() + await event_emitter( + {'type': 'chat:completion', 'data': {'output': full_output()}} + ) + await save_current_response_stream() + data = None + if delta and data: await queue_pending_delta_data(data, delta_type) elif data: diff --git a/src/lib/components/chat/Messages/structuredOutput.ts b/src/lib/components/chat/Messages/structuredOutput.ts index 55ef655a2b..cede49a3f0 100644 --- a/src/lib/components/chat/Messages/structuredOutput.ts +++ b/src/lib/components/chat/Messages/structuredOutput.ts @@ -626,6 +626,11 @@ export function applyResponseStreamEvent( return nextOutput; } + if (item.type === 'open_webui:code_interpreter') { + item.code = appendDelta(item.code ?? '', event.delta); + return nextOutput; + } + const key = deltaType === 'output_text' || deltaType === 'reasoning_text' ? 'text' : deltaType; item.content = [...(item.content ?? [])]; const part = ensurePart(item.content, event.content_index ?? 0);