From d8ba9d5538b79c19a4f9f7ac6ab57db992d712fe Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:56:20 +0100 Subject: [PATCH] fix: stopping a long tool-calling reply makes the next message compact too early (#34627) A stopped reply was saved without the token counts the model had already reported for it, so the next message had to estimate the reply's size from its text. That estimate includes the model's thinking, which is often not sent back to the model, so after a long tool-calling run it could come out far larger than the real context and trigger compaction well before the threshold. A stopped reply now keeps the counts reported so far, marked incomplete, so the size check starts from the real number; text the stopped round produced after its last report is not counted, which is far less than what the old estimate added. Stopped replies now also show their token usage and count toward the analytics token totals, still not as complete responses. Fixes #34626 --- backend/open_webui/utils/middleware.py | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index e3656d42a1..1b3be005d1 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -6589,6 +6589,7 @@ async def streaming_chat_response_handler(response, ctx): { 'done': True, 'output': cancelled_output, + **({'usage': {**usage, 'incomplete': True}} if usage else {}), }, ) await clear_response_stream(request.app.state.redis, response_stream_task_id)