Skip to content

fix(python): settle cancelled tasks awaited by async workflows - #5064

Merged
dbrattli merged 1 commit into
mainfrom
fix/python-await-task-cancellation
Oct 14, 2026
Merged

dbrattli merged 1 commit into
mainfrom
fix/python-await-task-cancellation

Conversation

@dbrattli

Copy link
Copy Markdown
Collaborator

Python Async.AwaitTask lets asyncio.CancelledError escape its completion callback because that exception derives from BaseException. A cancelled task can therefore leave its waiting workflow unsettled. The existing cancellation test returned through Async.StartImmediate before its assertion ran, closing its event loop before a background cancellation timer fired and producing a thread warning during a later test.

Compile Async.AwaitTask to a new await_task_with_cancellation entry point that reports native task cancellation as TaskCanceledException through the error continuation, matching .NET. Add the Python exception type and compiler mapping, including message and inner-exception support. Preserve the legacy await_task entry point for existing Python consumers; newly generated code requires the runtime containing the new entry point.

Replace the cancellation test with an awaited test that uses a child-entry handshake and checks the error outcome on both .NET and Python. Add native coverage for tasks cancelled before and during the wait, plus an F# regression for the exception type and payload.

@github-actions

Copy link
Copy Markdown
Contributor

Python Type Checking Results (Pyright)

Metric Value
Total errors 34
Files with errors 4
Excluded files 4
New errors ✅ No
Excluded files with errors (4 files)

These files have known type errors and are excluded from CI. Remove from pyrightconfig.ci.json as errors are fixed.

File Errors Status
temp/tests/Python/test_hash_set.py 18 Excluded
temp/tests/Python/test_applicative.py 12 Excluded
temp/tests/Python/test_nested_and_recursive_pattern.py 2 Excluded
temp/tests/Python/fable_modules/thoth_json_python/encode.py 2 Excluded

@dbrattli
dbrattli merged commit 5218693 into main Oct 14, 2026
44 checks passed
@dbrattli
dbrattli deleted the fix/python-await-task-cancellation branch October 14, 2026 18:14
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