From 588d58b9ff95ffbc941e36e86ba1acb168849fae Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Mon, 30 Nov 2026 19:25:28 +0100 Subject: [PATCH] fix: model answers the previous question after compaction between tool calls (#35375) When context compaction ran between tool calls and the messages it kept still included an earlier question, the current prompt was moved in front of that earlier question. The model then saw the previous question as the latest one and answered it again. The current prompt now stays in its place when it is still among the kept messages, and is only put back in front of them when compaction removed it. Fixes #35366 --- backend/open_webui/utils/middleware.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index b3c35ce5d3..5b0907a294 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -6490,8 +6490,7 @@ async def streaming_chat_response_handler(response, ctx): for message, content in user_messages: message['content'] = content if compacted: - if user_prompt is not None: - messages = [message for message in messages if message != user_prompt] + if user_prompt is not None and user_prompt not in messages: messages.insert( 1 if messages and messages[0].get('role') == 'system' else 0, dict(user_prompt),