From e9a98598340b6ec3aee838f222c36cae6fdf22e7 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Sat, 26 Sep 2026 18:22:48 +0530 Subject: [PATCH] fix(agent): replay the history prefix when healing a deleted session row MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The heal retry passed the caller's conversation_history through, so _db_flush_collect's id()-based history shortcut treated the prefix as already durable and skipped it. The row was recreated with only the new tail and the flush returned True: a silent partial restore. On the session_row_missing retry, pass conversation_history=None so the full in-memory transcript lands on the recreated row. Co-authored-by: 赵桂雄 --- agent/session_persistence.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/agent/session_persistence.py b/agent/session_persistence.py index 6279f4e3d5..7ea64314d0 100644 --- a/agent/session_persistence.py +++ b/agent/session_persistence.py @@ -444,7 +444,10 @@ class SessionPersistenceMixin: return True except Exception as e: if _db_flush_failed(self, e, batch_rows, _adoption_budget, messages): - return self._flush_messages_to_session_db_unlocked(messages, conversation_history, _adoption_budget=0) + # A recreated row lost the history prefix too: the id()-based history shortcut must not skip it. + healed = self._last_persistence_error_cause == "session_row_missing" + return self._flush_messages_to_session_db_unlocked( + messages, None if healed else conversation_history, _adoption_budget=0) return False def _get_messages_up_to_last_assistant(self, messages: List[Dict]) -> List[Dict]: