Ask for approvals and answers inside the run with `RequestInput`, put `AskUser` on the deferred pipeline, and mark deferred calls with `kind` and `answered_by`

Merged
DO
23d ago
+4049-244

Maintainer-directed work (no issue): the first slice of the unified approvals-and-questions design (option B, §7.2 steps 1-3), approved by @DouweM on 2026-11-10.

Why. Approvals, questions and external results are all deferred tool calls, but only approvals could wait inside the run, and AskUser waited privately in its tool body, invisible to a durable engine. This PR puts both on one waiting primitive and one callable contract: ask either returns the answer, or returns None after handing the resume token on, and the answer arrives when the token is resolved.

New public surface

  • pydantic_ai.capabilities.RequestInput(ask, *, timeout=None, name='deferred_tool_calls'); ask(ctx, requests, token) -> DeferredToolResults | None, sync or async (renamed from the unreleased AwaitApproval(announce, ...))
  • pydantic_ai.external_events: wait_for_external_event(name, *, ask, timeout=None), resolve_external_event, fail_external_event, ExternalEventError, ExternalEventWaiter.wait(name, *, ask, timeout), external_event_scope (unreleased)
  • CallDeferred(metadata=None, *, kind='external' | 'question'), DeferredToolRequests.kind(tool_call_id) -> DeferredToolKind ('approval' | 'question' | 'external'), DeferredToolResults.answered_by, build_results(answered_by=...)
  • Harness: AskUser (ordered before HandleDeferredToolCalls), TokenAnswerer ((ctx, request, token) -> AskUserResponse | None)

User-visible behavior

-AskUser(answerer=ask)  # waits inside the tool body, not recorded by a durable engine
+AskUser(answerer=ask)  # question deferred with kind='question', answered by AskUser's handler through the primitive
+RequestInput(policy)   # policy returns DeferredToolResults: answered in place, journaled on Lambda
+RequestInput(notify)   # notify returns None: wait until resolve_external_event / SendDurableExecutionCallbackSuccess
  • Engines without a waiter raise UserError: BaseDurabilityCapability.wrap_run installs a refusing waiter in the durable context unless the engine installed its own (Lambda does), so Temporal, DBOS, Prefect, Azure Durable Task, Render, Absurd and pgtask all refuse without per-engine waiter code. An unrecorded wait could get a different answer on replay and diverge from the journal (thanks @mpfaffenberger, Aditya). Outside durable runs the wait stays in process.
  • Lambda inline answer: the callback is created first; ask runs in step <name>.ask whose result is the answer; a non-None answer is returned without awaiting the callback, which stays open until its timeout and has no effect if resolved later.
  • kind()/answered_by are the typed core surface. Which calls are questions is stored in an internal _kinds field (not public API), serialized as _kinds only when there are questions, so stored, journaled and telemetry payloads keep it and existing payloads are unchanged (_CallDeferred.call_kind is likewise omitted unless 'question').

Verification: RequestInput/primitive, kind() and answered_by, AskUser token/ownership/ModelRetry/run_stream/durable, Temporal refusal, Lambda inline answer and AskUser replay. All new docs examples run in tests/test_examples.py; ruff, check_api_compatibility.py --against v2.66.0 (3 harness 0.x waivers), contract manifest; tests, types and coverage verified by CI.

What changes for existing users: AskUser with an answerer now answers after the step's other tool calls finish, one question at a time (still under run_stream(), since the tool body defers); the answer is no longer on the tool span. AskUserToolset no longer takes answerer/timeout (harness 0.x waivers). DeferredToolRequests/DeferredToolResults JSON and the deferred output schema gain kinds/answered_by.

Open decisions for review: AskUserAnsweredEvent fires only on AskUser's own answerer paths, not for answerer=None or questions RequestInput answers (the event needs an AskUserResponse those paths don't have); answered_by is event-only for now; kinds lists only questions (out of the repr); a failed token maps to AskUser's "did not answer in time" text.

Follow-ups (out of scope): sub-agent inheritance hook (§3.2, step 4), to be designed together with what else child runs should inherit from the parent (usage and usage limits, conversation-held state), and handling SubAgents with custom agent definitions (an agent the user passes in, not one built from the parent); related #4302, #12584, #8807, pydantic/pydantic-ai-harness#947. Waiters for other engines (#12975). clai2 migration (#12979). Argument digest. Recording answered_by on the ToolReturnPart. An explicit option for short waits on engines without a native waiter (Mike's suggestion): wait in process inside ONE durable step/activity so the answer is journaled, with a required timeout; works on Temporal/DBOS, and replaces the removed allow_non_durable_wait flag. #12710: rebase onto the Lambda waiter, which now looks up the step bridge when the wait starts (current_bridge()) instead of at wrap_run. A public field listing every call's kind, if wanted, added later (additively). A finite Lambda callback timeout when RequestInput.timeout is None and ask answers in place (documented for now: set timeout). Carrying kind through Render's own wire protocol.

PR decisions

2026-11-06 · primitive naming and routing · iter -

  • Decision: Core primitive is pydantic_ai.durable_exec.wait_for_external_event(name, *, announce, timeout=None) -> JsonValue; engines subclass ExternalEventWaiter and install it per durable run with external_event_scope (ContextVar); ExternalEventError signals timeout/failure
  • Why: Mirrors the replay_scope pattern from durable-replay-telemetry without depending on it; 'external event' covers both the token family and named-event engines
  • Source: https://github.com/pydantic/pydantic-ai/tree/durable-approvals

2026-11-06 · timeout type · iter -

2026-11-06 · decision payload schema · iter -

  • Decision: The resolver's payload is the JSON form of DeferredToolResults (approvals/calls/metadata), validated with TypeAdapter(DeferredToolResults) then DeferredToolRequests.build_results; no new payload type
  • Why: Existing typed, documented shape already covers approve, deny-with-message, override_args, external results, ToolFailed/ModelRetry and metadata, and round-trips through dump_json
  • Source: https://github.com/pydantic/pydantic-ai/tree/durable-approvals

2026-11-06 · invalid decision · iter -

  • Decision: A payload that is not valid DeferredToolResults or names calls that are not pending raises UserError and fails the run
  • Why: Task asked stale or wrong ids to fail cleanly; the decision is journaled so replay fails the same way instead of silently denying
  • Source: https://github.com/pydantic/pydantic-ai/tree/durable-approvals

2026-11-06 · timeout semantics · iter -

  • Decision: On ExternalEventError (timeout or resolver-reported failure) every pending approval gets ToolDenied and every pending external call ToolFailed, message No decision on this tool call arrived: <reason>; the run continues; no on_timeout knob
  • Why: Never runs a tool without approval, lets the model tell the user, keeps the durable run completing; a raise option can be added if asked
  • Source: https://github.com/pydantic/pydantic-ai/tree/durable-approvals

2026-11-06 · capability placement and scope · iter -

  • Decision: DurableApprovals(announce, *, timeout=None) lives in core pydantic_ai.capabilities, handles approvals and external calls, waits under the fixed name deferred_tool_calls; calls a partial decision leaves out stay pending
  • Why: The primitive is core and the capability is engine-agnostic; external calls are free with the DeferredToolResults payload; partial behavior matches the hook's accumulation semantics
  • Source: https://github.com/pydantic/pydantic-ai/tree/durable-approvals

2026-11-06 · ordering with ApprovalReviewer · iter -

  • Decision: DurableApprovals.get_ordering() returns position='innermost', so ApprovalReviewer, HandleDeferredToolCalls and other handlers resolve calls first and the person is asked only about the rest
  • Why: A wait suspends the run, so it should be the last resort; no change to harness ApprovalReviewer needed (covered by a composition test)
  • Source: https://github.com/pydantic/pydantic-ai/tree/durable-approvals

2026-11-06 · Lambda wait mechanics · iter -

  • Decision: Bridge _CallbackRequest runs create_callback + an announce step + Callback.result() on the handler thread instead of DurableContext.wait_for_callback
  • Why: wait_for_callback wraps operations in a child context that turns CallbackError into a 1.x CallableRuntimeError and a 3.x CallbackSubmitterError/subclasses; the direct form raises CallbackError for timeout/failure on both SDK lines
  • Source: https://github.com/pydantic/pydantic-ai/tree/durable-approvals

2026-11-06 · Lambda naming and step config · iter -

  • Decision: Callback named {agent}__external_event.{name}, announce step {agent}__external_event.{name}.announce; the announce step gets the base step_config; waiter installed in AWSLambdaDurability.wrap_run only inside the bridge
  • Why: Matches JournalOperationNamer style; step_config is documented as applying to every step
  • Source: https://github.com/pydantic/pydantic-ai/tree/durable-approvals

2026-11-06 · SDK pin · iter -

2026-11-06 · pre-push review 1 of 3 at 8bc45efdfded5f0176ffd019ac952ee353c0ff10 · iter -

2026-11-06 · pre-push review 1 of 3 at 8bc45efdfded5f0176ffd019ac952ee353c0ff10 · iter -

2026-11-06 · sync announce lane · iter -

  • Decision: A sync announce runs in a worker thread through _utils.run_in_executor, like sync tools and hooks; async runs on the loop
  • Why: Documented uses (Slack, email, DB row) are blocking I/O; agent_docs/concurrency.md asks for a deliberate lane; reviewer flagged it as a maintainer choice, default picked here
  • Source: https://github.com/pydantic/pydantic-ai/tree/durable-approvals

2026-11-06 · pre-push review 2 of 3 at 4734b9e700c30283d01b11634ce792bf11419522 · iter -

2026-11-06 · pre-push review 2 of 3 at 4734b9e700c30283d01b11634ce792bf11419522 · iter -

2026-11-06 · pre-push review 3 of 3 at 0ebe6c67adc652ed87164647ecbe0265efd5da76 · iter -

2026-11-06 · pre-push review 3 of 3 at 0ebe6c67adc652ed87164647ecbe0265efd5da76 · iter -

2026-11-06 · douwebot/veria thread: decision metadata · iter -

  • Decision: DurableApprovals rejects decision metadata keyed to calls that are not pending (UserError), instead of changing core build_results
  • Why: build_results only checks approvals/calls; keeping the fix in the capability avoids changing build_results for every caller; review budget exhausted so pushed after local checks
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757#discussion_r4498453284

2026-11-09 · redesign after maintainer review 2026-11-09 · iter -

  • Decision: Maintainer-approved scope change, signed off by Douwe in this session: rename DurableApprovals to AwaitApproval, which always works (in-process default waiter with resolve_external_event, engine waiter under a durable engine); tested docs examples; new pre-push review budget of 3 for this redesign
  • Why: Douwe's review of #12757: one capability that works durable or not, docs explaining announce vs. the answer and the relation to HandleDeferredToolCalls; sync announce stays in a worker thread and timeout keeps denying (no raise option)
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-09 · module placement · iter -

  • Decision: The primitive lives in a new public neutral module pydantic_ai.external_events (wait_for_external_event, resolve_external_event, fail_external_event, ExternalEventError, ExternalEventWaiter, external_event_scope); pydantic_ai.durable_exec re-exports only the engine-builder trio ExternalEventError, ExternalEventWaiter, external_event_scope
  • Why: It is no longer durable-only, so user code imports it from a neutral module like pydantic_ai.framing; engine authors keep finding everything on the documented pydantic_ai.durable_exec surface; unreleased, so renamed without deprecations
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-09 · failure API · iter -

  • Decision: fail_external_event(token: str, reason: str) -> None alongside resolve_external_event(token: str, payload: object) -> None instead of an error= parameter
  • Why: Mirrors the success/failure pair of token engines (Lambda SendDurableExecutionCallbackSuccess/Failure); keeps each signature single-purpose and typed, with no payload/error both-or-neither validation
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-09 · in-process waiter mechanics · iter -

  • Decision: Token is secrets.token_urlsafe(32) in a process-local dict; the entry holds an anyio.Event woken thread-safely (asyncio call_soon_threadsafe, Trio run_sync_soon); _pending_events.pop makes a token resolve once; the wait removes its entry on completion, timeout and cancellation; a resolution racing the timeout still wins; timeout raises ExternalEventError('No resolution arrived within <timeout>.')
  • Why: Resolvable from any thread (sync web endpoints) and both AnyIO backends; anyio.from_thread with a loop token needs anyio>=4.11 while the floor is 4.7
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-09 · payload normalization · iter -

  • Decision: resolve_external_event takes payload: object and converts it with to_jsonable_python (UserError if not serializable), so the wait returns JsonValue as it would through an engine
  • Why: JsonValue as a parameter type rejects ordinary dict[str, dict[str, bool]] literals under pyright (dict invariance), which the docs example hit; normalizing keeps in-process and Lambda payloads identical
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-09 · durable engines without a waiter · iter -

  • Decision: Inside a durable run whose engine installs no waiter (Temporal, DBOS, Prefect, other harness engines), the wait raises UserError instead of falling back in process; detected via the current RunContext's in_durable_context, which AwaitApproval sets around the wait
  • Why: An in-process wait there would not be journaled (re-announces on replay, lost on restart) and is unsafe in Temporal's workflow sandbox; open for Douwe to flip for DBOS/Prefect if he prefers 'always works'
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-09 · docs examples · iter -

  • Decision: All new/changed code blocks in await-approval.md, aws-lambda.md approvals, and backends.md run and lint in tests/test_examples.py (mocked model responses added; aws-lambda.md added to RUNNABLE_HARNESS_PAGES with a skipif for the SDK); no new skips
  • Why: Maintainer requirement 4; Lambda snippets only define the handler and a decide() function, so nothing calls AWS
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-09 · redesign pre-push review 1 of 3 at 1c201b1027805dbccea2e7ac2250a97c2dfafb8b · iter -

2026-11-09 · redesign pre-push review 1 of 3 at 1c201b1027805dbccea2e7ac2250a97c2dfafb8b · iter -

2026-11-09 · redesign pre-push review 2 of 3 at a56bf935b64814007cc87f799c0ac33ff70ff304 · iter -

2026-11-09 · redesign pre-push review 2 of 3 at a56bf935b64814007cc87f799c0ac33ff70ff304 · iter -

2026-11-09 · redesign pre-push review 3 of 3 at 6e17d81d19bab1229d92447ef162d7fa5f62e47e · iter -

2026-11-09 · redesign pre-push review 3 of 3 at 6e17d81d19bab1229d92447ef162d7fa5f62e47e · iter -

2026-11-10 · redesign 2 after maintainer approval 2026-11-10 · iter -

  • Decision: Douwe approved proposal option B (core RequestInput + harness AskUser on one primitive), ask-returns-results-or-None, keep raising on engines without a waiter plus an opt-in in-process flag, core kind/answered_by fields; scope = proposal §7.2 steps 1-3; fresh pre-push review budget of 3 for this redesign
  • Why: Maintainer sign-off 2026-11-10 relayed by the delegating agent; placement in core confirmed after a brief harness-only detour
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-10 · AwaitApproval renamed RequestInput, announce replaced by ask · iter -

  • Decision: RequestInput(ask, *, timeout, allow_non_durable_wait) in pydantic_ai.capabilities; ask(ctx, requests, token) -> DeferredToolResults | None, sync or async; wait_for_external_event(name, *, ask, timeout, allow_non_durable_wait) and ExternalEventWaiter.wait(name, *, ask, timeout); ask's answer goes through the JSON form like a resolution; a None answer means wait
  • Why: Proposal §2.3/§6; one signature serves inline answerers and token deliverers; JSON round trip keeps in-process and durable identical
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-10 · in-process timeout bounds ask · iter -

  • Decision: The in-process waiter's timeout covers ask plus the wait, so an async ask still running is cancelled; on Lambda the callback timeout starts at creation and does not cancel the ask step
  • Why: Preserves AskUser's existing timeout semantics (slow answerer cancelled, 'did not answer in time')
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-10 · Lambda inline answer · iter -

  • Decision: Callback created first; ask runs in step '.ask' whose result is the answer as a JSON string (or None); a non-None answer is returned without awaiting the callback, which is left open until its timeout; resolving it later has no effect on the run
  • Why: Lambda cannot resolve its own callback without an external API call; leaving it open is harmless and replay reuses the step result
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-10 · opt-in flag name · iter -

  • Decision: allow_non_durable_wait: bool = False on RequestInput, AskUser and wait_for_external_event; default keeps raising UserError on durable engines without a waiter
  • Why: Douwe: raise by default plus explicit opt-in; docs state replay re-asks, restart loses the wait, and it does not work on Temporal (workflow loop has no call_soon_threadsafe)
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-10 · kind and answered_by shape · iter -

  • Decision: CallDeferred(metadata, *, kind: 'external'|'question'='external'); DeferredToolRequests.kinds: dict[str, DeferredToolKind] lists only questions (non-default kinds) plus kind(tool_call_id) method; DeferredToolResults.answered_by: dict[str, str] carried by build_results/update/filter and RequestInput's decision payload; durable _CallDeferred journals call_kind only when 'question' (exclude_if) so existing payloads are unchanged
  • Why: Typed core fields per Douwe; listing only questions keeps DeferredToolRequests equality/output unchanged for every existing user; recording answered_by on ToolReturnPart metadata left as follow-up
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-10 · AskUser on the deferred pipeline · iter -

  • Decision: Tool body always emits AskUserRequestedEvent and raises CallDeferred(kind='question', metadata={'ask_user': }); AskUser.handle_deferred_tool_calls answers only its own questions (by that metadata) one at a time via wait_for_external_event('ask_user_question'); answerer gains a 3-positional-param TokenAnswerer form returning AskUserResponse | None; the toolset now carries the capability id as its toolset id so it works under durable engines; ExternalEventError (timeout or resolver failure) -> TIMED_OUT + timed_out event; other errors -> failed event and re-raise
  • Why: Proposal §1.4; owner metadata keeps two AskUsers apart under PrefixTools; answerer gets a ctx with the call's tool_call_id/tool_name as before
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-10 · AskUser behavior changes accepted · iter -

  • Decision: AskUser with an answerer now (a) answers after sibling tool calls finish, (b) ends the run under run_stream() since it never runs deferred handlers (#12686), (c) raises UserError on Temporal/DBOS/Prefect unless allow_non_durable_wait, (d) the answer no longer appears on the execute_tool span
  • Why: Consequences of moving onto the deferred pipeline that Douwe approved; documented; flagged as open decision in the PR
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-10 · kinds out of the repr · iter -

  • Decision: DeferredToolRequests.kinds is field(repr=False); answered_by stays in DeferredToolResults' repr
  • Why: Adding kinds={} to every repr changed printed docs output and UI stream snapshots for users who never use questions; kind() reads it
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-10 · redesign 2 pre-push review 1 of 3 at 023807d59dc42c62574237606719bb66758d6375 · iter -

2026-11-10 · redesign 2 pre-push review 1 of 3 at 023807d59dc42c62574237606719bb66758d6375 · iter -

  • Decision: remediated: AskUser keeps ModelRetry from the answerer as a retry prompt; answered_by docstring states it is event-only and ignored on resume (ToolReturnPart recording is follow-up); TemporalDurability.wrap_run installs a refusing waiter so allow_non_durable_wait can't hang a workflow (+ Temporal test); questions keep model order in DeferredToolRequests.calls; tests for AskUser ownership (ids, PrefixTools, foreign question) and run_stream behaviour. Escalated, not changed: run_stream regression (#12686) and AskUserAnsweredEvent for answerer=None/RequestInput-answered questions (event needs an AskUserResponse that those paths don't have)
  • Why: Findings 1-6 of review 1; remediation commit follows
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-10 · AskUserAnsweredEvent scope · iter -

  • Decision: 'Every path' means every path through AskUser's own answerer (inline answer, token resolution, timeout, failed token, answerer error); not emitted for answerer=None or when RequestInput answers a question
  • Why: The event carries an AskUserResponse, which those paths never see (they get the rendered ask_user_result); flagged for Douwe
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-10 · Temporal refuses external-event waits · iter -

  • Decision: TemporalDurability.wrap_run enters external_event_scope with a waiter that raises UserError (#12975), so allow_non_durable_wait is ignored on Temporal instead of hanging the workflow
  • Why: Review 1 finding 4; Temporal's workflow loop has no call_soon_threadsafe and threads are disabled
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-10 · redesign 2 pre-push review 2 of 3 at 05630538f120c4d22a1c5869c19d09529de6df32 · iter -

2026-11-10 · redesign 2 pre-push review 2 of 3 at 05630538f120c4d22a1c5869c19d09529de6df32 · iter -

  • Decision: dispatch failed: reviewer exceeded its context window reading the full branch diff; no findings returned
  • Why: counted against the budget; next dispatch scoped to the follow-up diff with targeted file reads
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-10 · redesign 2 pre-push review 3 of 3 at 05630538f120c4d22a1c5869c19d09529de6df32 · iter -

2026-11-10 · redesign 2 pre-push review 3 of 3 at 05630538f120c4d22a1c5869c19d09529de6df32 · iter -

2026-11-10 · CI repair at 06928e528f · iter -

  • Decision: extracted _with_deferred_tool_requests to bring _resolve_deferred_calls back to its pre-PR complexity (CI cognitive complexity check: 24 -> 26)
  • Why: pure extract-method refactor of reviewed logic; review budget exhausted, pushed after ruff and pre-commit
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-10 · AskUser under run_stream · iter -

  • Decision: AskUser keeps working under run_stream(): its tool body defers at runtime, and run_stream only short-circuits tools declared deferred (requires_approval/external), so #12686 affects RequestInput with those tools, not AskUser; test pins it
  • Why: CI showed the answer under run_stream, contradicting the earlier assumption; docs and PR body corrected
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-11 · webinar feedback 2026-11-10 · iter -

  • Decision: Took: additive RequestInput(name='deferred_tool_calls') naming the wait (Lambda callback/ask step), and docs that a decision must cover every pending call unless DeferredToolRequests is an output type, and that an approved call shows two call_tool: steps. Deferred to follow-ups: request summary in the journaled ask step, telling ask the wait's deadline
  • Why: Mergeable/releasable by 2026-11-11 for the Lambda webinar; only additive, low-risk items; existing signatures unchanged
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-11 · review remediation: AskUser ordering (douwebot) · iter -

  • Decision: AskUser.get_ordering returns CapabilityOrdering(wraps=[HandleDeferredToolCalls]), like ApprovalReviewer, so it answers its own questions before generic handlers wherever listed; test with a fill-everything handler listed first
  • Why: douwebot finding valid: a generic handler listed earlier would answer the question with a placeholder; making other handlers skip kind='question' would change HandleDeferredToolCalls semantics for every user
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-11 · review remediation: pickle coverage (douwebot) · iter -

  • Decision: CallDeferred pickle round trip folded into tests/test_exceptions.py parametrization (question case + kind on existing cases); separate test removed
  • Why: douwebot finding; avoid duplicate test
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-11 · review remediation: answers pass after_tool_execute (Veria) · iter -

  • Decision: Verified real: in-run handler answers in DeferredToolResults.calls skip execute_tool_call, so after_tool_execute guards never saw AskUser answers that previously came from the tool body. Fix scoped to questions the tool raised itself (CallDeferred(kind='question') from execution) and answered during the run: the processor keeps their ValidatedToolCall, and the answer passes the new ToolManager.after_tool_execute(validated, result) (ModelRetry/ValidationError -> retry, ToolFailed -> failed); a bare ToolReturn wrapper is unwrapped so hooks see the plain value. External results and answers passed to a new run are unchanged (pre-existing behaviour)
  • Why: Restores the guard pass AskUser answers had before this PR without moving behaviour for existing external-result users; before/wrap hooks not re-run to avoid double execution side effects and a second span
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-11 · review remediation: AskUser asks the questions the tool received (Veria) · iter -

  • Decision: The tool body records the questions it received (after before_tool_execute rewrites, e.g. argument guards) in the deferral metadata under 'questions'; AskUser rebuilds the request from them, falling back to the call's arguments
  • Why: Veria Medium finding valid: rebuilding from the ToolCallPart undid argument redaction that the in-tool answerer path previously respected
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-11 · maintainer decision 2026-11-11: remove allow_non_durable_wait, engine-side guard · iter -

  • Decision: Removed allow_non_durable_wait from RequestInput, AskUser and wait_for_external_event (+ docs/tests/skills). BaseDurabilityCapability.wrap_run now enters _refuse_unsupported_external_events(engine_name) in the durable context, installing a refusing ExternalEventWaiter unless the engine already installed one (Lambda installs its callback waiter before calling super). Engines that overrode wrap_run without super (Temporal, DBOS, pgtask, Absurd) now call super().wrap_run; Prefect, Azure Durable Task and Render inherit it. Temporal's own refusing waiter removed. RequestInput/AskUser no longer sniff RunContext.in_durable_context (AskUser still makes the run context current for its answerer, as the tool body did)
  • Why: Douwe after Mike Pfaffenberger/Aditya feedback: don't ship a core flag we'd deprecate; an unrecorded wait can diverge from the journal on replay (DBOS)
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-11 · Lambda bridge looked up at wait time · iter -

  • Decision: _CallbackWaiter no longer captures the StepBridge at wrap_run; wait() reads current_bridge() and raises UserError if none
  • Why: Mike: capture at wrap_run could hang in parallel branches and collides with #12710; small change, tested
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-11 · review remediation: test placement (douwebot) · iter -

  • Decision: Moved tests/test_deferred_tool_kinds.py into tests/test_tools.py (kinds/answered_by, remaining/filter, args-validator question, approved call deferring again) and tests/test_capabilities.py (after_tool_execute answer tests); file deleted
  • Why: douwebot: tests belong next to their siblings
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-11 · Lambda callback left open with timeout=None · iter -

  • Decision: Documented (RequestInput.timeout docstring, Lambda docs Approvals): without a timeout, a callback whose wait ask answered in place has no timeout and is never closed; set timeout when ask may answer in place. Finite-callback fix is a follow-up
  • Why: SDK source doesn't establish that open callbacks on a completed execution are harmless service-side; no signature change before release
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-11 · review remediation: inline handle_call answers pass after_tool_execute (douwebot) · iter -

  • Decision: handle_call passes its ValidatedToolCall to _resolve_single_deferred; when the deferral is a CallDeferred(kind='question') raised by execution (no validated.deferral), the handler's answer goes through ToolManager.after_tool_execute, which gained wrap_validation_errors (raw errors for sandboxed callers). Tests drive handle_call from a tool: redaction applies to the question, not the external result; raw ModelRetry/ToolFailed with wrap_validation_errors=False
  • Why: douwebot 3rd review: CodeMode/realtime use handle_call and skipped result guards for AskUser answers
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757

2026-11-11 · maintainer decision: DeferredToolRequests.kinds made internal · iter -

  • Decision: Public field kinds removed; replaced by internal dataclass field _kinds (repr=False, Field(exclude_if=empty)), set internally via the _kinds= constructor keyword; DeferredToolRequests.kind(tool_call_id) stays the public reader. Serialized key is _kinds, emitted only when questions exist, so TypeAdapter round trips (stored outputs, Temporal/DBOS results, journal payloads) keep question kinds, the deferred output schema lists _kinds, and telemetry redaction carries _kinds only when non-empty; existing payloads without questions are byte-identical to main. Cross-module reads carry pyright reportPrivateUsage ignores
  • Why: Douwe 2026-11-11: a public field listing only questions is confusing and changing a released core field later is a behavior change; a private-named serialized field is the smallest way to keep round-trips; a public shape can be added later additively
  • Source: https://github.com/pydantic/pydantic-ai/pull/12757