Skip to content

Add patch activation callback#2193

Open
Sushisource wants to merge 3 commits into
mainfrom
patch-activation-callback
Open

Add patch activation callback#2193
Sushisource wants to merge 3 commits into
mainfrom
patch-activation-callback

Conversation

@Sushisource

Copy link
Copy Markdown
Member

What was changed

Added an experimental WorkerOptions.patchActivationCallback that lets a worker decide whether the first newly encountered, non-replay patched call 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 false without recording a marker, while replay, existing history markers, and deprecated patches retain their existing behavior.

Because Workflow code normally executes in worker threads while patched is synchronous, the implementation uses a scoped synchronous worker-thread bridge based on SharedArrayBuffer and Atomics. 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 patched to roll out gradually without every new-code worker immediately recording a marker that older workers cannot replay.

Testing

  • Worker, Workflow, and test TypeScript builds
  • Focused runtime suite: 7 cases
  • Live rolling-worker integration suite: 2 cases
  • Focused ESLint and Prettier checks
  • Diff and sdk-core submodule cleanliness checks

@Sushisource
Sushisource force-pushed the patch-activation-callback branch 4 times, most recently from 147c980 to fcbce92 Compare July 15, 2026 17:29
@Sushisource
Sushisource force-pushed the patch-activation-callback branch from fcbce92 to 5b33dd4 Compare July 15, 2026 17:59
// 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);

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.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point can add a test

@Sushisource
Sushisource marked this pull request as ready for review July 16, 2026 23:17
@Sushisource
Sushisource requested a review from a team as a code owner July 16, 2026 23:17
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.

2 participants