8 Commits
Author SHA1 Message Date
nanobot 298b7ac6f6 fix: use dedicated _shutting_down flag for cancel-time checkpoint restore
Test Suite / Detect changes (push) Has been cancelled
Test Suite / webui (push) Has been cancelled
Test Suite / docker (push) Has been cancelled
Test Suite / Python (Windows, 3.14) (push) Has been cancelled
Test Suite / Python (minimum, 3.11) (push) Has been cancelled
Test Suite / Python (latest, 3.14 + coverage) (push) Has been cancelled
The previous guard used self._running, which is False both before run()
starts and during shutdown. Tests and process_direct() dispatch messages
with _running=False, so cancelled turns there silently skipped the
checkpoint restore and lost partial context. Introduce _shutting_down,
set only by stop(), and gate the restore on it.
2026-07-31 15:49:31 +08:00
nanobot c7270b8d81 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.
2026-07-31 15:37:41 +08:00
nanobot 66b8743024 docs: NixOS deployment guide from Camellia 2026-07-31 15:36:51 +08:00
nanobot 617a0129b7 Revert "docs: deployment guide from Camellia experience"
This reverts commit ded5d4d8ed.
2026-07-31 15:36:51 +08:00
nanobot 3b4eb40f1e docs: deployment guide from Camellia experience 2026-07-31 15:36:51 +08:00
nanobot 6b7f3889ea fix: raise error when Telegram bot not running instead of silently dropping messages
When the outbound dispatcher processes recovery notifications before the
Telegram bot is fully started, the send() method silently returned, causing
the notification to be lost. Now it raises RuntimeError so _send_with_retry
will retry until the bot is ready.
2026-07-31 15:36:51 +08:00
nanobot 9240000e75 fix: capture pending_user_turn before _restore_runtime_checkpoint clears it
_restore_runtime_checkpoint() clears both the runtime_checkpoint and
pending_user_turn flags (lines 1966-1967). recover_stale_sessions()
checked had_pending AFTER calling it, so had_pending was always False
when a checkpoint existed. This meant the re-publish of the last user
message never happened — the user got a notification but the interrupted
turn was never re-triggered.
2026-07-31 15:36:51 +08:00
nanobot 5248513ad1 feat: notify user and re-trigger interrupted turns on session recovery
recover_stale_sessions now publishes a restart notification to the user channel and re-publishes the last user message for sessions with a pending turn, so interrupted work continues automatically after a crash or restart. Also skip checkpoint restore during shutdown so pending markers survive for startup recovery.
2026-07-31 15:36:47 +08:00
+11 -3
View File
@@ -378,6 +378,7 @@ class AgentLoop:
)
self._unified_session = unified_session
self._running = False
self._shutting_down = False
self._mcp_servers = mcp_servers or {}
self._mcp_stacks: dict[str, MCPConnection] = {}
self._mcp_connecting = False
@@ -1224,11 +1225,11 @@ class AgentLoop:
# it into session history now makes it visible in the
# next conversation turn.
#
# During gateway shutdown (self._running is False), skip
# this so the pending markers survive and
# During gateway shutdown (self._shutting_down is True),
# skip this so the pending markers survive and
# recover_stale_sessions() can notify the user and
# re-trigger the interrupted turn on next startup.
if self._running:
if not self._shutting_down:
try:
key = self._effective_session_key(msg)
session = self.sessions.get_or_create(key)
@@ -1318,6 +1319,7 @@ class AgentLoop:
def stop(self) -> None:
"""Stop the agent loop."""
self._running = False
self._shutting_down = True
logger.info("Agent loop stopping")
async def _process_message(
@@ -2151,6 +2153,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(