Keep default `run_id` and `conversation_id` stable when a durable run is re-executed
- Closes #8825
Why
Inside a Temporal workflow, DBOS workflow or Prefect flow, an agent run without run_id= minted a fresh UUID7 every time the engine re-executed the workflow code. One run could then show several ids: one per tool activity, plus another on result.run_id. Anything keyed on ctx.run_id lost track of the run, for example StepPersistence (12 events written under 12 run ids). conversation_id drifted the same way when there was no history to inherit it from.
#6492 already added replay-stable default run ids for each engine, but used them only when the agent had a workspace. This PR uses them for every run under the built-in engines, which also derive the default conversation_id from the run id. A durability capability built on the public BaseDurabilityCapability supplies neither, so its runs keep UUID7 defaults.
[!WARNING]
Compatibility impact: Inside a durable workflow or flow, the default run_id is no longer a UUID7 but an engine-derived string (e.g. <temporal run id>:<uuid4>, <dbos workflow id>:<step>, with a :<n> suffix for runs started concurrently, <prefect flow run id>:<n>). The default conversation_id becomes a UUID5. Code that parses these defaults as UUID7 will break.
Why this can ship in a minor release: It's a bug fix. Per-attempt ids under durable execution were the bug, and no documented guarantee covered the id format beyond "unique".
Migration: To control the format, pass run_id= / conversation_id= explicitly.
New public surface
None. The hooks (_default_run_id, _default_conversation_id) are private.
User-visible behavior
agent/__init__.py :: Agent.iter()
└─ capabilities/combined.py :: CombinedCapability._default_run_id()
- └─ (only if a capability supplies `get_workspace`) durable_exec/<engine>/_durability.py :: <Engine>Durability._default_run_id()
+ └─ durable_exec/<engine>/_durability.py :: <Engine>Durability._default_run_id() -> replay-stable id inside a workflow/flow
+ └─ capabilities/combined.py :: CombinedCapability._default_conversation_id(run_id)
+ └─ durable_exec/<engine>/_durability.py :: <Engine>Durability._default_conversation_id(run_id)
+ └─ durable_exec/_base.py :: conversation_id_from_run_id() -> uuid5(namespace, run_id)
- └─ _agent_graph.py :: resolve_conversation_id(...)
+ └─ _agent_graph.py :: resolve_conversation_id(..., default=...)
On Temporal, the extra workflow.uuid4() draw sits behind workflow.patched('pydantic_ai:stable_default_run_id'), so histories recorded before this change replay without the draw and keep their random sequence. Agents that already drew (a workspace on the root, with TemporalDurability directly in the agent's capabilities) keep drawing without the patch. WrapperCapability now forwards both hooks, so a wrapped durability capability supplies the defaults too.
Verification
tests/durable_exec/temporal/test_durability.py::test_durability_default_ids_survive_replay: the issue's repro (max_cached_workflows=0, two tool activities) gets the same ids in each activity and in the result.tests/durable_exec/temporal/test_durability.py::test_durability_replays_history_recorded_before_stable_default_ids: a history recorded without the patch marker replays cleanly, and the workflow's nextworkflow.uuid4()draw matches the recorded one.tests/durable_exec/temporal/test_workspace.py::test_workspace_runs_draw_their_run_id_without_the_stable_id_patch: workspace runs draw without recording a patch marker, so their older histories replay unchanged.tests/durable_exec/test_dbos.py::test_dbos_default_ids_survive_recovery: a crashed (PENDING) workflow keeps its ids after recovery, including two runs started withasyncio.gather, which now get distinct ids (<step>and<step>:1).tests/durable_exec/test_prefect_workspace.py::test_prefect_default_ids_without_a_workspace_survive_a_flow_retry: replaces the test that asserted fresh UUID7s across a retry.tests/durable_exec/test_prefect_workspace.py::test_prefect_default_ids_reach_through_a_wrapped_durability_capabilitytests/durable_exec/test_durable_workspace.py::test_an_engine_without_default_ids_keeps_fresh_uuid7s: a durability capability on the public base keeps UUID7 defaults.
What changes for existing users
Durable runs without explicit ids under Temporal, DBOS or Prefect now get the same run_id and conversation_id on every re-execution. Nothing changes outside durable execution.
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