From efcbd9c6d72ed3f643b8c8dc80e7b55b1a201755 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Wed, 25 Nov 2026 13:21:47 +0400 Subject: [PATCH] refac --- backend/open_webui/routers/chats.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/backend/open_webui/routers/chats.py b/backend/open_webui/routers/chats.py index 6a651ba120..ab0f18bd83 100644 --- a/backend/open_webui/routers/chats.py +++ b/backend/open_webui/routers/chats.py @@ -1884,16 +1884,17 @@ async def delete_chat_by_id( # deleting the chat to prevent orphaned requests. await stop_item_tasks(request.app.state.redis, id) - # Cascade to internal child chats spawned from this one. - for child_id in await Chats.get_internal_chat_ids_by_parent_id(id, chat.user_id): - await stop_item_tasks(request.app.state.redis, child_id) - await Chats.delete_chat_by_id_and_user_id(child_id, chat.user_id) - + # Delete first so stopped sub-agents have no chat to report back to. if user.role == 'admin': result = await Chats.delete_chat_by_id(id, db=db) else: result = await Chats.delete_chat_by_id_and_user_id(id, user.id, db=db) + # Cascade to internal child chats spawned from this one. + for child_id in await Chats.get_internal_chat_ids_by_parent_id(id, chat.user_id): + await stop_item_tasks(request.app.state.redis, child_id) + await Chats.delete_chat_by_id_and_user_id(child_id, chat.user_id) + if result: await publish_event( request,