Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(remote): replace failed routes without duplicate-instance errors
Xubin Ren02ce0cfb6fd5
diff --git a/nanobot/webui/remote_instances.py b/nanobot/webui/remote_instances.pyindex 7bef0c7b6..274ee09b6 100644--- a/nanobot/webui/remote_instances.py+++ b/nanobot/webui/remote_instances.py@@ -475,8 +475,11 @@ class RemoteInstances:raise RemoteError("same_instance")# SSH aliases identify routes, not nanobot instances. Don't open# two independent browser views of the same live gateway.- if any(item.gateway_id == identity["gatewayId"]- for item in self.connections.values()):+ duplicates = [(saved_key, item) for saved_key, item in self.connections.items()+ if item.gateway_id == identity["gatewayId"]]+ for _, item in duplicates:+ await self._check(item)+ if any(not item.error for _, item in duplicates):raise RemoteError("duplicate_instance")# Require the installed WebUI too, not just a port answering HTTP.page = await client.get(base + "/")@@ -502,6 +505,12 @@ class RemoteInstances:profiles[key].local_port = proxy.portprofiles[key].proxy_origin = Trueself._write(profiles)+ # A failed route must not block a newly verified route to this bot.+ # Retire it only after the replacement is saved; retain its profile+ # and browser origin, so other tabs keep their drafts and fail closed.+ for saved_key, item in duplicates:+ await item.proxy.pause()+ del self.connections[saved_key]self._proxies[proxy.port] = proxyself.connections[key] = connectionreturn self._launch(key, profile, connection)diff --git a/tests/webui/test_remote_instances.py b/tests/webui/test_remote_instances.pyindex 55d0fed86..adfba8209 100644--- a/tests/webui/test_remote_instances.py+++ b/tests/webui/test_remote_instances.py@@ -329,6 +329,24 @@ async def test_forget_only_removes_saved_profile(manager, ssh):ssh.tunnel.close.assert_not_awaited()+async def test_offline_alias_does_not_block_replacement_connection(manager, ssh, monkeypatch):+ first = await save(manager)+ await manager.action("connect", {"id": first})+ ssh.tunnel.active = False+ alias = await save(manager, host="working-route")+ second_tunnel = SimpleNamespace(active=True, error="", port=23457, close=AsyncMock())+ second_proxy = SimpleNamespace(port=23458, origin="http://127.0.0.1:23458", secret="local-two")+ monkeypatch.setattr(remote_ssh, "open_tunnel", AsyncMock(return_value=second_tunnel))+ monkeypatch.setattr(RemoteProxy, "open", AsyncMock(return_value=second_proxy))++ assert (await manager.action("connect", {"id": alias}))["gateway_id"] == "remote-one"+ assert first not in manager.connections+ assert manager.connections[alias].proxy is second_proxy+ ssh.tunnel.pause.assert_awaited_once()+ ssh.tunnel.close.assert_not_awaited() # Keep the old browser origin reserved.+ assert len(manager.snapshot()["profiles"]) == 2 # No saved routes/drafts were deleted.++async def test_closing_local_manager_reaps_ssh(manager, ssh):key = await save(manager)await manager.action("connect", {"id": key})