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
This commit is contained in:
Classic298 authored and GitHub committed 2026-11-18 04:56:20 +04:00
1 parent 4c62f4f6d1
commit d8ba9d5538
1 file changed
+1
+1
View File
@@ -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)