Match DBOS child workflows to their tool calls by a stable ID on recovery
Closes #12290
Needs Aditya's review (@adtyavrdhn): core durable-execution change (durable_exec/dbos).
Why. DBOS matches a child workflow to the step position it started at. When parallel child_workflow tool calls start their children in a different order on recovery, a call gets another call's child, so its result or its error goes to the wrong call. The new tests reproduce this on main. Per the maintainer's scope update, each child now gets an ID derived from the parent workflow, the run and the tool call. On recovery, each call takes the step position of its own recorded child.
New public surface: none.
Behavior (DBOSDurability, tools with {'dbos': {'child_workflow': ...}}):
pydantic_ai_slim/pydantic_ai/durable_exec/dbos/_durability.py :: call_tool_operation()
-└─ call_tool_workflow(...) # child ID `{parent}-{step}`, whichever child is recorded at the step it reaches
+└─ _call_child_workflow(...)
+ ├─ wait while the next step position holds another call's child (as recorded before this execution)
+ └─ SetWorkflowID(f'{parent}-{run_id}-{run_step}-{execution}-{tool_call_id}') + call_tool_workflow(...)
Verification (tests/durable_exec/test_dbos.py):
test_dbos_child_workflows_keep_their_tool_calls_when_starts_reordercovers a crash after both children start, the same with a failing child, and a crash before the second child starts. Recovery reorders the calls withasyncio.Events. All three fail onmainwith swapped or duplicated results. Here each call gets its own result, every step recorded before the crash is unchanged, and both children are linked to the parent.test_dbos_child_workflow_tool_survives_recovery[positional_child_id]simulates a child started before this change. Recovery reuses it instead of running it again.test_dbos_child_workflow_tool_executed_again_by_capabilitychecks that awrap_tool_executethat callshandler()twice gets a fresh child each time.test_dbos_child_workflow_tools_run_in_parallel_with_a_workspace(intest_dbos_workspace.py) now names the children by tool call.- The full DBOS suite passes, as do the determinism and contract-manifest tests. Pyright and ruff are clean on the touched files.
What changes for existing users: Child workflows get derived IDs instead of {parent}-{n}. A recovered run's tool calls get their own children's results. Workflows in flight across the upgrade keep their positional matching.
Choices made:
- The ID includes the run step, so tool call IDs reused across steps can't collide. It also has an execution count, placed before the tool call ID, so a capability that runs a tool call again gets a fresh child without aliasing another call's ID.
- Ordering, not by-ID reads: every execution uses the same positions, one child start and
getResultpair per call, and every child stays linked to its parent. A call waits only on recovery, and only for a sibling that is about to take its own position. - To find the recorded child at the next step, the code reads DBOS's private
get_local_dbos_context().function_id, which this file already uses inget_default_run_id. It also does one unrecordedlist_workflow_stepsper workflow execution, in an emptycontextvars.Context(), because DBOS has no public unrecorded read from workflow code. - Out of scope: keeping tool calls parallel when a workspace is attached (workspace ops recorded by tool call ID). The maintainer allowed it as a follow-up, so the current sequential fallback stays.
- The
Run benchmarksfailure comes frommain(#13866). The fix is in #13899.
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.