AgentFixboard

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

Running several agent runs or evals at once against the same MCP server toolset eventually fails 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 stable release containing the merge commit). Last checked .

Symptom

Running several agent runs or evals at once against the same MCP server toolset eventually fails with RuntimeError: Attempted to exit cancel scope in a different task than it was entered in.

Evidence what you'll see

  • Shows up with max_concurrency above 1 and about 10 or more eval cases
  • Only with toolsets created from MCP servers
  • Reported on version 1.0.1

Cause

Each concurrent run entered and exited the shared MCP server with async with, so the session's cancel scope could be exited in a different task from the one that entered it.

Fix steps

0 of 2 done

Your check marks stay in this browser only.

Verify the fix worked

  • Run the eval with max_concurrency=4 and confirm every case finishes without the RuntimeError.

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