From 87d148e9cbdeeca1e1be7219e5c1ed4536f3994d Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sun, 8 Nov 2026 10:38:14 +0100 Subject: [PATCH] fix: /compact makes the next message larger after a long tool-calling reply (#33912) Context compaction can already run partway through a long reply that calls many tools. If /compact was used after such a reply, the next message sent the model every tool call and result from that reply again, so the request grew instead of shrinking and could go past the model's context limit. Now the model gets the same shortened history it got before /compact, plus the new summary. Nothing changes in the saved chat or in what the chat shows. Fixes #33911 --- backend/open_webui/utils/context_compaction.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/utils/context_compaction.py b/backend/open_webui/utils/context_compaction.py index 861a0d4f1c..8d277a0964 100644 --- a/backend/open_webui/utils/context_compaction.py +++ b/backend/open_webui/utils/context_compaction.py @@ -328,7 +328,13 @@ def _apply_latest_summary_checkpoint(messages: list[dict]) -> tuple[list[dict], message = messages[idx] value = message.get('contextSummary') or message.get('context_summary') if isinstance(value, str) and value.strip(): - return messages[idx:], value + # Rerun without the summary so a tool-loop reply keeps its mid-turn trim. + if message.get('output'): + [trimmed_message], _ = _apply_latest_summary_checkpoint( + [{**message, 'contextSummary': None, 'context_summary': None}] + ) + message = {**message, 'output': trimmed_message['output']} + return [message, *messages[idx + 1 :]], value marker = next( (