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
This commit is contained in:
Classic298 authored and GitHub committed 2026-11-08 18:38:14 +09:00
1 parent e8c0ad85e5
commit 87d148e9cb
1 file changed
+7 -1
@@ -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(
(