Skip to content

feat: optimize async execution#683

Open
tyaroshko wants to merge 26 commits intomainfrom
feat/async-execution-optimization
Open

feat: optimize async execution#683
tyaroshko wants to merge 26 commits intomainfrom
feat/async-execution-optimization

Conversation

@tyaroshko
Copy link
Copy Markdown
Collaborator

@tyaroshko tyaroshko commented Apr 7, 2026

Note

Medium Risk
Updates core flow/node execution to mix native-async and thread-offloaded sync work, which can affect concurrency, timeouts, and context propagation across many node types. Risk is mitigated by added unit/integration coverage but touches critical runtime paths (LLM execution, caching, executor lifecycle).

Overview
Optimizes async runtime execution paths by introducing native async node execution and isolating sync offloading to a per-Flow.run_async ContextAwareThreadPoolExecutor passed down into nodes.

Nodes now choose between running execute_async directly on the event loop (with new execute_async_with_retry using asyncio.wait_for/asyncio.sleep) or falling back to run_sync in an executor with explicit contextvars propagation; tools with their own event loops (e.g. CuaDesktopTool, E2BDesktopTool) are forced onto the thread-executor path.

Adds async-aware caching via cache_wf_entity_async (thread-offloading cache I/O), introduces BaseLLM.execute_async using litellm.acompletion (including async streaming handling), and extends LLM fallback logic to the async run_async path. Tests are updated/added to cover async caching, per-flow executors, node async routing/retry/timeout, and LLM async execution/fallback, with expectations adjusted (e.g., async LLM calls no longer pass a sync client).

Reviewed by Cursor Bugbot for commit 356b16e. Bugbot is set up for automated code reviews on this repo. Configure here.

@tyaroshko tyaroshko requested a review from a team as a code owner April 7, 2026 09:46
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

Coverage

Coverage Report •
FileStmtsMissCoverMissing
dynamiq/flows
   flow.py2355775%105, 112, 119, 153–154, 212–214, 236, 239, 245, 247–251, 258, 261, 267, 269, 271–272, 274, 276–278, 428–432, 442–443, 457–458, 460, 479–480, 482, 485, 504–505, 508–509, 512–513, 515–516, 519–521, 523–527, 529
dynamiq/nodes
   node.py77611984%53, 284, 332, 349, 382, 393, 408, 413–414, 418–419, 463–464, 466, 484, 503, 505, 539, 541, 548–549, 621–622, 625–627, 634–636, 644–645, 655–660, 667–668, 743, 756, 758, 760, 764, 775–776, 794–797, 800–803, 805, 810, 812–814, 818, 821–822, 827, 849–851, 857, 1252–1253, 1256–1258, 1261, 1264–1265, 1267, 1355, 1389–1390, 1415–1416, 1438–1439, 1467–1468, 1494–1495, 1520–1521, 1543–1544, 1564–1565, 1603, 1631, 1637, 1640, 1657–1659, 1732–1738, 1740, 1742–1743, 1754, 1774, 1809, 1843, 1849, 1902, 1924–1926
dynamiq/nodes/llms
   base.py3553689%31, 33, 140, 146, 342–345, 352–358, 385, 562–571, 592–593, 626, 628, 658, 860, 937, 940, 971–972
tests
   conftest.py99198%141
TOTAL26978897566% 

Tests Skipped Failures Errors Time
1572 1 💤 0 ❌ 0 🔥 2m 2s ⏱️

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 356b16e. Configure here.

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.

1 participant