Skip to content

Add support for async workflow activities#1053

Draft
seherv wants to merge 9 commits into
dapr:mainfrom
seherv:async-compat
Draft

Add support for async workflow activities#1053
seherv wants to merge 9 commits into
dapr:mainfrom
seherv:async-compat

Conversation

@seherv
Copy link
Copy Markdown
Contributor

@seherv seherv commented May 25, 2026

Description

Workflow activities can now be async, and the runtime will automatically dispatch them to the event loop. Sync activities are still dispatched to the thread pool. The user-facing API remains exactly the same.

Also added a benchmark suite to verify performance locally.

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #834 #897 #975

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

f"Activity '{req.name}#{req.taskId}' result is too large to deliver "
f'(RESOURCE_EXHAUSTED). Failing the activity task: {rpc_error.details()}'
)
failure_res = pb.ActivityResponse(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This nesting got hard to follow, I needed to refactor this file to understand the logic better.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2026

Codecov Report

❌ Patch coverage is 83.90501% with 61 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.84%. Comparing base (bffb749) to head (e8c4c05).
⚠️ Report is 137 commits behind head on main.

Files with missing lines Patch % Lines
...-workflow/dapr/ext/workflow/_durabletask/worker.py 35.29% 44 Missing ⚠️
...workflow/tests/test_async_activity_registration.py 92.30% 12 Missing ⚠️
...ext-workflow/dapr/ext/workflow/workflow_runtime.py 93.02% 3 Missing ⚠️
...rkflow/tests/durabletask/test_activity_executor.py 93.33% 1 Missing ⚠️
.../tests/durabletask/test_activity_executor_async.py 97.61% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1053      +/-   ##
==========================================
- Coverage   86.63%   82.84%   -3.79%     
==========================================
  Files          84      149      +65     
  Lines        4473    15017   +10544     
==========================================
+ Hits         3875    12441    +8566     
- Misses        598     2576    +1978     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Sergio Herrera <627709+seherv@users.noreply.github.com>
@JoshVanL JoshVanL requested a review from Copilot May 26, 2026 10:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@seherv seherv requested a review from Copilot May 27, 2026 07:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Comment thread ext/dapr-ext-workflow/dapr/ext/workflow/_durabletask/worker.py Outdated
Comment thread ext/dapr-ext-workflow/docs/concurrency.md Outdated
Comment thread ext/dapr-ext-workflow/AGENTS.md Outdated
Comment thread ext/dapr-ext-workflow/AGENTS.md Outdated
Comment thread ext/dapr-ext-workflow/tests/test_async_activity_registration.py
Comment thread ext/dapr-ext-workflow/benchmarks/RESULTS.md Outdated
Signed-off-by: Sergio Herrera <627709+seherv@users.noreply.github.com>
@seherv seherv requested a review from Copilot June 1, 2026 09:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

ext/dapr-ext-workflow/dapr/ext/workflow/_durabletask/worker.py:678

  • This adds an extra registry lookup (get_activity) and inspect.iscoroutinefunction check on the hot dispatch path, but _ActivityExecutor._resolve() will look up the activity again during execution. Consider plumbing activity_fn (and/or an is_async flag decided at registration time) through to the executor so each activity work item only does one lookup in total.
                                activity_handler,
                                work_item.activityRequest,
                                stub,
                                work_item.completionToken,
                            )

Comment thread ext/dapr-ext-workflow/tests/test_async_activity_registration.py Outdated
Comment thread ext/dapr-ext-workflow/dapr/ext/workflow/_durabletask/worker.py
Comment thread ext/dapr-ext-workflow/docs/concurrency.md Outdated
Comment thread ext/dapr-ext-workflow/benchmarks/bench_async_activities.py
Signed-off-by: Sergio Herrera <627709+seherv@users.noreply.github.com>
@seherv seherv requested a review from Copilot June 1, 2026 11:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 5 comments.

Comment thread ext/dapr-ext-workflow/benchmarks/bench_async_activities.py Outdated
Comment thread ext/dapr-ext-workflow/benchmarks/bench_async_activities.py
Comment thread ext/dapr-ext-workflow/tests/test_async_activity_registration.py Outdated
Comment thread ext/dapr-ext-workflow/dapr/ext/workflow/_durabletask/worker.py
Signed-off-by: Sergio Herrera <627709+seherv@users.noreply.github.com>
@seherv seherv requested a review from Copilot June 1, 2026 13:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.

Comment thread ext/dapr-ext-workflow/tests/test_async_activity_registration.py Outdated
Comment thread ext/dapr-ext-workflow/dapr/ext/workflow/_durabletask/worker.py
Comment thread ext/dapr-ext-workflow/dapr/ext/workflow/_durabletask/worker.py
Comment thread ext/dapr-ext-workflow/dapr/ext/workflow/_durabletask/worker.py Outdated
seherv added 3 commits June 1, 2026 16:11
Signed-off-by: Sergio Herrera <627709+seherv@users.noreply.github.com>
Signed-off-by: Sergio Herrera <627709+seherv@users.noreply.github.com>
@seherv seherv requested a review from Copilot June 1, 2026 14:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 4 comments.

Comment thread ext/dapr-ext-workflow/docs/concurrency.md
Comment thread ext/dapr-ext-workflow/AGENTS.md Outdated
Comment thread ext/dapr-ext-workflow/benchmarks/bench_async_activities.py Outdated
Comment thread ext/dapr-ext-workflow/dapr/ext/workflow/_durabletask/worker.py
Signed-off-by: Sergio Herrera <627709+seherv@users.noreply.github.com>
@seherv seherv requested a review from Copilot June 1, 2026 14:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 15 changed files in this pull request and generated 3 comments.

Comment on lines +25 to +37
def is_async_callable(fn: Any) -> bool:
"""Return True if ``fn`` is async. Catches ``functools.partial`` of coroutines,
sync decorators that wrap async functions, and callable instances with ``async __call__``.
"""
candidate = fn
while isinstance(candidate, functools.partial):
candidate = candidate.func
candidate = inspect.unwrap(candidate) if callable(candidate) else candidate
if inspect.iscoroutinefunction(candidate):
return True
if not inspect.isfunction(candidate) and hasattr(candidate, '__call__'):
return inspect.iscoroutinefunction(candidate.__call__)
return False
Comment on lines +1145 to 1151
except RuntimeError as exc:
# Manager thread pool shut down (worker is tearing down). Treat as transient:
# the sidecar will re-dispatch the work item once the worker reconnects.
self._logger.warning(
f"Could not deliver activity response for '{req.name}#{req.taskId}': "
f'{exc}. The sidecar will re-dispatch this work item.'
)
hosts or need per-call timeout isolation, stick with per-call clients.

## Re-running the benchmark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: asyncio support for workflow sdk

2 participants