Repository navigation
Conversation
dbrattli
merged commit Oct 15, 2026
18ce662
into
fix/async-cleanup-generic-continuations
8 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@dbrattli Here is what I found while reviewing #5062
Summary
Fixes async cleanup ordering and generic unit continuations in the Python runtime, with the same
fixes mirrored in the TypeScript runtime where they applied.
Runtime fixes (Python and TypeScript)
TryFinallyandUsinginstall the cleanup continuation before the cancellation checkpoint, so apre-cancelled token still runs compensation.
TryFinallyclaims settlement under a lock in Python;on_cancelcan arrive from another threadwhile
on_successruns on the loop.Trampolinegains acompletedflag (Python now matches TypeScript). After a terminal continuationruns, exceptions thrown by continuation code propagate instead of being routed back to
on_error,which previously re-entered a succeeded
try/withhandler.protected_bindandTryWithonly guard the binder or handler evaluation, not the resultingcomputation.
from_continuationsrejects a second completion withInvalidOperationException, matching .NET.from_continuations_unitis now built on top of it and shares the guard.MailboxProcessor.PostAndAsyncReplydelivers exactly once when the reply races with the poster'sstart, and ignores a second
Reply, matching .NETAsyncReplyChannel.Trampoline.runonly looks up the event loop on the hijack path and runs inline when no loopis running.
Python compiler
unitare wrapped witherase_unit_callableso Pyright accepts the erased unit argument. This now also covers spread (
ParamArray) calls,curried applications, and calls to local generic functions.
uncurryApplicationsemits empty signature types and the identifier type is already instantiated). The Python
Contextnow records declared lambda types atLet/LetRecand uses them as a fallback.