Repository navigation
[Async stack 5/6] Functions async orchestration support - #363
andystaples wants to merge 1 commit into
Conversation
4ebbc8b to
a35936b
Compare
a35936b to
f9ae519
Compare
f9ae519 to
69872f1
Compare
Rebased onto main as a single commit. Includes: - Add Functions coroutine orchestrator support - Use the native async shape for Functions orchestrators and add call_http helper - Track df.call_http as a cold operation and tighten Functions async messages Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Unawaited HTTP call coroutines can be finalized before teardown because they are tracked only weakly, causing RuntimeWarnings; retain them until teardown and add a regression test.
1 open issue
What changed in this PR
Adds Azure Functions support for two-argument async def orchestrators, aligning the provider with the core SDK while preserving existing synchronous and generator behavior.
Changes:
- Accepts async orchestrators across Functions entry points and rejects unsupported signatures.
- Adds
df.call_httpfor async and eager contexts, sharing the existing durable HTTP implementation. - Expands replay, HTTP, typing, and real-host test coverage.
| File | Description |
|---|---|
tests/azure-functions-durable/typing/import_package.py |
Checks HTTP overloads and orchestrator registration types. |
tests/azure-functions-durable/test_http_retry.py |
Extends HTTP coverage across legacy, eager, and async contexts. |
tests/azure-functions-durable/test_functions_coroutine_orchestrators.py |
Tests async replay, event timeouts, and signature validation. |
tests/azure-functions-durable/e2e/test_coroutine_e2e.py |
Adds real-host async orchestration tests. |
tests/azure-functions-durable/e2e/apps/dtask_style/orchestrators.py |
Adds async activity, fan-out, race, and HTTP probes. |
azure-functions-durable/azure/durable_functions/worker.py |
Broadens orchestration callable annotations. |
azure-functions-durable/azure/durable_functions/orchestrator.py |
Validates orchestrator signatures during handle creation. |
azure-functions-durable/azure/durable_functions/internal/compat/orchestration_context.py |
Validates async signatures and delegates legacy HTTP scheduling. |
azure-functions-durable/azure/durable_functions/http/call.py |
Implements shared HTTP scheduling and the new public helper. |
azure-functions-durable/azure/durable_functions/decorators/durable_app.py |
Updates decorator typing and adds signature validation. |
azure-functions-durable/azure/durable_functions/__init__.py |
Exports call_http from the package. |
Review effort: Balanced
| BUILTIN_HTTP_POLL_ORCHESTRATOR_NAME, input=request, return_type=DurableHttpResponse) | ||
|
|
||
|
|
||
| @_cold_operation |
cd0ba46 to
5630723
Compare
Bernd Verst (berndverst)
left a comment
There was a problem hiding this comment.
The two-argument async shape fits Functions without changing the legacy generator API. The Functions host tests passed in both payload-typing modes, and I verified that a decorated Blueprint orchestrator with a typed input and output replays through the Functions entry point. Before approving, I'd like registration to reject async signatures the host can't invoke, and durable HTTP to honor the teardown guard before it serializes the request.
| If ``fn`` is an async orchestrator with fewer than two positional | ||
| parameters. | ||
| """ | ||
| if accepts_two_positional_args(fn) or not is_async_callable(fn): |
There was a problem hiding this comment.
This counts positional slots, but it doesn't check that the function can actually be called with (ctx, input). For example, async def orch(ctx, value, *, required) indexes successfully, then every instance fails because the host never supplies required. A third required positional parameter does the same. Can we use inspect.signature(fn).bind(...) with two placeholders for async functions and surface the error at registration? The legacy sync/generator routing can stay as it is.
| token_source: TokenSource | None, | ||
| is_raw_str: bool, | ||
| retry_options: HttpRetryOptions | None) -> DurableHttpResponse: | ||
| request = _build_request(method, uri, content, headers, token_source, is_raw_str, retry_options) |
There was a problem hiding this comment.
Can we check whether dispatch teardown permits scheduling before building the HTTP request? In a finally block unwound at the end of a pending dispatch, both await df.call_http(ctx, ...) and df.call_http(ctx.as_task_context(), ...) run TokenSource.to_json() before the scheduler rejects them. Invalid raw content also replaces the teardown error with a TypeError. Please put the check before validation and serialization for both paths; the request should still be built immediately for eager calls and only on start for cold calls.

Warning
This PR is part of a review-only stack and must not be merged individually. The whole stack will be squash-merged after every PR in it is approved.
Summary
Adds
async deforchestrator support to the Azure Functions Durable provider using the same shape as the core SDK and Durable Task Scheduler provider:async def orchestrator(ctx: task.AsyncOrchestrationContext, input). The second argument is the orchestration input.Async orchestrators
async deforchestrators pass straight through to the core worker, which suppliestask.AsyncOrchestrationContext. This works throughDFApp/Blueprint.orchestration_trigger,Orchestrator.create, andDurableFunctionsWorker.async deforchestrators with fewer than two positional parameters, such as single-parameter or keyword-only-input functions, are not supported.orchestration_triggerandOrchestrator.createraiseTypeErrorat decoration time, and the worker raises it before registration. The message points to the two-parameter shape. The function is inspected only, so no coroutine is created.DurableOrchestrationContextorchestrators remain generator or regular functions with unchanged behavior, includingtask_all/task_any.df.call_httpazure.durable_functions.call_http(ctx, method, uri, *, content, headers, token_source, is_raw_str, retry_options). It returns aDurableHttpResponse.task.AsyncOrchestrationContext, it returns a cold coroutine namedcall_http: validation, serialization (including headers and content), and scheduling happen when the coroutine starts. Like the context's own operations, a call that never starts is closed at dispatch teardown, so it schedules nothing and reports no never-awaited warning. Withtask.OrchestrationContext, it schedules immediately and returns aTasktoyield. Other context types raiseTypeError.DurableOrchestrationContext.call_http: the built-in HTTP activity, 202/Location polling sub-orchestration,HttpRetryOptions, and token sources. The compat method's behavior is unchanged.Typing
FunctionsOrchestratorcoverstask.Orchestrator(sync and two-parameter async) plus single-parameterDurableOrchestrationContextcallables. The decorators and worker use it.Limitations
orchestrator_generator_wrappertesting helper drives generator orchestrators only. Test async orchestrators with the replay executor, a provider, or the in-memory backend.Tests
call_httpfor v1, eager, and async contexts (success, 202 polling, retry failure, cold validation and header reads, no never-awaited warning for unstarted calls, content encoding).as_task_context()+task.when_anyrace, and asynccall_httpprobes, whichtest_coroutine_e2e.pyruns against a real Functions host.call_httpoverloads and orchestrator registration.Layer 6 contains the release-facing docs (READMEs, migration guide, changelogs). This PR contains no version bumps.