You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Traceback (most recent call last):
File "/Users/huangdon/Documents/universe-platform/warehouse/plan_agent/main.py", line 77, in <module>
asyncio.run(main())
File "/Users/huangdon/miniconda3/envs/universe/lib/python3.11/asyncio/runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/Users/huangdon/miniconda3/envs/universe/lib/python3.11/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/huangdon/miniconda3/envs/universe/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/Users/huangdon/Documents/universe-platform/warehouse/plan_agent/main.py", line 31, in main
async with MCPConnectionManager(context.server_registry):
File "/Users/huangdon/Documents/universe-platform/libs/mcp-agent/src/mcp_agent/mcp/mcp_connection_manager.py", line 186, in __aexit__
await self._tg.__aexit__(exc_type, exc_val, exc_tb)
File "/Users/huangdon/miniconda3/envs/universe/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 778, in __aexit__
return self.cancel_scope.__exit__(exc_type, exc_val, exc_tb)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/huangdon/miniconda3/envs/universe/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 464, in __exit__
raise RuntimeError(
RuntimeError: Attempted to exit a cancel scope that isn't the current tasks's current cancel scope
Why is This Happening?
This error typically occurs when an async task group (_tg) is being exited (aexit) from a different task than the one that created it.
In your traceback:
The error originates from MCPConnectionManager.aexit():
async with MCPConnectionManager(context.server_registry):
This means something is trying to exit the async with block improperly.
Inside MCPConnectionManager.aexit(), it calls:
Here, self._tg is an AnyIO task group (possibly anyio.create_task_group()). aexit() is called from a different task than the one that started the group.
AnyIO detects that the cancel_scope is being exited from the wrong task, leading to:
raise RuntimeError("Attempted to exit a cancel scope that isn't the current task's current cancel scope")
How to Fix It
There are a few possible causes and fixes:
✅ 1️⃣ Ensure the Task Group is Created & Exited in the Same Task
If MCPConnectionManager creates a task group like this:
async with anyio.create_task_group() as tg:
self._tg = tg # Storing task group
Then make sure _tg.aexit() is called within the same task that created it.
The text was updated successfully, but these errors were encountered:
Error
Why is This Happening?
This error typically occurs when an async task group (_tg) is being exited (aexit) from a different task than the one that created it.
In your traceback:
The error originates from MCPConnectionManager.aexit():
This means something is trying to exit the async with block improperly.
Inside MCPConnectionManager.aexit(), it calls:
Here, self._tg is an AnyIO task group (possibly anyio.create_task_group()).
aexit() is called from a different task than the one that started the group.
AnyIO detects that the cancel_scope is being exited from the wrong task, leading to:
How to Fix It
There are a few possible causes and fixes:
✅ 1️⃣ Ensure the Task Group is Created & Exited in the Same Task
If MCPConnectionManager creates a task group like this:
Then make sure _tg.aexit() is called within the same task that created it.
The text was updated successfully, but these errors were encountered: