From b933292d63d12be3fd1416fe55519ddc7aa336bc Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Mon, 17 Aug 2026 09:13:51 +0200 Subject: [PATCH] refactor: track visited ids when resolving a chat's current message (#28035) `delete_message_from_history` follows `childrenIds` down to the deepest leaf without recording where it has been. Record it. --- backend/open_webui/models/chats.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/models/chats.py b/backend/open_webui/models/chats.py index 8e39edf456..258d5b7cc6 100644 --- a/backend/open_webui/models/chats.py +++ b/backend/open_webui/models/chats.py @@ -902,8 +902,10 @@ class ChatTable: if current_id is None else messages.get(current_id, {}).get('childrenIds', []) ) - while child_ids: + visited_ids = set() + while child_ids and child_ids[-1] not in visited_ids: current_id = child_ids[-1] + visited_ids.add(current_id) child_ids = messages.get(current_id, {}).get('childrenIds', []) history['currentId'] = current_id if current_id in messages else None return deleted_ids