Add patch activation callback#2193
Open
Sushisource wants to merge 3 commits into
Open
Conversation
Sushisource
force-pushed
the
patch-activation-callback
branch
4 times, most recently
from
July 15, 2026 17:29
147c980 to
fcbce92
Compare
Sushisource
force-pushed
the
patch-activation-callback
branch
from
July 15, 2026 17:59
fcbce92 to
5b33dd4
Compare
cconstable
reviewed
Jul 16, 2026
| // ts-prune-ignore-next (used by the workflow Worker thread entry point) | ||
| export function waitForPatchActivationCallbackResult(resultBuffer: SharedArrayBuffer): boolean { | ||
| const header = getHeader(resultBuffer); | ||
| Atomics.wait(header, 0, PatchActivationCallbackStatus.Pending); |
Contributor
There was a problem hiding this comment.
This is waiting on user-supplied logic right? So what happens if it hangs and never returns? I'm guessing the workflow times out but does that cause other things running on this worker to stall as well? Might be fine but worth checking.
Member
Author
There was a problem hiding this comment.
Good point can add a test
Sushisource
marked this pull request as ready for review
July 16, 2026 23:17
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
Added an experimental
WorkerOptions.patchActivationCallbackthat lets a worker decide whether the first newly encountered, non-replaypatchedcall activates a patch.The callback receives frozen workflow information and the patch ID. Its strict boolean decision is memoized for the workflow run. Declined patches return
falsewithout recording a marker, while replay, existing history markers, and deprecated patches retain their existing behavior.Because Workflow code normally executes in worker threads while
patchedis synchronous, the implementation uses a scoped synchronous worker-thread bridge based onSharedArrayBufferandAtomics. The callback closure stays on the Worker side and is never serialized or evaluated from source.This ports the behavior introduced by temporalio/sdk-ruby#481.
Why?
This allows workflow changes using
patchedto roll out gradually without every new-code worker immediately recording a marker that older workers cannot replay.Testing