Agent FixboardAgentFixboard

Concurrent runs sharing an MCP server fail with a cancel scope RuntimeError

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.

From GitHub

pydantic/pydantic-ai

Difficulty
Easy
Time
~5 min
Steps
2
Fixed in
v1.92.0
Last checked

Verified fix: PR #4514 merged on . Fixed in v1.92.0 (first published release whose tag contains the merge commit). Last checked .

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_concurrency is 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_concurrency of 4 and confirm every case finishes without that RuntimeError.

If it still fails

  • The linked issue does not describe the cancel-scope RuntimeError on v1.92.0. On 1.0.1 it 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