You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add deterministic async/await orchestrators across all three Python packages - #293
Adds coroutine-first orchestration to durabletask, durabletask.azuremanaged, and azure-functions-durable. An async def orchestrator automatically receives an async context; no conversion call is needed. Existing generator orchestrators retain their eager durable task handles, and both styles use the same history and replay engine. Durable parents and children can use either style.
Functions also supports single-argument async orchestrators with df.AsyncDurableOrchestrationContext, preserving the v1-style method and argument names, including durable HTTP retry options.
Behavior and limitations
Async context operations are cold, single-use native coroutines. Validation, serialization, action allocation, and relative timer deadlines begin when a coroutine starts. Generator-context operations remain eager. as_task_context() and Task.wait() provide explicit interoperability with reusable durable handles.
The documented deterministic asyncio subset includes ordered gather, task groups, local tasks and futures, durable sleeps, and timeouts. asyncio.wait, as_completed, arbitrary third-party async libraries, external I/O, threads, and subprocesses are outside the contract. Nondeterministic work belongs in activities.
The Functions compatibility context provides async task_all and task_any; grouping preserves input order and duplicate references, and supplied futures are borrowed rather than implicitly cancelled.
Cancelling an owned event wait or timer withdraws its local registration, but cannot undo already-issued remote work or side effects. A cancelled pending entity-lock acquisition may still be granted; retain and shield the acquisition if it must later be released.
Dispatch-local tasks and scopes are cleaned up at every dispatch boundary, including suspension. Finalizers may run before logical orchestration completion and cannot schedule or await new durable work. Durable compensation belongs in normal orchestration control flow.
Replay and release considerations
Converting an in-flight generator orchestration requires preserving replay-visible actions, ordering, payloads, timers, event consumption, and entity-release behavior. Python/asyncio upgrades can also change scheduling; validate recorded histories before changing runtimes for in-flight instances. See the async orchestration contract for the supported APIs and upgrade guidance.
All three package changelogs document the feature under Unreleased. Provider releases require the corresponding core capability; package versions and dependency minimums should be updated together in a coordinated release PR after the core release.
Make durable tasks awaitable, drive native coroutines through the existing replay engine, and preserve generator compatibility. Include provider smoke coverage, prototype documentation, and coordinated-release notes.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Give each replay dispatch explicit ownership of its orchestrator generator: close it once in an outer finally after the response is built, so cleanup in finally blocks runs deterministically and cannot alter the returned actions or custom status. Ordinary teardown failures are logged without replacing dispatch results or abandonment.
Async bridges such as Pydantic AI otherwise retain AnyIO task scopes, event loops, and orchestration contexts indefinitely. Also relevant to the async/await work in #293 and #294.
Fixes#299
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 35371373-86cf-4897-bf7c-460fa3c88d1f
Preserve generator dispatch recovery and snapshots; resume coroutine branches per history completion, order cancellation wakeups, and define the bounded async contract.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Handle closure tasks created during cleanup, retaining warnings for ordinary errors and terminal recovery for unexpected BaseException exits.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Exercise TestModel parallel tools and recorded failures without a trampoline, retain adapter serialization and replay-stable metadata, and cover Windows Python versions in CI.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
andystaples
changed the title
Prototype async/await orchestrators across all three Python packages
Add deterministic async/await orchestrators across all three Python packages
Oct 30, 2026
Continue bounded cleanup after callback and process-control failures. Deliver durable completions through ordered subscriptions instead of repeated pending-work scans, and scale the cleanup budget for large cooperative fan-out. Add focused regressions and keep documentation adoption guidance minimal.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve the async completion observer and cleanup fixes while adopting main's ExceptionGroup control-flow classification and Python 3.11 minimum. Resolve the provider changelog by retaining both changes.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Callback-originated StopIteration can silently complete a still-pending workflow, while duplicate timer registrations can overwrite observers and cleanup failures can mask process-control exceptions.
Adds native async/await orchestrators across all three Python packages using the shared replay engine, while retaining generator support and mixed-style sub-orchestrations.
Changes:
Adds deterministic asyncio scheduling, durable timers, local cancellation, and dispatch cleanup.
Adds core and provider tests, Functions host smoke tests, a Pydantic AI integration proof, and Windows coverage.
Documents supported async APIs, replay constraints, and provider release coordination.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The wrapper fails on direct durable awaits in async tests with a running event loop, while completed-task retention keeps discarded results alive and causes memory usage to grow across replay batches.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Durable awaits fail when called from an async test loop
Calling this wrapper from an async test with a running asyncio loop fails even for a direct durable await: Task.__await__ sees the test's loop and raises "Durable tasks can only be awaited inside a durable orchestrator." Isolate every coroutine send/throw from the ambient loop and restore the caller's state afterward. Add an async-test regression for direct durable awaits.
Completed tasks retain results for the entire replay
durabletask/internal/asyncio_loop.py:132
_tasks retains every completed task until dispatch teardown, including each successful task's result. Replaying sequential, discarded gather batches therefore keeps earlier decoded activity results alive, so memory grows with the full replay rather than the live batch. Retire successful completed tasks and use a separate monotonic creation counter for cancellation ordering, while preserving tracking for pending tasks and unobserved failures.
Replace AnyIO test usage with asyncio task groups and retain replay, context propagation, cancellation ordering, and cleanup coverage. Remove the test dependency and third-party compatibility claims.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Retire completed local tasks when their failures are observed, including after the initial completion callback. Preserve pending-task tracking and unobserved background failure reporting.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Expose an explicit native-coroutine facade while preserving eager durable handles and existing generator APIs. Clean up owned event registrations and timers without changing borrowed-operation cancellation semantics.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
Reviewed the shared async replay implementation and the core, Azure Managed and Functions integration paths. I found no blocking correctness or compatibility defects at 0872493. The additive API preserves existing generator authoring and avoids introducing new abstract requirements; replay parity and provider coverage are substantial.
The main tradeoff is replay CPU: a local synthetic sequential replay benchmark was approximately 2.2x slower for equivalent async code than generators, while an executor-only comparison showed no material slowdown for existing generators. This is opt-in overhead, not a merge blocker, but is relevant for long histories.
The documented restrictions on external I/O, dispatch-local cleanup, migration of persisted histories and Python-version-dependent scheduling are important. Core regressions passed locally on 3.11/3.13/3.14, provider tests passed, and the live CI matrix is green. No changes requested.
Superseded by the review stack #356 → #357 → #358 → #360 → #361 → #363 → #364. The top of the stack (#364) has a tree identical to this PR's final state. Review each layer independently; the stack is squash-merged as a whole once every layer is approved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds coroutine-first orchestration to
durabletask,durabletask.azuremanaged, andazure-functions-durable. Anasync deforchestrator automatically receives an async context; no conversion call is needed. Existing generator orchestrators retain their eager durable task handles, and both styles use the same history and replay engine. Durable parents and children can use either style.Functions also supports single-argument async orchestrators with
df.AsyncDurableOrchestrationContext, preserving the v1-style method and argument names, including durable HTTP retry options.Behavior and limitations
as_task_context()andTask.wait()provide explicit interoperability with reusable durable handles.gather, task groups, local tasks and futures, durable sleeps, and timeouts.asyncio.wait,as_completed, arbitrary third-party async libraries, external I/O, threads, and subprocesses are outside the contract. Nondeterministic work belongs in activities.task_allandtask_any; grouping preserves input order and duplicate references, and supplied futures are borrowed rather than implicitly cancelled.Replay and release considerations
Converting an in-flight generator orchestration requires preserving replay-visible actions, ordering, payloads, timers, event consumption, and entity-release behavior. Python/asyncio upgrades can also change scheduling; validate recorded histories before changing runtimes for in-flight instances. See the async orchestration contract for the supported APIs and upgrade guidance.
All three package changelogs document the feature under
Unreleased. Provider releases require the corresponding core capability; package versions and dependency minimums should be updated together in a coordinated release PR after the core release.Relates to #294.