Symptom
Concurrent runs that share an MCP server toolset fail with RuntimeError: Attempted to exit cancel scope in a different task than it was entered in.
Evidence what you'll see
- The report sees it when
max_concurrencyis above 1 and the eval has about 10 or more cases. - It shows up for toolsets created from MCP servers.
Why it happens
Each concurrent run entered and exited the shared MCP server with async with, so the session's cancel scope could be left from a different task than the one that entered it.
Affected versions
Pydantic AI 1.0.1, Python 3.12.7. The linked issue does not name an operating system.
Fix steps
0 of 2 done
Your check marks stay in this browser only.
How to check it worked
- Run the eval with
max_concurrencyof4and confirm every case finishes without thatRuntimeError.
If it still fails
- The linked issue does not describe the cancel-scope
RuntimeErroronv1.92.0. On1.0.1it appears once concurrency is above 1.
Sources and credit
Summarized in our own words from these public reports. Credit goes to their authors.
Provided as is, without warranty. Try changes in a non-production environment and back up first. Security-related steps: verify against the official docs. Terms · Request removal or attribution change
Hit an error we don't cover? Submit it