Raise `UserError` when validation requests approval for an external tool, keep single-model tool arguments through durable re-validation, and document concurrent DBOS runs and shared MCP `http_client`s
This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.
Four independent fixes in deferred tools, durable execution and MCP, shipped together. Two change code: a deferral raised while validating a tool call now routes like one raised by the tool, and durable engines that re-validate tool arguments after a JSON round trip now read them as they were validated. Two are documentation for limitations that stay.
[!WARNING]
Compatibility impact: A validation hook (after_tool_validate, or wrap_tool_validate after its handler) or a tool's args_validator that raises ApprovalRequired for an external tool, from an ExternalToolset or an AG-UI frontend tool, now raises UserError instead of listing the call in DeferredToolRequests.calls. A CallDeferred raised while validating a requires_approval=True tool now lists the call in calls instead of approvals.
Why this can ship in a minor release: Both relied on routing that contradicted the documented contract, under which a deferral raised during validation is handled exactly like one raised by the tool function.
Migration: For an external tool, raise CallDeferred with the metadata its executor needs, and approve the call where it's executed.
New public surface: none.
1. Validation-time deferrals on tools deferred by their kind
An external tool's calls, and a requires_approval=True tool's, are collected by their tool's kind. A deferral raised while validating one was ignored there: an ApprovalRequired on an external tool put the call in calls, where the application's executor runs it unapproved, and a CallDeferred on an approval tool put it in approvals. The deferral's metadata was dropped in both cases.
@dataclass
class RequireApproval(AbstractCapability[Any]):
async def after_tool_validate(self, ctx, *, call, tool_def, args):
raise ApprovalRequired(metadata={'reason': 'policy'})
agent = Agent(model, toolsets=[ExternalToolset([tool_def])], capabilities=[RequireApproval()], output_type=[str, DeferredToolRequests])
agent.run_sync('...')
# before: DeferredToolRequests(calls=[<the call>], approvals=[], metadata={})
# after: UserError: `ApprovalRequired` was raised while validating a call to external tool ...
Now the raised deferral decides, as it does for every other tool, and its metadata reaches DeferredToolRequests.metadata. That lifts the known limitation #6897 recorded and pinned in test_args_validator_deferral_metadata_not_merged_for_already_deferred_kinds, now ..._kept_...; a tool body's metadata still can't arrive, since the body doesn't run before approval. An external tool can't be approved: its calls run outside the agent run, and resuming an approved one already raised RuntimeError('External tools cannot be called'). So requesting approval for one is a UserError, on the graph and in ToolManager.handle_call (Code Mode, realtime). docs/hooks.md and docs/capabilities/custom.md say so.
2. Single-model tool arguments through durable re-validation
Engines that run tools in another process (TemporalAgent, TemporalDurability, and the Render and Azure Durable Task harness engines) validate a tool's arguments again after they arrive as JSON. For def run_job(data: Job), validated arguments are {'data': Job(...)} and arrive as {'data': {'data': ..., 'dry_run': True}}. When Job itself has a field data that accepts a dict, the validator read that as Job(data={...everything...}, dry_run=False): the tool ran with its other fields reset to their defaults.
FunctionSchema.revalidate now validates the envelope's content as the model's input instead of guessing, and revalidate_function_call and the TemporalAgent activity use it. Arguments of every other shape validate as before.
durable_exec/_toolset.py :: revalidate_function_call() # TemporalDurability, Render, Azure Durable Task
durable_exec/temporal/_toolset.py :: call_tool_in_activity() # TemporalAgent
-└─ _function_schema.py :: _validate_single_arg({'data': {'data': {...}, 'dry_run': True}})
- └─ Job(data={'data': {...}, 'dry_run': True}, dry_run=False)
+└─ durable_exec/_toolset.py :: revalidate_function_args()
+ └─ _function_schema.py :: FunctionSchema.revalidate()
+ └─ Job(data={...}, dry_run=True)
3. Docs: concurrent runs of one agent in one DBOS workflow
Every run of an agent records its steps under the same names, and DBOS replays steps by start order, checking only names. Two concurrent runs of one agent in one workflow (asyncio.gather(agent.run(a), agent.run(b)), or parallel tool calls that each run the same nested agent) can start their steps in a different order during recovery, and each run gets the other's recorded results. A new "Concurrent Agent Runs" section says to give each run a workflow of its own (a @DBOS.workflow per run, or child_workflow tool metadata), and the "Durable calls in parallel tools" warning now says reordered same-named steps can swap results, not only fail recovery. Detecting the swap during recovery is follow-up #12962.
4. Docs: a shared MCP http_client shares its cookie jar
MCPToolset(url, auth=<function>, http_client=client) opens one session per run, but every session sends through client, so a cookie the server sets for one user's run goes out with later runs for other users. "Per-user authentication", the http_client annotation and the http_client docstring now say not to share a client between users' runs, and to configure TLS with verify= instead.
Verification
- Item 1:
tests/test_capability_hooks.py—TestToolHookDeferrals.test_validate_hook_deferral_overrides_tool_kind,test_validate_hook_cannot_require_approval_for_external_tool,test_handle_call_cannot_require_approval_for_external_tool;tests/test_tools.py::test_args_validator_deferral_metadata_kept_for_already_deferred_kinds. - Item 2:
tests/durable_exec/temporal/test_toolsets.py::test_single_model_arg_named_like_its_field_keeps_its_arguments(a workflow on bothTemporalDurabilityandTemporalAgent) andtests/durable_exec/test_durable_run_context.py::test_revalidate_function_call_reads_a_single_model_argument_as_it_was_validated. - Each of those fails on
mainand passes here. The Temporal suite skips on Python 3.14+, so it was run on 3.13. - Items 3 and 4 were checked by running them: a child workflow per concurrent DBOS run, and
child_workflowon parallel nested-agent tool calls, keep each run's results through recovery;MCPToolset(verify=...)withouthttp_clientgives each session its own client and cookies (FastMCP 3.4.7).
What changes for existing users: nothing, unless a validation hook deferred a tool that was already deferred by its kind, or a durable tool takes a single Pydantic model with a field named like the parameter.
PR decisions
2026-11-09 · one PR for four bug fixes · iter -
- Decision: Ship the four reproduced defects as one PR, each fixed as an ordinary bug
- Why: David asked for one PR, not one PR per defect (2026-11-09)
- Source: https://github.com/pydantic/pydantic-ai/tree/deferred-approval-durable-fixes
- Session: 1628b29c-cb2c-43b8-9268-6e738f6157fd
2026-11-09 · external tool approval during validation fails closed · iter -
- Decision: ApprovalRequired raised while validating an external tool call raises UserError (graph and handle_call); other validation-time deferrals route by type and keep metadata
- Why: An approved external call already raises RuntimeError on resume, so no approval path exists; supporting approve-then-hand-off would be a new feature that changes the pinned RuntimeError
- Source: https://github.com/pydantic/pydantic-ai/tree/deferred-approval-durable-fixes
- Session: 1628b29c-cb2c-43b8-9268-6e738f6157fd
2026-11-09 · durable re-validation unwraps through FunctionSchema.revalidate · iter -
- Decision: Boundaries look the tool's FunctionSchema up in its FunctionToolset and pass the envelope content through a private marker the single-arg wrap validator recognizes; no new public field, no wire change, no validation-context marker
- Why: Calling the validator on the unwrapped content still hits its collision guess for alias models dumped by field name; a user validation context can't carry a marker
- Source: https://github.com/pydantic/pydantic-ai/tree/deferred-approval-durable-fixes
- Session: 1628b29c-cb2c-43b8-9268-6e738f6157fd
2026-11-09 · DBOS concurrent runs and MCP shared http_client: docs only · iter -
- Decision: Document one workflow per concurrent run (child workflow) and correct the parallel-tools warning; document that a shared http_client shares its cookie jar and point per-user setups at verify=
- Why: Code fixes would strand in-flight DBOS workflows or break released MCP configurations; a DBOS replay check needs its own design
- Source: https://github.com/pydantic/pydantic-ai/tree/deferred-approval-durable-fixes
- Session: 1628b29c-cb2c-43b8-9268-6e738f6157fd
2026-11-09 · no THREAT_MODEL.md update · iter -
- Decision: None of the THREAT_MODEL.md 'Keeping this model current' triggers applies
- Why: No new input path, authority transfer, trust or disclosure default change, or execution backend guarantee change; DBOS and MCP items document existing behavior
- Source: https://github.com/pydantic/pydantic-ai/tree/deferred-approval-durable-fixes
- Session: 1628b29c-cb2c-43b8-9268-6e738f6157fd
2026-11-09 · validator deferral metadata kept for requires_approval tools · iter -
- Decision: test_args_validator_deferral_metadata_not_merged_for_already_deferred_kinds, which pinned the dropped metadata as current behavior, now asserts the validator's metadata reaches DeferredToolRequests.metadata (renamed ...kept...); the body case is unchanged because the body never runs before approval
- Why: The validator ran and raised ApprovalRequired(metadata=...); dropping it contradicts the documented contract that a validation-time deferral is handled like one raised by the tool function
- Source: https://github.com/pydantic/pydantic-ai/tree/deferred-approval-durable-fixes
- Session: 1628b29c-cb2c-43b8-9268-6e738f6157fd
2026-11-09 · pre-push review 1 of 3 at a3b771fda762803d58726925912c59d5f750d813 · iter -
- Decision: dispatched (outcome appended below)
- Why: reviewed tree f0cbfef541ead652dd01b3730110985890d87485; scope 58d5894b2ca6f7c6045e448c111cdb301b1b261e..a3b771fda762803d58726925912c59d5f750d813 (full branch); first review
- Source: https://github.com/pydantic/pydantic-ai/tree/deferred-approval-durable-fixes
- Session: 1628b29c-cb2c-43b8-9268-6e738f6157fd
2026-11-09 · pre-push review 1 of 3 at a3b771fda762803d58726925912c59d5f750d813 · iter -
- Decision: remediated: agent skill CAPABILITIES-AND-HOOKS.md gains the external-tool UserError rule; two _function_schema.py comments no longer name Temporal as an envelope caller
- Why: reviewed tree f0cbfef541ead652dd01b3730110985890d87485; scope 58d5894b2c..a3b771fda7 (full branch); 2 findings, both valid
- Source: https://github.com/pydantic/pydantic-ai/tree/deferred-approval-durable-fixes
- Session: 1628b29c-cb2c-43b8-9268-6e738f6157fd
2026-11-09 · pre-push review 2 of 3 at d00693628bc8184db752f0b7d25622d74ecd8563 · iter -
- Decision: dispatched (outcome appended below)
- Why: reviewed tree 21f38391c2e0554e957ad2e9fd98a75c63fbb119; scope a3b771fda7..d00693628bc8184db752f0b7d25622d74ecd8563 (follow-up on review 1 remediation)
- Source: https://github.com/pydantic/pydantic-ai/tree/deferred-approval-durable-fixes
- Session: 1628b29c-cb2c-43b8-9268-6e738f6157fd
2026-11-09 · wire validator deferral metadata into kind-based collection · iter -
- Decision: Lift the known limitation #6897 recorded: a validation-time deferral's metadata reaches DeferredToolRequests.metadata for tools deferred by kind; the pinning test now asserts it
- Why: #6897 pinned the drop so that changing it would be a deliberate decision; David accepted the fix shape that includes it (2026-11-09)
- Source: https://github.com/pydantic/pydantic-ai/pull/6897
- Session: 1628b29c-cb2c-43b8-9268-6e738f6157fd
- Supersedes: validator deferral metadata kept for requires_approval tools
2026-11-09 · pre-push review 2 of 3 at d00693628bc8184db752f0b7d25622d74ecd8563 · iter -
- Decision: no findings
- Why: reviewed tree 21f38391c2e0554e957ad2e9fd98a75c63fbb119; scope a3b771fda7..d00693628b; both review-1 findings verified fixed
- Source: https://github.com/pydantic/pydantic-ai/tree/deferred-approval-durable-fixes
- Session: 1628b29c-cb2c-43b8-9268-6e738f6157fd
2026-11-09 · exempt delta at 340d54f92c from reviewed d00693628b · iter -
- Decision: No re-review: missing-coverage test addition only (tests/test_tools.py), chained from reviewed SHA d00693628bc8184db752f0b7d25622d74ecd8563
- Why: CI coverage missed _tool_execution.py arc 1120->1122; the added validator raises CallDeferred() without metadata on a requires_approval tool, the routing the reviewed tree established; test passes and covers the arc
- Source: https://github.com/pydantic/pydantic-ai/pull/12958
- Session: 1628b29c-cb2c-43b8-9268-6e738f6157fd
2026-11-09 · empty commit be54950f39 to retrigger CI · iter -
- Decision: Exempt delta: tree identical to 340d54f92c, itself an exempt coverage-test delta chained from reviewed d00693628b
- Why: CI run 42669606617 concluded failure without creating its coverage and check jobs, no job failed, and GitHub refuses to retry it
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/42669606617
- Session: 1628b29c-cb2c-43b8-9268-6e738f6157fd
2026-11-09 · defer: DBOS replay check for concurrent runs of one agent · iter -
- Decision: Filed as #12962 instead of fixing here; route: immediate work, owner dsfaccini (assigned, pydanty:skip)
- Why: Out of scope for this PR — the check needs its own design (what each run records, where it's checked, how older recordings are treated); David chose to file it (2026-11-09)
- Source: https://github.com/pydantic/pydantic-ai/issues/12962
- Session: 1628b29c-cb2c-43b8-9268-6e738f6157fd
2026-11-09 · empty commit 7df9d6bfca to retrigger CI · iter -
- Decision: Exempt delta: tree identical to 340d54f92c (exempt coverage-test delta chained from reviewed d00693628b)
- Why: CI run 42672976282 created no classify or test jobs during the GitHub Actions major outage (incident from 18:12Z); Actions reported operational at 18:45Z
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/42672976282
- Session: 1628b29c-cb2c-43b8-9268-6e738f6157fd
2026-11-09 · exempt delta at 2c569b206a from reviewed d00693628b · iter -
- Decision: No re-review: test-only move of the Temporal single-model round-trip test from a new module into tests/durable_exec/temporal/test_toolsets.py, per douwebot
- Why: Same test body and assertions under the module's existing gating; passes on Python 3.13 for both paths; pyright clean
- Source: https://github.com/pydantic/pydantic-ai/pull/12958#discussion_r4516751654
- Session: 1628b29c-cb2c-43b8-9268-6e738f6157fd
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.