From c7270b8d8187f217ff4ea669b8ecf0cf26f8aa3d Mon Sep 17 00:00:00 2001 From: nanobot Date: Fri, 31 Jul 2026 15:37:41 +0800 Subject: [PATCH] fix: prevent duplicate user message on session recovery re-publish The re-published last user message was persisted into session history a second time when the agent loop processed it, duplicating the user's input. Mark the re-published InboundMessage with SKIP_USER_PERSIST_META so should_persist_user_message() and _save_skip_for_turn() treat it as already-persisted. --- nanobot/agent/loop.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.py index 001009bb..5606230a 100644 --- a/nanobot/agent/loop.py +++ b/nanobot/agent/loop.py @@ -2151,6 +2151,12 @@ class AgentLoop: sender_id=chat_id, chat_id=chat_id, content=last_user_msg["content"], + # The message already exists in session history + # (persisted before the crash); skip persisting it + # again so recovery does not duplicate it. + metadata={ + turn_continuation.SKIP_USER_PERSIST_META: True + }, ) ) logger.info(