From 35e9872cd3c99b97a2ee0f6183bf095a2be9f51b Mon Sep 17 00:00:00 2001 From: chengyongru Date: Sat, 9 May 2026 15:27:23 +0800 Subject: [PATCH] refactor(loop): extract _build_retry_wait_callback --- nanobot/agent/loop.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/nanobot/agent/loop.py b/nanobot/agent/loop.py index 3bd7bf84e..877b58ef6 100644 --- a/nanobot/agent/loop.py +++ b/nanobot/agent/loop.py @@ -536,6 +536,25 @@ class AgentLoop: return _bus_progress + async def _build_retry_wait_callback( + self, msg: InboundMessage + ) -> Callable[[str], Awaitable[None]]: + """Build a retry-wait callback that publishes to the message bus.""" + + async def _on_retry_wait(content: str) -> None: + meta = dict(msg.metadata or {}) + meta["_retry_wait"] = True + await self.bus.publish_outbound( + OutboundMessage( + channel=msg.channel, + chat_id=msg.chat_id, + content=content, + metadata=meta, + ) + ) + + return _on_retry_wait + async def _dispatch_command_inline( self, msg: InboundMessage, @@ -1137,18 +1156,7 @@ class AgentLoop: ) _bus_progress = await self._build_bus_progress_callback(msg) - - async def _on_retry_wait(content: str) -> None: - meta = dict(msg.metadata or {}) - meta["_retry_wait"] = True - await self.bus.publish_outbound( - OutboundMessage( - channel=msg.channel, - chat_id=msg.chat_id, - content=content, - metadata=meta, - ) - ) + _on_retry_wait = await self._build_retry_wait_callback(msg) # Persist the triggering user message up front so a mid-turn crash # doesn't silently lose the prompt on recovery. ``media`` rides along