From 75bb64be19ce61be44dbd3341bcb689608a6c1f7 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Mon, 16 Nov 2026 15:27:31 +0100 Subject: [PATCH] fix: two background sub-agent reports that finish close together split the chat into two branches (#34542) * fix: two background sub-agent reports that finish close together split the chat into two branches When a model started two background sub-agents and the second one finished while the reply to the first report was still being written, the second report was attached to the answer that started them. The two reports ended up as separate branches and the chat switched to the second one, hiding the first report and the reply to it. The second report now goes after the reply that is still being written and is answered once that reply ends, so the conversation stays on one branch. Fixes #34540 * Only treat an unfinished reply as the place for a report while it is still being written --- backend/open_webui/utils/subagents.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/backend/open_webui/utils/subagents.py b/backend/open_webui/utils/subagents.py index 688177d3ac..996626a578 100644 --- a/backend/open_webui/utils/subagents.py +++ b/backend/open_webui/utils/subagents.py @@ -661,23 +661,24 @@ async def delegate( updated_history = updated_chat.setdefault('history', {}) updated_messages = updated_history.setdefault('messages', {}) parent_message = updated_messages.get(parent_message_id) - done_assistants = [ + is_active = await has_active_tasks(request.app.state.redis, parent_chat_id) + assistants = [ message for message_id, message in updated_messages.items() if message.get('role') == 'assistant' - and message.get('done') is not False + and (is_active or message.get('done') is not False) and ( parent_message is None or any(entry is parent_message for entry in get_message_list(updated_messages, message_id)) ) ] result_parent_id = ( - max(done_assistants, key=lambda message: message.get('timestamp', 0)).get('id') - if done_assistants + max(assistants, key=lambda message: message.get('timestamp', 0)).get('id') + if assistants else parent_message_id ) pending_message['parentId'] = result_parent_id - if await has_active_tasks(request.app.state.redis, parent_chat_id): + if is_active: pending_message['meta']['status'] = 'pending' updated_messages[pending_message_id] = pending_message if result_parent_id and result_parent_id in updated_messages: