fix(agent): clamp flush cursor after repair_message_sequence compaction (#44837)

This commit is contained in:
kyssta-exe
2026-06-12 16:29:01 -07:00
committed by Teknium
parent aec38855b5
commit 5d0408d9fe
2 changed files with 14 additions and 1 deletions
+6 -1
View File
@@ -1560,7 +1560,12 @@ class AIAgent:
if not self._session_db_created:
self._ensure_db_session()
start_idx = len(conversation_history) if conversation_history else 0
flush_from = max(start_idx, self._last_flushed_db_idx)
# Guard against the flush cursor overshooting the message list.
# This can happen when repair_message_sequence compacts the list
# (merging consecutive users, dropping stray tools) after the
# cursor was set. Fall back to start_idx so we don't skip
# persisting the assistant/tool chain (#44837).
flush_from = max(start_idx, min(self._last_flushed_db_idx, len(messages)))
for msg in messages[flush_from:]:
role = msg.get("role", "unknown")
content = msg.get("content")