From d7a74450b529b246a2649c2256918d6670430c1a Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Wed, 30 Sep 2026 17:43:13 +0200 Subject: [PATCH] fix: question and answer vanish from the chat when a background sub-agent finishes before the answer (#31557) When a background sub-agent finished while the model was still writing the answer that started it, the sub-agent's report was placed as a reply to the previous answer instead. Once the answer ended, the chat switched to that other branch of the conversation, which hid the latest question and answer, and the model replied to the report without seeing that question and answer. The report now follows the answer that started the sub-agent (or the newest completed reply after it), so the conversation stays on one branch. Fixes #31507 --- backend/open_webui/utils/subagents.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/utils/subagents.py b/backend/open_webui/utils/subagents.py index f020e0cd94..b2f9693af8 100644 --- a/backend/open_webui/utils/subagents.py +++ b/backend/open_webui/utils/subagents.py @@ -615,10 +615,16 @@ async def delegate( updated_chat = copy.deepcopy(parent.chat or {}) updated_history = updated_chat.setdefault('history', {}) updated_messages = updated_history.setdefault('messages', {}) + parent_message = updated_messages.get(parent_message_id) done_assistants = [ message - for message in updated_messages.values() - if message.get('role') == 'assistant' and message.get('done') is not False + for message_id, message in updated_messages.items() + if message.get('role') == 'assistant' + and 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')