Title: Support `async def` activities in the core worker · Issue #319 · microsoft/durabletask-python · GitHub
Open Graph Title: Support `async def` activities in the core worker · Issue #319 · microsoft/durabletask-python
X Title: Support `async def` activities in the core worker · Issue #319 · microsoft/durabletask-python
Description: Problem Registering an async def activity with TaskHubGrpcWorker (or DurableTaskSchedulerWorker) fails at runtime. The activity executor calls the function without awaiting it, and the data converter then tries to serialize the coroutine...
Open Graph Description: Problem Registering an async def activity with TaskHubGrpcWorker (or DurableTaskSchedulerWorker) fails at runtime. The activity executor calls the function without awaiting it, and the data convert...
X Description: Problem Registering an async def activity with TaskHubGrpcWorker (or DurableTaskSchedulerWorker) fails at runtime. The activity executor calls the function without awaiting it, and the data convert...
Opengraph URL: https://github.com/microsoft/durabletask-python/issues/319
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support `async def` activities in the core worker","articleBody":"## Problem\n\nRegistering an `async def` activity with `TaskHubGrpcWorker` (or `DurableTaskSchedulerWorker`) fails at runtime. The activity executor calls the function without awaiting it, and the data converter then tries to serialize the coroutine:\n\n```python\nasync def fetch(ctx: task.ActivityContext, city: str) -> float:\n async with httpx.AsyncClient() as client:\n ...\n\nworker.add_activity(fetch)\n# Activity task #1 failed: Failed to serialize object of type 'coroutine' to JSON:\n# Object of type 'coroutine' is not JSON serializable\n```\n\nPython also emits `RuntimeWarning: coroutine 'fetch' was never awaited`.\n\nThe only workaround today is a sync activity that calls `asyncio.run(...)`. That holds a worker thread for the whole I/O wait and creates a new event loop per call, even though the worker already runs its own loop and `_AsyncWorkerManager` can await coroutine work items.\n\n## Why\n\n- I/O-bound activities (HTTP calls, async database drivers, Azure SDK `aio` clients) are the common case. With async activities they no longer occupy a thread from `maximum_thread_pool_workers` while they wait.\n- The Azure Functions provider in this repo already accepts `async def` activities (`azure-functions-durable/.../internal/compat/activity.py` checks `inspect.iscoroutinefunction`). The core worker is the remaining gap.\n- #294 adds async/await support for **orchestrators**. Activities are a separate code path and are not covered there, so this complements it without overlapping.\n\n## Proposed design\n\n- If an activity is a coroutine function (or a callable object with an `async def __call__`), the worker runs it on its event loop and awaits it. Sync activities keep their existing thread pool path unchanged.\n- Concurrency stays bounded by `ConcurrencyOptions.maximum_concurrent_activity_work_items`, as it is today.\n- Tracing, failure details and the activity execution hooks behave the same on both paths. Blocking calls (payload store, `CompleteActivityTask`) are moved off the loop with `asyncio.to_thread`.\n- `call_activity()` gets an overload so an async activity's task is typed with the awaited result instead of a coroutine.\n- A sync activity that returns an awaitable fails with a clear `TypeError` (use `async def`) instead of the serialization error above.\n\nNo public API is removed, and no package version or dependency changes.\n\nI have an implementation with tests ready and will open a PR referencing this issue. Happy to adjust the design if you'd prefer a different approach, for example aligning it with #293.\n","author":{"url":"https://github.com/KSouleymane","@type":"Person","name":"KSouleymane"},"datePublished":"2026-11-02T18:15:35Z","url":"https://github.com/microsoft/durabletask-python/issues/319"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e278c2de-776f-f962-00c7-081c537f0282 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E260:78925:69176:9327D:6AFE1E8B |
| html-safe-nonce | 0ed8078b207cd46bfd3120bd4e04fe4435bb2f01b38d641fdef2e29fc88af913 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMjYwOjc4OTI1OjY5MTc2OjkzMjdEOjZBRkUxRThCIiwidmlzaXRvcl9pZCI6IjEwMzYzODAwNzI3OTA4NTk0MDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e0835b5f0d6e265ae6d48a758b2f0c9c3f95fcec0689478ca3dea567caec200c |
| hovercard-subject-tag | issue:6168341388 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/durabletask-python/319/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3e2335be42bb857236a53e6fbbaa989545a4771afbc61904afc77484e738c285/microsoft/durabletask-python/issues/319 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3e2335be42bb857236a53e6fbbaa989545a4771afbc61904afc77484e738c285/microsoft/durabletask-python/issues/319 |
| og:image:alt | Problem Registering an async def activity with TaskHubGrpcWorker (or DurableTaskSchedulerWorker) fails at runtime. The activity executor calls the function without awaiting it, and the data convert... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | KSouleymane |
| hostname | github.com |
| expected-hostname | github.com |
| None | d0525ab1464526bf4532a5551aa348cf100dff75ef808a96fc67a08b1d946aa9 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/durabletask-python git https://github.com/microsoft/durabletask-python.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 627664515 |
| octolytics-dimension-repository_nwo | microsoft/durabletask-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627664515 |
| octolytics-dimension-repository_network_root_nwo | microsoft/durabletask-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | fef3993a71fa20f7be8e167132fbf9619bc66e12 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width