From 22f8516dd9f9ade50ff4f6d60fa01ab965926b77 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sat, 5 Dec 2026 05:03:38 +0100 Subject: [PATCH] fix: a chat compacted on demand is compacted again although little is left (#35679) Compacting a chat by hand stores the summary on the last reply, and that reply still carried the token count of the whole history the summary replaced. The server kept counting the chat at its size from before the compaction, so when later replies reported no token count, a short chat was compacted again a couple of messages later and its reported context usage stayed at the old size. The server now counts from what is actually left after the compaction. The context usage shown in the chat (/status) is worked out by the page itself and gets the matching change in a separate fix. Related to #35678 --- backend/open_webui/utils/context_compaction.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/open_webui/utils/context_compaction.py b/backend/open_webui/utils/context_compaction.py index 1314ef1600..c1a5e07534 100644 --- a/backend/open_webui/utils/context_compaction.py +++ b/backend/open_webui/utils/context_compaction.py @@ -318,6 +318,8 @@ def _apply_latest_summary_checkpoint(messages: list[dict]) -> tuple[list[dict], [{**message, 'contextSummary': None, 'context_summary': None}] ) message = {**message, 'output': trimmed_message['output']} + # A reply compacted on demand still carries the usage of the history its summary replaced. + message = {key: item for key, item in message.items() if key != 'usage'} return [message, *messages[idx + 1 :]], value marker = next(