Make the durable engine extension surface public: operation types, `ParameterTransports`, `DurableRunContext` and run identity hooks

Merged
DO
1mo ago
+1239-822

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, with serialize_run_context, deserialize_run_context, unavailable_field_message, and the new restore(serialized, *, deps, agent, engine_spec). It rebuilds validation_context from the agent the first time it's read. TemporalRunContext now subclasses it.
  • ParameterTransports: one method per operation kind, each passing parameters through unchanged by default, plus an async prepare_function_call. Backends expose it as DurableOperationBackend.parameter_transports, and RegisteredOperationBackend(parameter_transports=...) accepts one. revalidate_function_call is 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_id and 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

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 -

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 -

2026-10-22 · pre-push review 2 of 3 at d51b2a1c9fb07e90c15b088ddc5ede7dd017fbba · iter -

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 -

2026-10-22 · pre-push review 3 of 3 at dc8d091a15b1bf585c6ded3c291a8a8080cb08ca · iter -

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