Skip to content

Add patch activation callback#782

Merged
Sushisource merged 3 commits into
mainfrom
patch-activation-callback
Jul 18, 2026
Merged

Add patch activation callback#782
Sushisource merged 3 commits into
mainfrom
patch-activation-callback

Conversation

@Sushisource

@Sushisource Sushisource commented Jul 10, 2026

Copy link
Copy Markdown
Member

What was changed

Added an experimental TemporalWorkerOptions.PatchActivationCallback that lets a worker decide whether the first newly encountered, non-replay Workflow.Patched call activates a patch.

The callback receives workflow information and the patch ID. Its 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.

This ports the behavior introduced by temporalio/sdk-ruby#481.

The work is intentionally split into two commits:

  1. Add patch activation callback contains only the callback API, plumbing, activation semantics, and rollout tests.
  2. Harden read-only workflow contexts makes the callback read-only and completes the workflow context's read-only enforcement. This includes guarding nested patches, workflow metadata and handler mutation, continue-as-new, and patch calls from queries and update validators.

Note

We can drop the second commit if it feels like too much to put in the PR, but, it's done and I think adds some nice safety.

Why?

This allows workflow changes using Workflow.Patched to roll out gradually without every new-code worker immediately recording a marker that older workers cannot replay.

Keeping the read-only hardening in a subsequent commit separates the callback's intended behavior from the broader workflow-context consistency fixes discovered during review.

Testing

  • .NET SDK build across all target frameworks with zero warnings
  • First callback-only commit independently formatted and tested
  • 21 focused callback, read-only, mutation, handler, query, and update-validator cases
  • Changed-file formatting verification
  • Diff and sdk-core submodule cleanliness checks

@jmaeagle99 jmaeagle99 self-assigned this Jul 11, 2026
@Sushisource
Sushisource force-pushed the patch-activation-callback branch 3 times, most recently from 81323b6 to 8399fc4 Compare July 15, 2026 17:21
@Sushisource
Sushisource marked this pull request as ready for review July 15, 2026 17:44
@Sushisource
Sushisource requested a review from a team as a code owner July 15, 2026 17:44
@Sushisource
Sushisource force-pushed the patch-activation-callback branch from 8399fc4 to 5292791 Compare July 17, 2026 18:48

@jmaeagle99 jmaeagle99 left a comment

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.

Few minor comments but looks good overall.

Comment thread CHANGELOG.md Outdated
connections now compress outbound requests and accept gzip-compressed responses by default. If the remote
service does not support gzip compression, the connection is downgraded to uncompressed requests. Set it
to `GrpcCompression.None` to opt out.
- Added AWS Lambda worker support packages, including OpenTelemetry helpers for Lambda workers.

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.

Looks to be accidentally duplicated. Please remove.

Comment thread CHANGELOG.md Outdated
service does not support gzip compression, the connection is downgraded to uncompressed requests. Set it
to `GrpcCompression.None` to opt out.
- Added AWS Lambda worker support packages, including OpenTelemetry helpers for Lambda workers.
- Added the experimental `TemporalWorkerOptions.PatchActivationCallback`, allowing workers to

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.

Please move to Unreleased section.

/// <inheritdoc/>
public void AssertNotReadOnly(string operation)
{
if (contextFrozen || inQueryOrValidator)

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.

I think the hardening is fine to add, but maybe add something in the changelog to raise that this is intentionally being checked, especially for queries and validators.

Comment thread src/Temporalio/Worker/WorkflowInstance.cs Outdated
@Sushisource
Sushisource force-pushed the patch-activation-callback branch from 5292791 to 811a664 Compare July 17, 2026 23:05
@Sushisource
Sushisource enabled auto-merge (squash) July 17, 2026 23:05
@Sushisource
Sushisource force-pushed the patch-activation-callback branch from 811a664 to ea7e71a Compare July 18, 2026 00:44
@Sushisource
Sushisource merged commit d497a9a into main Jul 18, 2026
10 checks passed
@Sushisource
Sushisource deleted the patch-activation-callback branch July 18, 2026 01:03
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