Make the durable engine extension surface public: operation types, `ParameterTransports`, `DurableRunContext` and run identity hooks
Why we make these changes
Part of #4764 (Azure Durable Functions / Durable Task). Some durability engines run a durable unit on a different worker from the run that dispatched it: Temporal activities, Render child tasks, and the Durable Task integration in #11021. Those engines have to move each operation's parameters, including the RunContext, across the boundary as data. The types and helpers for that were private, so Render imported them through render/_compat.py, and #11021 needs the same set. Render also kept its own copy of Temporal's RunContext serialization, and that copy had already drifted: it carried no tool_name_for_kind snapshot.
This PR makes that surface public and moves the serialization into one engine-neutral class that all three engines build on. It also retires the private hooks engines had to override: the parameter transports and function-call preparation move onto a public ParameterTransports on the engine's backend, the validation-context hook goes away, and the replay-safe run identity and clock hooks become public on AbstractCapability.
New public surface
In pydantic_ai.durable_exec:
DurableRunContext, withserialize_run_context,deserialize_run_context,unavailable_field_message, and the newrestore(serialized, *, deps, agent, engine_spec). It rebuildsvalidation_contextfrom the agent the first time it's read.TemporalRunContextnow subclasses it.ParameterTransports: one method per operation kind, each passing parameters through unchanged by default, plus an asyncprepare_function_call. Backends expose it asDurableOperationBackend.parameter_transports, andRegisteredOperationBackend(parameter_transports=...)accepts one.revalidate_function_callis the shared worker-side argument re-validation.- On
AbstractCapability:get_default_run_id(),get_default_conversation_id(),get_run_clock(),get_run_start_time(). These were_default_run_idand friends, which Temporal, DBOS and Prefect already overrode. - Operation building blocks:
DurableOperation,BoundDurableOperation,DurableOperationConfig,ParameterTransport,ResultCodec,CacheIdentity,durable_unit_scope. - Parameter types:
ModelRequestParams,ModelCompactMessagesParams,ModelCancelSuspendedResponseParams,EventStreamHandlerParams,ToolsetGetToolsParams,ToolsetCallToolParams,DynamicToolsetCallToolParams,CapabilityOperationParams,CapabilityMethodDeclaration,WorkspaceCall,WorkspaceCallParams. - Result types and helpers:
CallToolResult,DynamicToolsResult,WorkspaceCallResult,ModelRequestContextProjection,capability_operation_result_type.
Removed: the private _*_parameter_transport, _prepare_function_call_params and _validation_context hooks on BaseDurabilityCapability. Only Temporal and Render overrode them.
User-visible behavior
A tool running in a Temporal activity can read the agent's validation context:
agent = Agent(..., validation_context=lambda ctx: {'tenant': ctx.deps.tenant}, capabilities=[TemporalDurability()])
@agent.tool
def lookup(ctx: RunContext[Deps]) -> str:
return ctx.validation_context['tenant'] # before: UserError ('validation_context' is not available); after: the rebuilt value
Temporal's serialized payload, other field guards, and error messages are unchanged. Render's tool_name_for_kind now answers from the dispatch-time snapshot instead of returning None, and its "workspace can't be restored" message uses the engine spec's wording.
Verification
tests/durable_exec/test_durable_run_context.py: a JSON round trip of a real run's context throughDurableRunContext.restore, covering carried fields, guards, enqueue/emit rejection, and a subclass carrying an extra field.tests/durable_exec/test_durable_exec_compat.py: pins the new exports.- Existing Temporal suites (run locally on 3.13) and
tests/harness/renderpass unchanged.
What changes for existing users
Nothing breaks: ctx.validation_context becomes readable inside Temporal activities, and Render's tool_name_for_kind and workspace-restore message change as described above.
For third-party durability engines: the private hooks they overrode are renamed or moved, with no shim, since underscore names carry no compatibility promise. Rename _default_run_id, _default_conversation_id, _run_clock and _run_start_time overrides to get_default_run_id, get_default_conversation_id, get_run_clock and get_run_start_time; move _*_parameter_transport and _prepare_function_call_params overrides to a ParameterTransports subclass passed to the backend; delete _validation_context overrides.
PR decisions
2026-10-22 · pre-push review 1 of 3 at b76cbc8a047c342665719128364b3f890003fb27 · iter -
- Decision: reserved; dispatching
- Why: tree a63a9a1cbf86c09f08f683bfc288ea0cfb463d53; scope a62610dc2f..b76cbc8a04 (full branch); first review
- Source: https://github.com/pydantic/pydantic-ai/tree/durable-exec-public-builder-api
2026-10-22 · pre-push review 1 of 3 at b76cbc8a047c342665719128364b3f890003fb27 · iter -
- Decision: remediated: transports moved from private BaseDurabilityCapability hooks to a public ParameterTransports on the backend (Douwe's call); DurableRunContext gets public unavailable_field_message and restore(rebuild_validation_context=); docs wording on RunContext field names
- Why: 3 findings: private hooks documented as contract; no public validation_context restore; inaccurate docs sentence
- Source: https://github.com/pydantic/pydantic-ai/tree/durable-exec-public-builder-api
2026-10-22 · parameter transports live on the backend, not the capability · iter -
- Decision: Public ParameterTransports (identity defaults) on DurableOperationBackend.parameter_transports; RegisteredOperationBackend takes parameter_transports=; the 12 private _*_parameter_transport hooks on BaseDurabilityCapability are removed
- Why: Douwe (in session, 2026-10-22): no private hooks on the durability capability; the spec is a frozen ClassVar and can't hold per-instance transport state
- Source: https://github.com/pydantic/pydantic-ai/issues/4764
2026-10-22 · pre-push review 2 of 3 at d51b2a1c9fb07e90c15b088ddc5ede7dd017fbba · iter -
- Decision: reserved; dispatching
- Why: tree b1d11da8ac0a82359e2e7ef8edcf522bc273b8b7; scope b76cbc8a04..d51b2a1c9fb07e90c15b088ddc5ede7dd017fbba (follow-up) + full branch as context
- Source: https://github.com/pydantic/pydantic-ai/tree/durable-exec-public-builder-api
2026-10-22 · pre-push review 2 of 3 at d51b2a1c9fb07e90c15b088ddc5ede7dd017fbba · iter -
- Decision: remediated at 46e62ab8d5cc9a44dba70dbef09650ff20744bff: DynamicToolset imported from public pydantic_ai.toolsets (3 files); prior findings a-c verified fixed
- Why: 1 finding: private toolsets._dynamic import
- Source: https://github.com/pydantic/pydantic-ai/tree/durable-exec-public-builder-api
2026-10-22 · exempt delta d51b2a1c9f..46e62ab8d5cc9a44dba70dbef09650ff20744bff (chains from reviewed d51b2a1c9f) · iter -
- Decision: no re-review: import-path-only change applying review 2's exact fix
- Why: Rubric rungs: public API - annotations name the same class object, no signature change; behavior - DynamicToolset is the same object re-exported, one import is TYPE_CHECKING-only; tests/docs untouched. Render tests + pyright rerun clean
- Source: https://github.com/pydantic/pydantic-ai/tree/durable-exec-public-builder-api
2026-10-22 · pre-push review 3 of 3 at dc8d091a15b1bf585c6ded3c291a8a8080cb08ca · iter -
- Decision: reserved; dispatching
- Why: tree 7150f212196cb8ea6e24841027825faf2e1c53d8; follow-up scope: d51b2a1c9f..HEAD (commits 46e62ab8d5, merge 006574ab57 conflict resolution, dc8d091a15) with full branch 97658483119a3f2996e3d74f273fd68a2adaa376..HEAD as context
- Source: https://github.com/pydantic/pydantic-ai/pull/11088
2026-10-22 · pre-push review 3 of 3 at dc8d091a15b1bf585c6ded3c291a8a8080cb08ca · iter -
- Decision: remediated at da4469dc82c70c366d585273a36d087f9e8bea59: agent-less validation_context stays guarded (unit_validation_context for arg validation), Temporal docs + docstring + capabilities AGENTS.md updated; plus fb154cc8e0 CI pyright fix (deserialize_run_context return types). Budget exhausted; no fourth review
- Why: 3 findings: agent-less None broke guard contract; stale Temporal docs; stale AGENTS.md path
- Source: https://github.com/pydantic/pydantic-ai/pull/11088
2026-10-23 · post-budget delta: main merge 72c24d93ab + API allowlist entry · iter -
- Decision: Allowlisted Griffe false positive on TemporalDurability.engine_spec (same value, now TEMPORAL_ENGINE_SPEC constant) against v2.60.0; merged main with only the allowlist file conflicting (took main's, re-added entry)
- Why: Review budget exhausted; delta is a target-branch merge plus machine-consumed allowlist data, verified by running check_api_compatibility.py --against v2.60.0 locally (0 errors)
- Source: https://github.com/pydantic/pydantic-ai/pull/11088
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
- PR title is fit for the release changelog.
🤖 Generated with Claude Code