Skip to content

Add deterministic workflow task groups - #2086

Draft
VegetarianOrc wants to merge 3 commits into
amazzeo/task-group-warningfrom
amazzeo/deterministic-task-group
Draft

VegetarianOrc wants to merge 3 commits into
amazzeo/task-group-warningfrom
amazzeo/deterministic-task-group

Conversation

@VegetarianOrc

@VegetarianOrc VegetarianOrc commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add workflow.TaskGroup for Python 3.11+ to make cancellation of mixed Temporal operations deterministic.

  • Reuse the standard-library task-group state machine, replacing its private task registry with a dictionary-backed ordered collection.
  • Request cancellation in task-addition order, without promising cleanup completion order.
  • Export the API with a clear Python 3.10 construction error, recommend it in the sandbox warning and README, and combine the release notes.
  • Cover registry ordering, cancellation/cleanup, nesting, and mixed timer/activity/child-workflow history ordering and replay with caching enabled and disabled.

Fixes #2069. Stacked on #2085.

Compatibility notes

The implementation depends on the private asyncio _tasks registry, audited across CPython 3.11–3.14. It inherits the running interpreter cancellation semantics, including older Python limitations, subject to existing workflow event-loop restrictions; eager task start is not supported. Previously recorded nondeterministic histories are not repaired.

Validation

Final revision on Python 3.13.7:

  • poe test -s tests/test_workflow_task_group.py tests/test_workflow_exports.py tests/worker/workflow_sandbox/test_runner.py — 27 passed.
  • poe lint — passed, including pyright, mypy, and basedpyright.
  • git diff --check — passed.

An earlier, broader test revision also passed on Python 3.10.18, 3.11.8, 3.12.13, 3.13.7, and 3.14.2 using the local ABI3 bridge. The final simplified suite was not rerun across that full matrix.

leaf_message=(
"asyncio.TaskGroup is not supported in workflows "
"because its task cancellation order is non-deterministic"
"asyncio.TaskGroup() is non-deterministic, use workflow.TaskGroup() instead"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oOoo

@VegetarianOrc
VegetarianOrc force-pushed the amazzeo/deterministic-task-group branch 2 times, most recently from 239676a to bb46e58 Compare November 6, 2026 19:06
@VegetarianOrc
VegetarianOrc force-pushed the amazzeo/deterministic-task-group branch from bb46e58 to 0e9592c Compare November 6, 2026 19:28

This branch has not been deployed

No deployments
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.

[Bug] TaskGroup cancellation of mixed Temporal operations can break replay

2 participants