mirror of
https://github.com/open-webui/open-webui.git
synced 2026-12-01 17:32:52 -05:00
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:
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(
|
||||
(
|
||||
|
||||
Reference in new issue
Block a user