fix: preserve real cancellation in MCP paths

This commit is contained in:
adabarbulescu
2026-07-18 17:36:35 +08:00
committed by Xubin Ren
parent 07ad0bafa8
commit d4f5abe004
5 changed files with 80 additions and 9 deletions
+28
View File
@@ -111,6 +111,34 @@ class TestHandleStop:
class TestDispatch:
@pytest.mark.asyncio
async def test_run_logs_and_continues_after_leaked_cancelled_error(self, monkeypatch):
loop, bus = _make_loop()
loop._connect_mcp = AsyncMock()
loop.close_mcp = AsyncMock()
loop.auto_compact.check_expired = MagicMock()
warnings: list[str] = []
calls = 0
async def consume_once_then_stop():
nonlocal calls
calls += 1
if calls == 1:
raise asyncio.CancelledError()
loop.stop()
raise asyncio.TimeoutError()
monkeypatch.setattr(bus, "consume_inbound", consume_once_then_stop)
monkeypatch.setattr(
"nanobot.agent.loop.logger.warning",
lambda message, *args, **kwargs: warnings.append(message),
)
await loop.run()
assert calls == 2
assert any("Ignoring leaked CancelledError" in warning for warning in warnings)
def test_exec_tool_not_registered_when_disabled(self):
from nanobot.agent.tools.shell import ExecToolConfig
from nanobot.config.schema import ToolsConfig