fix: propagate cancellation to scopes and awaits registered after cancel#770
Open
xepozz wants to merge 3 commits into
Open
fix: propagate cancellation to scopes and awaits registered after cancel#770xepozz wants to merge 3 commits into
xepozz wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c731fe147
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Scope cancellation was a one-shot pass over the onCancel handlers: any cancellation-aware resource registered after cancel() had already run was never notified. As a result a nested scope created under an already cancelled parent was born uncancelled, and an await registered in an already cancelled scope blocked forever (the workflow got stuck). Introduce a register-or-fire-immediately helper (addOnCancel) used by the public onCancel(), onAwait() and createScope(); store the cancellation reason so late handlers receive it; and guard onException()/onResult() against a double close pass. This matches the Go/Java/TS SDKs, where cancellation is sticky and observed at registration time. Adds acceptance tests covering nested-scope inheritance, fail-fast await, the public onCancel hook, and a faithful replica of the issue reproduction (each one hangs without the fix). Fixes #769
4c731fe to
1540624
Compare
Make the sticky scope-cancellation behavior opt-in via FeatureFlags::$propagateCancellationToNewScopes (default false = previous behavior). When enabled, a nested scope, await or onCancel handler registered after the surrounding scope was already cancelled is notified immediately instead of being missed. - Scope reads the flag at addOnCancel() and nextPromise(). - Acceptance suite enables it in RuntimeBuilder::init() alongside the other flags. - Add a unit test covering both flag states.
wolfy-j
approved these changes
Jun 26, 2026
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.
What was changed
Made scope cancellation sticky so nested scopes and awaits registered after cancel() are notified immediately instead of being missed.
Why?
Matches Go/Java/TS behaviour. Fixes #769.
Checklist
Closes [Bug] Cancellation is not propagated to scopes and awaits registered after cancellation #769
How was this tested: