Add a run-level in-flight work registry, `RunContext.in_flight`, that runs wait for before ending
Part of #13202: this is PR 1 of its plan. The issue stays open for the follow-up PRs, starting with moving BackgroundTools onto the registry.
Why. Tools and capabilities start work that finishes after the step that started it, such as background tools and sub-agent tasks. Today each producer decides at its own seam whether the run waits for that work, and none can wait at a deferred pause. This PR adds one run-level registry, ctx.in_flight, with one end rule that every producer and engine shares, and one event that UIs can read.
On 11/25 Douwe approved this shape: ctx.in_flight.start(fn, kind='background_tool', ..., on_end='drain'|'cancel'), with on_end='drain' as the default. A durable suspend drains the run's own background work or cancels it. register() keeps 'detach' for work in resources that outlive the run, such as shell jobs, kept sandboxes and app-owned tasks, per his 11/11 ruling on #13202.
New public surface. RunContext.in_flight and the pydantic_ai.in_flight module: InFlightRegistry (start, register, settle, live, wait_idle), InFlightWork, InFlightOnEnd, InFlightWorkState, InFlightWorkPhase and InFlightWorkSnapshot. InFlightWorkEvent is also exported from pydantic_ai.
Behaviour.
- When the run ends with output, it waits for
'drain'work until that work has queued content or finished, and the model then gets a turn on what was queued. At aDeferredToolRequestsorPendingModelResponsepause, it waits for all'drain'work. Errors, cancellation, timeouts and usage limits cancel everything except'detach'work. - In durable runs,
ctx.in_flightis accepted in workflow and flow code on Temporal, Prefect, Azure Durable Task and Render. It is refused, with aUserErrorthat names the engine, on DBOS, AWS Lambda, Absurd and pgtask, in every mode, until #14500 lands. The refusal comes from one rule: an engine that identifies recorded units by start order, which a private engine-spec flag marks, refuses it. That flag is set on all four engines, and on those engines recovery could hand the work and the run each other's recorded results. A sequential tool-execution mode doesn't refuse it by itself: a user who chooses sequential mode on Temporal, Prefect, Azure Durable Task or Render can still usectx.in_flight. On Lambda, Absurd and pgtask a suspend also ends the run (#14493). It still raises inside activities, steps and tasks. - A wait for an external event that the engine records, reached from a
handle_deferred_tool_callshook (HandleDeferredToolCalls,AskUser), applieson_end:'cancel'work is cancelled before the wait.'drain'work runs alongside the wait, and the wait returns only once that work has finished. Work that is itself in such a wait, together with the work that started it, is excluded, so sibling pieces don't wait for each other.'detach'work is left alone.- Engines whose waiter refuses the wait still raise, after the cancel.
- The logic is generic: it uses the run's parallel execution mode and whichever waiter is installed. There are no engine-name checks and no new spec field, and the public
ExternalEventWaitercontract is unchanged.
Verification.
tests/test_in_flight.py: end rule, pauses, cancellation, and durable waits through an engine-styleExternalEventWaiter(cancel first, drain after, self- and nested-waits, failing cancel callback, eager task factory).- Temporal waits and end rule:
'cancel'then'drain'around an approval, the end-of-run drain across a model activity, and history replay. - Temporal, DBOS and Prefect: accepted in workflow and flow code, refused inside units. AWS Lambda: refused.
What changes for existing users. Nothing: no producer uses the registry yet.
Follow-ups. Entering a durable wait doesn't call _notify(). Work already sitting in another wait's drain loop only re-checks on its next change, which can make it wait longer than it needs to, though it can't deadlock (noted in the durable sign-off).
PR decisions
2026-11-11 · Registry owns asyncio tasks, not an anyio TaskGroup around the run · iter -
- Decision: start() creates tasks the registry holds; run teardown cancels non-detached work and waits for it in a shielded scope
- Why: anyio 4.15 TaskGroup.aexit wraps a host-body exception in BaseExceptionGroup and adds a checkpoint even with no children, which would change every run's error type and timing for users who register nothing; concurrency.md allows create_task when the owner cancels and drains at teardown
- Source: https://github.com/pydantic/pydantic-ai/issues/13202#issuecomment-6809779685
2026-11-11 · start() takes on_end drain or cancel only · iter -
- Decision: detach is only for register(); start(on_end='detach') raises UserError
- Why: the run owns the tasks it starts and must stop them by teardown; work built to outlive the run (shell jobs, after_run compaction) is owned elsewhere and registers
- Source: https://github.com/pydantic/pydantic-ai/tree/in-flight-registry
2026-11-11 · Errors of started work end the run; registered errors don't · iter -
- Decision: An exception escaping a start()ed coroutine is raised at the next step boundary (and while the end rule waits); settle(error=) only records state
- Why: design section 2 (as BackgroundTools._deliver does); producers convert errors the model should hear about; registered work's producer owns its failure handling
- Source: https://github.com/pydantic/pydantic-ai/tree/in-flight-registry
2026-11-11 · Base on main, not #13054 · iter -
- Decision: End rule waits before main's drain; the pause stands for the mixed-step deferred shape on main, and for all-deferred and PendingModelResponse pauses once #13054 lands
- Why: #13054 owns the core pause semantics in _pending_messages.py/_enqueue.py; this PR doesn't touch them, so the two don't conflict
- Source: https://github.com/pydantic/pydantic-ai/pull/13054
2026-11-11 · pre-push review 1 of 3 at 8a38827da62c09c7f082b859c7f77266080f02e1 · iter -
- Decision: reserved; dispatched
- Why: tree 2cf614f3be9277ae4df78937c8252692d192a6a2; scope a52da278a9..8a38827da6 full branch; first review; policy-base 03fd4e3c91
- Source: https://github.com/pydantic/pydantic-ai/tree/in-flight-registry
2026-11-12 · register() defaults to on_end=detach · iter -
- Decision: Douwe: "detach" applies to any work that lives in a persistent resource that outlives the run; drain = result belongs to this run; cancel = best-effort work worthless after the run. register() defaults to detach (overridable); start() keeps drain
- Why: maintainer decision recorded on the issue
- Source: https://github.com/pydantic/pydantic-ai/issues/13202
2026-11-12 · pre-push review 1 of 3 at 8a38827da62c09c7f082b859c7f77266080f02e1 · iter -
- Decision: remediated in 185b6b82bf: pause docs defer to message-history for queued content at a pause, no longer claim recording (#1 docs part); register()/settle() require the event loop with a UserError, tested from a sync tool and a thread (#3); error docs say hooks miss it and post-last-step errors are not raised (#4); no_leaked_tasks + run_stream_events test (#5 partial); example id uses tool_call_id (#6). Open for maintainer: #1 waiting at all-deferred/PendingModelResponse pauses on main redirects until #13054 lands; #2 wake on enqueue vs first settle (kept: maintainer ruled first result). Declined: #7 top-level export (not needed for PR 1); #5 toolset-order and run_stream tests (noted as limitations)
- Why: reviewed tree 2cf614f3be9277ae4df78937c8252692d192a6a2
- Source: https://github.com/pydantic/pydantic-ai/tree/in-flight-registry
2026-11-12 · pre-push review 2 of 3 at 185b6b82bf · iter -
- Decision: reserved; dispatched
- Why: tree d64a027defb21041f9feea394ffa3da3e0c9d2bd; follow-up scope 8a38827da6..185b6b82bf plus prior findings
- Source: https://github.com/pydantic/pydantic-ai/tree/in-flight-registry
2026-11-12 · pre-push review 2 of 3 at 185b6b82bf · iter -
- Decision: remediated in 40b6f2f053: wait_idle docs exclude detach; message-history points to start(); _after_step docstring no longer claims recording; InFlightOnEnd docstring lists usage limits. Prior #1/#2/#5-partial/#7 remain as open questions/limitations for the maintainer. Budget: one review left, not dispatched (wording-only delta, docstrings + docs prose)
- Why: reviewed tree d64a027defb21041f9feea394ffa3da3e0c9d2bd
- Source: https://github.com/pydantic/pydantic-ai/tree/in-flight-registry
2026-11-12 · pre-push review 3 of 3 at 40b6f2f053 · iter -
- Decision: reserved; dispatched
- Why: tree 5ca146e94ce2cbaf3f78bf03cdf0ef2dcdabf29d; follow-up scope 185b6b82bf..40b6f2f053 plus review-2 findings
- Source: https://github.com/pydantic/pydantic-ai/tree/in-flight-registry
2026-11-12 · pre-push review 3 of 3 at 40b6f2f053 · iter -
- Decision: no findings
- Why: reviewed tree 5ca146e94ce2cbaf3f78bf03cdf0ef2dcdabf29d; budget spent
- Source: https://github.com/pydantic/pydantic-ai/tree/in-flight-registry
2026-11-12 · CI on 40b6f2f053: pyright, a streaming test, stale contract manifest · iter -
- Decision: remediated in 570bbe86c6: start() checks on_end through a str copy so pyright keeps the Literal; tests annotate tools with bare RunContext; event-stream test uses TestModel (FunctionModel can't stream); manifest gains RunContext._in_flight with the same three DurableRunContext sites as every other guarded field. Review budget spent; pushed after ruff + pre-commit
- Why: CI run 43125267634
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · CI on 570bbe86c6: pyright widened InFlightWork.on_end to str · iter -
- Decision: remediated in d7109d152b: annotate the attribute; the str-copy workaround in start() reverted (it targeted the wrong line)
- Why: CI run 43126626150 quality checks
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · CI on d7109d152b: coverage gaps in tests; Pyright time budget · iter -
- Decision: remediated in b399aca966: test waits for the slow task to start before cancelling; thread-test tool returns None. Pyright passed with 0 errors at 289.2s vs the 280s budget; other PRs' same step took 276-312s in the same window, so treated as runner variance
- Why: CI run 43127756635 coverage and quality checks
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · Land PR 2 after #13054 · iter -
- Decision: PR 2 (BackgroundTools on the registry) lands after #13054, so pauses stand in the all-deferred and PendingModelResponse shapes
- Why: cluster owner answer on #13217 (Douwe delegated)
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · Plain-end wait wakes on settle or queued content · iter -
- Decision: in ace4a292ee: the wait wakes on whichever comes first, a drain item settling or content arriving in the pending-message queue (PendingMessageQueue.notifying listener, call_soon_threadsafe), so work that queues a result and keeps running does not hold back the model turn
- Why: cluster owner answer on #13217, matching the design ("has queued something")
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · Keep asyncio for start(); agent runs do not support Trio · iter -
- Decision: No Trio path for ctx.in_flight: agent runs themselves need asyncio (agent/init.py _run_lifecycle_hooks uses asyncio.create_task for the ready waiter and _utils.ScopedTask; _tool_execution.py runs every tool call via asyncio.create_task); Trio tests only cover standalone primitives (wait_for_external_event from #12757, provider entry) and timeout= raising before a run starts
- Why: cluster owner asked to check Trio support for runs before accepting asyncio tasks
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · Export InFlightWorkEvent from pydantic_ai · iter -
- Decision: in ace4a292ee: top-level export next to EnqueuedMessagesEvent, as core stream events are; run_stream() not waiting after its final output stays documented in custom.md
- Why: cluster owner answer on #13217
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · CI on ace4a292ee: contextmanager Iterator annotation deprecated · iter -
- Decision: remediated in 0c94a57489: Generator[None] return type; tests and 100% coverage already passed on ace4a292ee
- Why: CI run 43132032237 quality checks (reportDeprecated)
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · douwebot review at 0c94a57489: plain-end wait wording · iter -
- Decision: remediated in 2d5c61f35d: docs/docstring/skill say the wait lasts until content is queued or all draining work has finished (code unchanged: a silent settle only wakes the wait, so live drain work is not cancelled); span until=queued; test for a piece settling without queuing while another drains
- Why: douwebot finding, valid
- Source: https://github.com/pydantic/pydantic-ai/pull/13217#discussion_r4545223287
2026-11-12 · douwebot review at 2d5c61f35d: run_stream() and the end rule · iter -
- Decision: remediated in 4abd2b3a2e: run_stream() does reach _after_step through SetFinalResult, so it waits; docs now say it waits but delivers nothing (matching BackgroundTools documented run_stream behaviour), with a test
- Why: douwebot finding, valid
- Source: https://github.com/pydantic/pydantic-ai/pull/13217#discussion_r4545283299
2026-11-12 · douwebot optional: durable flag unused in PR 1 · iter -
- Decision: kept (part of the settled API on #13202; PR 4 gives it behaviour); docstrings now say the run does not act on it yet
- Why: settled design decision lists durable on handles and start/register
- Source: https://github.com/pydantic/pydantic-ai/pull/13217#discussion_r4545283303
2026-11-12 · douwebot optional: wait_idle/wait from the work itself · iter -
- Decision: documented rather than special-cased: wait() and wait_idle() docstrings say started work waiting for itself never returns, and wait_idle(kind=) can exclude it
- Why: no producer does this in PR 1; excluding the current task needs task bookkeeping the registry doesnt otherwise keep
- Source: https://github.com/pydantic/pydantic-ai/pull/13217#discussion_r4545283313
2026-11-12 · douwebot review at 4abd2b3a2e: call_soon_threadsafe on Temporal workflow loop · iter -
- Decision: remediated in dda9f70687: listener notifies directly on the loop thread and uses call_soon_threadsafe only from other threads (verified temporalio _WorkflowInstanceImpl defines call_soon but not call_soon_threadsafe); the partial-result test now enqueues from a worker thread to cover that branch. Temporal workflow test deferred to PR 5 (per-engine tests in the plan)
- Why: douwebot finding, valid
- Source: https://github.com/pydantic/pydantic-ai/pull/13217#discussion_r4545330571
2026-11-12 · CI on dda9f70687: event order after direct wakes · iter -
- Decision: fixed in a209f0b817: on the loop thread the wait now wakes when content is queued, before the queuing work finishes, so drained precedes that work settled; four tests expected the old order
- Why: CI run on dda9f70687 test jobs
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · douwebot review at dda9f70687: Temporal page and link style · iter -
- Decision: fixed in a209f0b817: temporal.md lists ctx.in_flight among members that raise in an activity; custom.md uses reference-style links for ctx.enqueue, DeferredToolRequests and PendingModelResponse
- Why: douwebot findings, valid
- Source: https://github.com/pydantic/pydantic-ai/pull/13217#discussion_r4545366069
2026-11-12 · douwebot review at a209f0b817: failing cancel callback at teardown · iter -
- Decision: fixed in 473d6bd97d: InFlightWork.cancel() settles in a finally; _aclose cancels every handle, waits for all, then raises the first callback error; regression test with no_leaked_tasks
- Why: douwebot finding, valid
- Source: https://github.com/pydantic/pydantic-ai/pull/13217#discussion_r4545516700
2026-11-12 · CI on 473d6bd97d: Pyright time budget · iter -
- Decision: reran failed jobs: Pyright passed with 0 errors in 287.7s vs the 280s budget; main pushes took 275-304s on the same step this hour, so runner variance
- Why: CI run 43142682431
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · Durable review at 473d6bd97d: blocking items · iter -
- Decision: fixed in 0f04d3bcc0: (1) _notify_from compares asyncio.get_running_loop() is loop, no-loop threads use call_soon_threadsafe; (2) in_flight drain span via _durable_replay.start_as_current_span; (3) ctx.in_flight raises a UserError when ctx.in_durable_context is set, documented in custom.md and the skill reference. Activity guard message drops its now-wrong advice to use workflow-level code
- Why: Douwe durable-exec review
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · Temporal drain-across-activity test moves to the suspend-rule PR · iter -
- Decision: Option A: raise in every durable context for PR 1; the Temporal test for item 1 is replaced by real Temporal (workflow code + activity) and DBOS (function tool in workflow code + dynamic-toolset step) tests that ctx.in_flight raises; the drain-across-activity test lands with PR 4
- Why: item 3 makes workflow-side registration impossible, so item 1s test cannot be built; cluster owner chose A
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · Durable review non-blocking items · iter -
- Decision: in 0f04d3bcc0: in_flight.py added to test_workflow_side_determinism module set; real-engine Temporal and DBOS tests added
- Why: Douwe durable-exec review
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · douwebot/PR Review Checks at 0f04d3bcc0 · iter -
- Decision: fixed in ef424c66ea: handles annotated InFlightWork[None] (Any kept where start(asyncio.Event().wait)); Prefect flow-code + task guard test; off-asyncio backends get a requires-asyncio UserError (tested on Trio); docs scope when drain-wait events reach consumers; teardown raises a cancel-callback error only when the run otherwise succeeded (push_async_exit), documented on register(cancel=) and tested
- Why: douwebot and PR Review Checks findings, valid
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · douwebot optional at ef424c66ea: engine pages · iter -
- Decision: fixed in 10d2c430c8: dbos.md, prefect.md and temporal.md say ctx.in_flight raises throughout a durable run (workflow/flow code and units); DBOS child-workflow sentence lists it
- Why: douwebot optional finding; a douwebot comment blocks a clean approval
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · douwebot optional at 10d2c430c8: live()/wait_idle() loop check · iter -
- Decision: fixed in f011689772: both call _check_on_loop; test for live() from a worker thread
- Why: douwebot optional finding; a douwebot comment blocks a clean approval
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · douwebot optional at f011689772: drained event snapshot · iter -
- Decision: fixed in 6ed0956886: draining work started during the wait is recorded and listed in the drained event; span gets in_flight.waited; test
- Why: douwebot optional finding; a douwebot comment blocks a clean approval
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · douwebot optional at 6ed0956886: AWS Lambda page · iter -
- Decision: fixed in a032a1d13a: aws-lambda.md and its README gain a constraint bullet that ctx.in_flight raises throughout a durable execution
- Why: douwebot review-body optional finding fails the clean-approval gate
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · douwebot optional at a032a1d13a: several failures · iter -
- Decision: documented in 9501768ded (start() docstring and custom.md): only the first error is raised
- Why: douwebot optional finding; documenting matches the error-precedence choice already made for the teardown
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-12 · douwebot optional at 9501768ded: foreign event loop · iter -
- Decision: fixed in 194279755f: the registry records the loop it was created on (the run loop, since _prepare_run is async) and every method requires that loop; test registering from asyncio.run in a worker thread
- Why: douwebot optional finding
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-13 · douwebot optional at 194279755f: how to get the loop · iter -
- Decision: fixed in 4b5a5c6dfb: settle() docstring and custom.md say to capture the loop with asyncio.get_running_loop() where the work was registered
- Why: douwebot optional finding fails the clean-approval gate
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-13 · PR Review Checks at 4b5a5c6dfb: Any in a test · iter -
- Decision: fixed in 16356d6d87: dict[str, InFlightWork[None] | InFlightWork[bool]]; typing.Any import dropped
- Why: valid finding
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-13 · douwebot optional at 16356d6d87: unbounded teardown wait · iter -
- Decision: documented in 42c48cf8d2 (start() docstring, custom.md): the end-of-run wait for cancelled work is not bounded by timeout=; work must honour cancellation. No bound added: a bounded wait would leak still-running tasks
- Why: douwebot optional finding
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-13 · PR Review Checks at 42c48cf8d2: PendingModelResponse pause untested · iter -
- Decision: fixed in 83dd700c72: test drives _after_step with a PendingModelResponse End and checks it waits for all drain work; not a full batch run because main redirects queued content at that pause until #13054
- Why: valid finding
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-13 · douwebot optional at 42c48cf8d2: mutable on_end · iter -
- Decision: fixed in 83dd700c72: InFlightWork.on_end is a read-only property
- Why: reclassifying could orphan a run-owned task
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-13 · douwebot optional at 83dd700c72: bare run() · iter -
- Decision: fixed in 556ffdfcb0: run() and InFlightWork wait/result/cancel linked reference-style
- Why: douwebot nit
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-13 · douwebot approval at 556ffdfcb0 had summary prose · iter -
- Decision: empty commit 8f5c8f9c6f to request a fresh review: the gate (review_gates.py) only accepts the bare approval body, and the bot refuses to re-review a head with an earlier non-bare review
- Why: Gate: clean douwebot approval failed with no findings
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-13 · PR Review Checks at 8f5c8f9c6f: private _after_step test · iter -
- Decision: fixed in beac206218: the PendingModelResponse pause test runs through agent.run with a FunctionModel subclass whose continuation_delay marks suspended responses as jobs (a plain FunctionModel would keep continuing them instead of pausing); asserts the wait, not post-pause delivery
- Why: valid finding; tests/AGENTS.md public-API rule
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-25 · Douwe approved the shape · iter -
- Decision: ctx.in_flight.start(fn, kind='background_tool', ..., on_end='drain'|'cancel'), default 'drain'; a durable suspend drains or cancels the run's own background work; register() keeps 'detach' (11/11 ruling: shell jobs and resources that outlive the run). Listed ctx.in_flight raising under durable as a gap to fix
- Why: Douwe (lead) approval 2026-11-25, relayed by the webinar-aws-lambda session
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-25 · Durable runs: accept unless tools run sequentially; on_end at a durable wait · iter -
- Decision: in fa0f75fbc9: ctx.in_flight works in durable container code; refused (UserError naming the engine) when the run's parallel execution mode is 'sequential' in a durable context (Lambda via sequential_tools_in_durable_context, Absurd/pgtask default, DBOS with a workspace), matching where BackgroundTools falls back to the foreground (#14445/#14459); still raises in units. wait_for_external_event under an engine-installed waiter, reached from resolve_deferred_tool_calls (HandleDeferredToolCalls, AskUser), cancels 'cancel' work first and returns only once 'drain' work finished; 'detach' untouched; refusing waiters (Prefect, Azure, Render, DBOS until #14522) still raise after the cancel. No engine-name checks, no public spec field, ExternalEventWaiter contract unchanged
- Why: webinar-aws-lambda's call, implementing Douwe's approved shape; keeps #14459 Temporal survives_approval_wait green (the wait doesn't drain before ask)
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-25 · Merge origin/main at eb42f773a6 · iter -
- Decision: merge commit d26a7cb5ec: one conflict in test_workflow_side_determinism.py docstring list, kept both in_flight.py and retry_on_model_errors.py; contract manifest regenerated with --write (no diff); in_flight.py asyncio.Event gets noqa TID251 for main's new ban (registry is asyncio-only)
- Why: PR was CONFLICTING
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-25 · pre-push review 1 of 3 at fa0f75fbc9 (task 2026-11-25) · iter -
- Decision: reserved; dispatched
- Why: tree c4f64433630f50c9c74a28740393d553e5a4bf84; policy base 94400f65be; scope eb42f773a6..fa0f75fbc9 full branch, focus d26a7cb5ec..fa0f75fbc9 (durable redesign); previous task's 3-review budget was spent on 11/12
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-25 · pre-push review 1 of 3 at fa0f75fbc9 (task 2026-11-25) · iter -
- Decision: remediated in c67519a5bf: (1) Temporal wait test gated on workflow state (cancel work cancelled), not ask-side records, so the Replayer replays; (2) in-process test: async delete records drain 'succeeded'; (3) Temporal end-rule drain test added, DBOS/Prefect completion-order replay limit disclosed in custom.md; (4) engine-neutral refusal reason; (5) _durable_wait excludes the waiting work's own handle, test; (6) durable wait emits no events/span, docs narrowed to the wait to end; (7) stale _enqueue comment, DBOS-with-workspace listed, Temporal determinism note
- Why: reviewed tree c4f64433630f50c9c74a28740393d553e5a4bf84
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-25 · pre-push review 2 of 3 at c67519a5bf (task 2026-11-25) · iter -
- Decision: reserved; dispatched
- Why: tree 5b7f65d1d2998778bca80b1ef3d7103ecb0ba222; follow-up scope fa0f75fbc9..c67519a5bf plus review-1 findings; full branch diff as context
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-25 · pre-push review 2 of 3 at c67519a5bf (task 2026-11-25) · iter -
- Decision: remediated in 8134147901: (1) DBOS/Prefect drain replay limit stated plainly in custom.md, dbos.md, prefect.md; (2) _durable_wait finds the waiting work via a ContextVar set in _call, so child tasks (gather, wait_for on 3.11) are covered, test uses gather; (3) Temporal end-rule test asserts activity-completed, timer-fired, activity-completed order from history. Prior 7 findings verified resolved
- Why: reviewed tree 5b7f65d1d2998778bca80b1ef3d7103ecb0ba222
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-25 · pre-push review 3 of 3 at 8134147901 (task 2026-11-25) · iter -
- Decision: reserved; dispatched
- Why: tree 7e9d394de680632e6b9c8ee3536898d241294612; follow-up scope c67519a5bf..8134147901 plus review-2 findings
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-25 · pre-push review 3 of 3 at 8134147901 (task 2026-11-25) · iter -
- Decision: remediated in 139a7887e1: (1) _current_work holds the start() holder, read lazily, so an eager task factory no longer IndexErrors (test on 3.12+); (2) the ContextVar is the chain of started work, outermost first, so work that started the waiting work and awaits it is neither cancelled nor waited for (nested test). Review 2's three findings verified resolved. Budget spent: no fourth review; ruff check/format and the contract manifest pass
- Why: reviewed tree 7e9d394de680632e6b9c8ee3536898d241294612
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-25 · Merge origin/main at b38aba00d6 · iter -
- Decision: merge commit a2668c6bde: conflict in test_dbos.py where main dropped the subprocess mark on the next MCP test (now in-process FastMCPTransport); kept the in_flight test, took main's undecorated MCP test; manifest regenerated with --write (no further diff). Review budget spent, pushed on budget exhaustion
- Why: PR went CONFLICTING again after main moved
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
2026-11-25 · Refuse ctx.in_flight where a suspend ends the run · iter -
- Decision: in 73dfa71822: Absurd/pgtask with parallel_ordered_events accepted ctx.in_flight, but a durable sleep (model retry_after: absurd/_operation_backend.py:115-117, pgtask/_operation_backend.py:66-74) suspends by raising out of agent.run, so run teardown cancels live work and recovery doesn't restart it (#14493 case b; external-event waits were already refused by _UnsupportedWaiter). Private DurabilityEngineSpec._suspend_ends_run=True on Absurd, pgtask, AWS Lambda; RunContext.in_flight refuses at access; API waivers for the three engine_spec values; #14493/#13274 can relax it. Azure accepts: the trampoline loop re-runs the whole agent coroutine each dispatch (azure_durable_task/_bridge.py:36-41,148-169,198-216), so started work is re-created deterministically like parallel tool calls. Budget spent: ruff, contract, API check only
- Why: cluster owner (webinar-aws-lambda) asked to close the Absurd/pgtask cell per Douwe's 11/24 option B for BackgroundTools
- Source: https://github.com/pydantic/pydantic-ai/issues/14493
2026-11-25 · Refuse ctx.in_flight on DBOS until #14500 · iter -
- Decision: in 354bb3183f: private DurabilityEngineSpec._steps_identified_by_start_order replaces _suspend_ends_run (the property holds for DBOS, Lambda, Absurd and pgtask, all of which number units as they start; the last three also suspend by ending, #14493). Set on DBOSDurability; RunContext.in_flight refuses after the sequential check with a message naming start order and #14500. dbos.md and custom.md no longer advise 'cancel' work; Prefect note kept (tasks keyed by arguments). Tests: DBOS workflow code + step, DBOS with a workspace (sequential message), Absurd/pgtask parallel messages updated. Waivers regenerated for four engine_spec values. PR 2 note: BackgroundTools on DBOS falls back like ruling B (foreground + warn once)
- Why: Douwe's durable review at 73dfa71822, blocking item 1; webinar-aws-lambda's call
- Source: https://github.com/pydantic/pydantic-ai/pull/13217#issuecomment-7152250617
2026-11-25 · Sibling work no longer deadlocks at a durable wait · iter -
- Decision: in 354bb3183f: registry keeps _in_wait (a Counter, so concurrent waits of one work count separately) of work inside _durable_wait, its own chain included; excluded from both the cancel list and the drain loop; two-sibling test with a waiter that answers only once both asked
- Why: Douwe's durable review at 73dfa71822, blocking item 2
- Source: https://github.com/pydantic/pydantic-ai/pull/13217#issuecomment-7152250617
2026-11-25 · Azure: finally in started work runs once per dispatch · iter -
- Decision: in 354bb3183f: sentence in custom.md, bullet in docs/harness/azure-durable-task.md 'Replay and side effects' and its README twin. Budget spent: ruff, contract --write (no diff), API check pass
- Why: Douwe's durable review at 73dfa71822, non-blocking note
- Source: https://github.com/pydantic/pydantic-ai/pull/13217#issuecomment-7152250617
2026-11-25 · macroscope: duplicate id under an eager task factory · iter -
- Decision: fixed in fd9209a59d: start() reserves the id in _starting around create_task(); _check_can_add refuses a reserved id; eager-factory test starts the same id from inside fn
- Why: valid: an eager factory runs fn inside create_task(), before _add()
- Source: https://github.com/pydantic/pydantic-ai/pull/13217#discussion_r4690090553
2026-11-25 · macroscope: eager task factory and the waiting chain · iter -
- Decision: fixed in fd9209a59d: _durable_wait keeps the start() holders in _in_wait (a list of holder lists) and checks membership when it needs it, so a handle start() appends after an eager first step still counts as waiting work
- Why: valid for work that reaches the wait during its eager first step; the 139a7887e1 holder fix read the holders only once, on entry
- Source: https://github.com/pydantic/pydantic-ai/pull/13217#discussion_r4690090568
2026-11-25 · PR Review Checks: module READINESS_WAIT_TIMEOUT in test_in_flight.py · iter -
- Decision: fixed in fd9209a59d: import READINESS_WAIT_TIMEOUT from tests/_timeouts.py (two threads, same finding)
- Why: valid: tests/AGENTS.md test-cost rule
- Source: https://github.com/pydantic/pydantic-ai/pull/13217#discussion_r4690150983
2026-11-25 · PR Review Checks: Any in new harness tests · iter -
- Decision: fixed in fd9209a59d: Absurd, pgtask and Lambda in_flight refusal tests use AbstractCapability[None]/RunContext[None]; pgtask drops its new Any import (six threads, same finding)
- Why: valid: tests/harness/AGENTS.md no-Any rule. Budget spent: ruff, contract only
- Source: https://github.com/pydantic/pydantic-ai/pull/13217#discussion_r4690150988
2026-11-25 · Durable sign-off notes 2 and 3 · iter -
- Decision: in 22702100c1: _durable_wait removes one _in_wait entry per holder by identity (two empty holders compare equal, and a holder is listed once per wait); refusal reads 'in {engine} runs yet' (no 'a Absurd'), test expectations updated. Note 1 (entering a wait doesn't _notify()) left as a follow-up in the PR body. Budget spent: ruff, contract --write (no diff)
- Why: independent durable review sign-off at fd9209a59d, notes
- Source: https://github.com/pydantic/pydantic-ai/pull/13217
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.