Use public `DBOS.reserve_step` for DBOS event-handler step reservations on `dbos>=3.4.0`

Merged
DS
1mo ago
+45-27

This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.

Follow-up to #11157; no issue closes.

Why we make these changes

#11157 reserves a DBOS step id when a tool calls ctx.emit(), then runs the event-handler step at that id later from the stream consumer. DBOS had no public API for this, so it used private internals (dbos._context.snapshot_step_context, dbos._core.run_step_async, dbos._dbos._get_dbos_instance). dbos 3.4.0 adds the public DBOS.reserve_step / StepReservation for exactly this (dbos-inc/dbos-transact-py#918, requested in #915).

  • DBOSDurability reserves with DBOS.reserve_step() when dbos has it and runs the handler step through StepReservation.run_async.
  • On dbos 2.10–3.3 the floor stays dbos>=2.10.0: the private SnapshotStepReservation keeps the old path behind the same run_async shape, with a TODO(v3) beside the existing dbos one in pyproject.toml.

StepReservation.run_async also calls DBOS._configure_asyncio_thread_pool(). DBOS.run_step_async, which get_run_start_time calls at every durable run start, already makes that call.

Scope boundary: the other private dbos uses stay as they are — get_default_run_id via dbos._context.get_local_dbos_context, and the dbos._error imports. dbos 3.4.0 exports neither from dbos.

New public surface

none

Verification

What changes for existing users

Nothing: the same step ids are recorded and replayed, so workflows recorded before this change replay unchanged.

PR decisions

2026-11-01 · Extract #11157 local notes under local-notes/pr11157 · iter -

  • Decision: Repro probes and stress probe live at local-notes/pr11157/local-notes/; run from there for step 4.
  • Why: Dispatch step 0 asked to extract the archived tarball into this worktree's local-notes.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11157
  • Session: e67554bd-2d3e-4bbb-954f-cfd1d853ee7c

2026-11-01 · Older dbos: version-gated fallback, keep dbos>=2.10.0 · iter -

2026-11-01 · Wait for exclude-newer window before locking dbos 3.4.0 · iter -

  • Decision: Do not touch [tool.uv.exclude-newer-package]; lock dbos 3.4.0 after 2026-11-04T15:25Z and open the PR only then.
  • Why: That table's comment reserves it for our own packages; without 3.4.0 in uv.lock the locked CI leg cannot cover the reserve_step path. Decided by David via manager dispatch local-notes/dispatch-20261101T172238Z.md.
  • Source: https://pypi.org/project/dbos/3.4.0/
  • Session: e67554bd-2d3e-4bbb-954f-cfd1d853ee7c

2026-11-01 · pre-push review 1 of 3 at a0e0fbc3e4049ca633e4654d3977177c47384890 · iter -

2026-11-01 · pre-push review 1 outcome at a0e0fbc3e4049ca633e4654d3977177c47384890 · iter -

  • Decision: Remediated: moved the dbos>=3.4.0 TODO(v3) directly after the existing dbos TODO(v3) in root pyproject.toml. Dismissed: _configure_asyncio_thread_pool/_claim concern (idempotent and already called via DBOS.run_step_async in get_run_start_time; reservations popped once and run from the reserving workflow's code; 3.4.0 tests and repros pass) — note the added call in the PR body. Skipped: 3.4 branch uncovered by CI until the settled lock bump.
  • Why: Reviewer findings 1-3 triaged against dbos 3.4.0 source (dbos/_dbos.py StepReservation._claim, DBOS._configure_asyncio_thread_pool).
  • Source: https://github.com/dbos-inc/dbos-transact-py/pull/918
  • Session: e67554bd-2d3e-4bbb-954f-cfd1d853ee7c

2026-11-01 · exempt delta at ac5d10aa8b023a641ba7585079aa2062b271c245 chains from reviewed a0e0fbc3e4049ca633e4654d3977177c47384890 · iter -

2026-11-04 · exempt delta at 61644263c chains from reviewed a0e0fbc3e4049ca633e4654d3977177c47384890 · iter -

2026-11-04 · pre-push review 2 of 3 at 5e146e4a1c1f092d295ebe61152627a748dee81e · iter -

2026-11-04 · pre-push review 2 outcome at 5e146e4a1c1f092d295ebe61152627a748dee81e · iter -

  • Decision: Dismissed both findings with evidence; no code change. (1) SnapshotStepReservation assert on snapshot_step_context(): unreachable — it is built only under in_durable_context (DBOS.workflow_id not None, so a local DBOS context exists), and snapshot_step_context returns ctx.snapshot_step_ctx() or ctx, never None, in dbos 2.10.0, 2.29.0 and 3.3.0; DBOS.reserve_step raises under the same precondition. (2) StepReservation.run_async signature: dbos 3.4.0 is run_async(dbos_step_options, func, *args, **kwargs), matching call_reserved; pyright passes on 3.4.0.
  • Why: First launch at this reservation never ran (CLI swallowed the prompt); the relaunch is review 2. Post-merge: targeted suites pass, #10300 repros and stress probe journals identical on dbos 3.4.0.
  • Source: https://github.com/dbos-inc/dbos-transact-py/pull/918
  • Session: 67c4f548-17e5-45ad-a173-eb10e5d8679c

2026-11-04 · Split the dbos 3 migration into its own PR; hold #12555 · iter -

  • Decision: A separate worker in worktree dbos-3-migration opens the dbos 3 PR: lock dbos 3.4.0, migrate the 18 run_admin_server test configs to work on dbos 2.10 and 3.x, fix docs/production.md DBOS(fastapi=...). #12555 pushes nothing until it merges, then merges upstream/main (lock bump drops out) and runs its lifecycle; add a 'depends on' line to the body once the manager sends the PR number.
  • Why: Decided by David via the manager, 2026-11-04: one purpose per PR, the docs crash gets its own fix, and #12555's CI keeps covering DBOS.reserve_step.
  • Source: https://github.com/pydantic/pydantic-ai/actions/runs/41924384317 ; local-notes/dispatch-20261104T224216Z.md
  • Session: 67c4f548-17e5-45ad-a173-eb10e5d8679c

2026-11-04 · Verify the dbos 2.10.0 fallback-coverage claim on resume · iter -

  • Decision: After #12568 merges and main is merged: run the lowest resolution as CI's test-durable-exec leg installs it, find which tests exercise SnapshotStepReservation on dbos 2.10.0, and make the body's verification line say exactly that; if no test covers the fallback on 2.10.0, report to the manager before pushing.
  • Why: Unverified report from the dbos-3-migration worker via the manager: tests/durable_exec/test_dbos.py imports dbos._serialization.DBOSDefaultSerializer (absent in 2.10.0), so its except ImportError skips the whole module on the lowest leg, already on main; the body's claim that the 3.12 lowest leg covers the fallback may be false.
  • Source: https://github.com/pydantic/pydantic-ai/pull/12568 ; local-notes/dispatch-20261104T234144Z.md
  • Session: 67c4f548-17e5-45ad-a173-eb10e5d8679c

2026-11-05 · exempt delta at 3af2b02060 chains from reviewed 5e146e4a1c1f092d295ebe61152627a748dee81e · iter -

  • Decision: Clean upstream/main merge after #12568 (05d21dbdf) landed; the lock bump drops out of the branch diff; no re-review.
  • Why: Exempt row 'Target-branch merge with no conflict resolution': the merge resolved no conflict; git diff upstream/main...HEAD equals git diff upstream/main...5e146e4a1 minus uv.lock (blob hashes and hunk offsets aside), and HEAD's uv.lock equals main's (dbos 3.4.0). On dbos 3.4.0 pyright on _durability.py and _operation_backend.py reports 0 errors and the three targeted suites pass (295 passed; a first run under machine load timed out four MCP initialize handshakes in test_dbos.py, unrelated to reservations, and passed on retry).
  • Source: https://github.com/pydantic/pydantic-ai/pull/12568
  • Session: 969eca25-0b33-4dc9-b42c-f3785cdc073c

2026-11-05 · dbos 2.10.0 fallback coverage verified at 3af2b02060 · iter -

  • Decision: SnapshotStepReservation is covered on dbos 2.10.0: test_dbos_parallel_immediate_events_keep_emission_step_order, test_dbos_mixed_dispatch_events_keep_emission_step_order, test_dbos_immediate_events_then_durable_steps_fork_every_step, test_dbos_parent_emit_inside_nested_run_keeps_own_reservation and test_dbos_emitted_events_precede_tool_steps_on_replay (8 cases) cover all of its lines; the body's verification line names them.
  • Why: Local run as CI's test-durable-exec lowest leg installs it (uv sync --all-packages --all-extras --no-extra mcp-tasks --resolution lowest-direct, Python 3.12, dbos 2.10.0): the DBOS files of tests/durable_exec plus the harness step-persistence suite give 516 passed, 4 skipped, and _operation_backend.py 100% line and branch coverage; those five tests alone leave no SnapshotStepReservation or call_reserved line missing. #12568 made test_dbos.py import on 2.10.0, so the module-level skip the worker reported no longer applies.
  • Source: https://github.com/pydantic/pydantic-ai/pull/12568
  • Session: 969eca25-0b33-4dc9-b42c-f3785cdc073c

2026-11-05 · douwebot review 5786391925 triage at 3af2b02060 · iter -

  • Decision: pyproject.toml TODO placement (4481578336): do — moved the dbos>=3.4.0 TODO(v3) above the DBOS LoggingHandler comment block so that block sits directly over its filter; kept it in pyproject.toml beside the dbos>=2.31.0 TODO(v3), since dropping it would reverse the settled 'Older dbos' decision. Module-level reserve_step selection (4481578347): skip, net-neutral — hasattr(DBOS, 'reserve_step') costs ~43 ns per emission, and the v3 cleanup touches _durability.py either way because SnapshotStepReservation types _event_step_reservations there.
  • Why: Douwebot APPROVE with two Optional comments; the merge bar needs a clean approval on a head with no douwebot comments. Timing: timeit on dbos 3.4.0; reference: _durability.py _event_step_reservations annotation.
  • Source: https://github.com/pydantic/pydantic-ai/pull/12555#pullrequestreview-5786391925
  • Session: 969eca25-0b33-4dc9-b42c-f3785cdc073c

2026-11-05 · exempt delta at 26cec22ce chains from reviewed 5e146e4a1c1f092d295ebe61152627a748dee81e · iter -

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.