Skip to content

Conversation

Sushisource
Copy link
Member

What was changed

Added the annotations and options for worker-deployment-based versioning

Why?

All aboard the versioning train

Checklist

  1. Closes [Feature Request] Support New Worker Versioning API #1659

  2. How was this tested:
    Added tests

  3. Any docs updates needed?

@Sushisource Sushisource requested a review from a team as a code owner April 15, 2025 23:58
Copy link
Contributor

@THardy98 THardy98 left a comment

Choose a reason for hiding this comment

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

Didn't really look through the core bridge stuff, maybe worth coordinating on #1638.

For your workflow test files deployment-versioning-no-annotations... there's a workflows directory in test/src that might make more sense for them to be located, instead of directly in test/src.

Just want to re-affirm how this works:

  • on the worker, we have the worker's configured deployment version, and the default versioning behaviour for all its workflows
  • on the workflow, we can override this versioning behaviour with the newly added workflow definition options (it's a little funky, we're making use of JS's quirk that a function is an object, so a workflow with definition options is a function with properties, as already discussed)
  • workflow versioning behaviour is read into the activator (which uses it solely when concluding the activation) and workflow info

Tests were helpful, though I think you probably want someone whose more familiar with the versioning behaviour to take a look

@Sushisource Sushisource force-pushed the worker-deployment-versioning branch 4 times, most recently from a120422 to e59e2d0 Compare April 18, 2025 23:33
@Sushisource Sushisource force-pushed the worker-deployment-versioning branch from a8d4a69 to f18b1ca Compare April 24, 2025 00:00
@Sushisource
Copy link
Member Author

This will need to hang out for a bit since I want temporalio/api#579 in before I incorporate that

@Sushisource Sushisource force-pushed the worker-deployment-versioning branch 2 times, most recently from 218743e to 8169797 Compare May 2, 2025 01:06
@Sushisource Sushisource force-pushed the worker-deployment-versioning branch 4 times, most recently from e79e306 to 3ee553e Compare May 9, 2025 21:27
/**
* A workflow function that has been defined with options from {@link WorkflowDefinitionOptions}.
*/
export interface WorkflowFunctionWithOptions<Args extends any[], ReturnType> extends AsyncFunction<Args, ReturnType> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this have any value being exported publicly? If yes, then AsyncFunction should also be exported. If not, then please add @internal and @hidden (I will have to experiment a bit more to figure out how to reduce this to a single annotation, but in the mean time, let's use both).

@Sushisource Sushisource force-pushed the worker-deployment-versioning branch from 0382bdf to 48bbb74 Compare May 14, 2025 22:05
@Sushisource Sushisource force-pushed the worker-deployment-versioning branch 2 times, most recently from 4c67a37 to ee0f8ed Compare May 15, 2025 17:07
@Sushisource Sushisource force-pushed the worker-deployment-versioning branch from ee0f8ed to 129ab88 Compare May 15, 2025 17:16
@Sushisource Sushisource force-pushed the worker-deployment-versioning branch from 9209367 to f60c0a0 Compare May 15, 2025 21:52
@@ -1227,6 +1227,7 @@ export class WorkflowClient extends BaseClient {
cronSchedule: options.cronSchedule,
header: { fields: headers },
priority: options.priority ? compilePriority(options.priority) : undefined,
versioningOverride: options.versioningOverride ? options.versioningOverride : undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
versioningOverride: options.versioningOverride ? options.versioningOverride : undefined,
versioningOverride: options.versioningOverride ?? undefined,

@@ -1296,6 +1297,7 @@ export class WorkflowClient extends BaseClient {
cronSchedule: opts.cronSchedule,
header: { fields: headers },
priority: opts.priority ? compilePriority(opts.priority) : undefined,
versioningOverride: opts.versioningOverride ? opts.versioningOverride : undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
versioningOverride: opts.versioningOverride ? opts.versioningOverride : undefined,
versioningOverride: opts.versioningOverride ?? undefined,

@@ -80,9 +80,27 @@ export function initRuntime(options: WorkflowCreateOptionsInternal): void {
const defaultWorkflowFn = mod['default'];

if (typeof workflowFn === 'function') {
activator.workflow = workflowFn;
if (isWorkflowFunctionWithOptions(workflowFn)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like those two branches are identical, and in both branches, you ned up making the assignment to activator.workflow anyway. I'd suggest reverting to the original if-elseif-else structure, and move the "workflow definition options" stuff after that whole block.

Copy link
Contributor

@mjameswh mjameswh left a comment

Choose a reason for hiding this comment

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

Still a few nits, but no need for another round of review after that. You can safely ignore the unrelated test failures on the feature repo due to protobufjs, as well as the doc publish error due to vercel token needing refresh.

@Sushisource Sushisource force-pushed the worker-deployment-versioning branch from fd9e99c to bc6157f Compare May 16, 2025 16:24
@Sushisource Sushisource merged commit 9aae0d2 into main May 16, 2025
25 of 27 checks passed
@Sushisource Sushisource deleted the worker-deployment-versioning branch May 16, 2025 16:42
@SamuelMS
Copy link

SamuelMS commented Aug 13, 2025

@Sushisource @mjameswh defaultVersioningBehavior is a mandatory option in workerDeploymentOptions, but undefined and UNSPECIFIED aren't accepted as documented here: TS SDK docs and 1.11.5 release

TypeScript sample snippet from the docs:

const myWorker = await Worker.create({
  workflowsPath: require.resolve('./workflows'),
  taskQueue,
  workerDeploymentOptions: {
    useWorkerVersioning: true,
    version: { buildId: '1.0', deploymentName: 'llm_srv' },
    // does not work
    defaultVersioningBehavior: 'UNSPECIFIED',
  },
  connection: nativeConnection,
});

In my use-case, I actually want to set useWorkerVersioning to false – to ignore versioning entirely, but to have online workers self-report in the workflow deployments section of the UI regardless.

TypeScript throws e.g. TS2322: Type undefined is not assignable to type VersioningBehavior, and at runtime you get e.g. Error: Unknown versioning behavior: UNSPECIFIED. Excluding defaultVersioningBehavior entirely throws temporal_sdk_core::worker::workflow: Error while completing workflow activation error=status: InvalidArgument, message: "versioning behavior cannot be specified without deployment options being set with versioned mode", details: [], metadata: MetadataMap { headers: {"content-type": "application/grpc"} } when workflows run.

Let me know if I'm misinterpreting how this is intended to be used, or if you'd like a dedicated issue raised for this.

Thank you!

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.

[Feature Request] Support New Worker Versioning API
6 participants