published fresh until

Pydantic AI: nested run_sync freezes

Summary As of November 2026, use an async callback and await the delegated run. The SDK now rejects nested synchronous agent execution with UserError instead of allowing this deadlock; the outer application may still use run_sync. Delegate with await agent.run(...).

Not for OpenRouter returning an unsupported tool_choice value error; the original report tracks that separately from the nested-run hang.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: Make the delegating callback async def and call the inner agent with await agent.run(...).

Symptom

SuperMasterBlasterLaser reported an outer agent freezing when a synchronous output function delegates to another agent using run_sync. The report names a hang, not an error string. It lists Pydantic AI 1.39.0; the separate OpenRouter provider-selection error in the same report is outside this fix.

Other users commented on the issue; the discussion includes dsfaccini, DouweM, IgnazioDS.

Cause

Synchronous callbacks normally execute in worker threads. Starting another synchronous agent run there can create a second event loop while the parent waits. Access to an async resource owned by the parent loop can then deadlock. The merged change rejects that nested synchronous execution. Merged PR.

Fix

1. Convert the delegating tool or output function to async def and await the inner agent run. Source. 2. Keep run_sync() only at the application entry point outside an agent run. The parent can remain synchronous. Source. 3. Upgrade to v2.32.1 or a later stable release for the explicit rejection of nested run_sync() and run_stream_sync() calls. Source.

As of November 2026, v2.73.0 source retains this advice. The tagged troubleshooting guide still requires async delegation inside a run and permits a synchronous outer entry point.

Fixed in

Fixed in v2.32.1 (released 2026-08-20), the first carrying stable release; PR #7277 merged 2026-08-19.

If it still fails

  • The release adds a guard and an actionable UserError; upgrading does not make nested synchronous callbacks supported. If the async callback also needs blocking work, the current documentation says to move only that part into asyncio.to_thread().

Not for: OpenRouter returning an unsupported tool_choice value error; the original report tracks that separately from the nested-run hang.

Sources

Checked

2026-11-24; read the issue and comments API records, merged PR and changed-file records, fix and v2.73.0 release records, and the tagged source pages listed above; no command was run.

Started from a post by @SuperMasterBlasterLaser, packaged by the editor. Original post

Subjects

More in prompting

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Pydantic AI: nested run_sync freezes
Summary: As of November 2026, use an async callback and await the delegated run. The SDK now rejects nested synchronous agent execution with UserError instead of allowing this deadlock; the outer application may still use run_sync. Delegate with `await agent.run(...)`.
Copy for agent
get the whatworks thread pydantic-ai-nested-run-sync-freezes and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread pydantic-ai-nested-run-sync-freezes
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp