diff --git a/backend/open_webui/utils/context_compaction.py b/backend/open_webui/utils/context_compaction.py index fcb313cbbb..3b6c74017a 100644 --- a/backend/open_webui/utils/context_compaction.py +++ b/backend/open_webui/utils/context_compaction.py @@ -5,7 +5,6 @@ import logging from typing import Any from fastapi.responses import JSONResponse - from open_webui.models.chats import Chats from open_webui.models.config import Config from open_webui.utils.misc import get_content_from_message, get_last_user_message, get_message_list @@ -108,7 +107,9 @@ async def compact_messages_for_request( raise chat_id = metadata.get('chat_id') - checkpoint_message_id = metadata.get('user_message_id') or metadata.get('message_id') + checkpoint_message_id = ( + recent_messages[0].get('id') or metadata.get('user_message_id') or metadata.get('message_id') + ) if chat_id and checkpoint_message_id and not chat_id.startswith(('local:', 'channel:')): await Chats.upsert_message_to_chat_by_id_and_message_id( chat_id,