Skip to content

Update Workflow/Activity priority - #8396

Merged
yiminc merged 10 commits into
temporalio:mainfrom
stephanos:update-prio
Dec 2, 2025
Merged

Update Workflow/Activity priority#8396
yiminc merged 10 commits into
temporalio:mainfrom
stephanos:update-prio

Conversation

@stephanos

@stephanos stephanos commented Sep 29, 2025

Copy link
Copy Markdown
Contributor

What changed?

Allow updating priority of Workflow and Activity.

Based on

Why?

Users want to change the priority after starting the workflow/activity.

How did you test it?

  • built
  • run locally and tested manually
  • covered by existing tests
  • added new unit test(s)
  • added new functional test(s)

@stephanos
stephanos force-pushed the update-prio branch 4 times, most recently from 36fa1b9 to 4646a2d Compare October 2, 2025 03:47
@stephanos
stephanos changed the base branch from main to stamp October 2, 2025 03:47
@stephanos
stephanos changed the base branch from stamp to main October 2, 2025 03:48
@stephanos stephanos mentioned this pull request Oct 2, 2025
5 tasks
@stephanos
stephanos force-pushed the update-prio branch 4 times, most recently from 3b6b5ac to 1e9ae2f Compare October 2, 2025 14:58
errorMessage := fmt.Sprintf(
"Activity task with this stamp not found. Id: %s,: type: %s, current stamp: %d",
ai.ActivityId, ai.ActivityType.Name, ai.Stamp)
return nil, rejectCodeUndefined, serviceerror.NewNotFound(errorMessage)
return nil, rejectCodeUndefined, serviceerrors.NewObsoleteMatchingTask(errorMessage)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This seems much more consistent and a better error type, too.

@stephanos
stephanos force-pushed the update-prio branch 2 times, most recently from e7581c5 to 1c4b8b8 Compare October 2, 2025 16:36
@stephanos
stephanos changed the base branch from main to workflow-task-stamp October 2, 2025 16:37
@stephanos
stephanos force-pushed the update-prio branch 3 times, most recently from 5578ed9 to 69d768f Compare October 2, 2025 16:40
@stephanos
stephanos marked this pull request as ready for review October 2, 2025 16:40
@stephanos
stephanos requested a review from a team as a code owner October 2, 2025 16:40
@stephanos
stephanos force-pushed the update-prio branch 6 times, most recently from 552b4d7 to 288a3c2 Compare October 3, 2025 19:07
Comment on lines +244 to +246
if _, ok := updateFields["retryPolicy"]; ok {
mergeInto.RetryPolicy = mergeFrom.RetryPolicy
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This seems like a reasonable addition to me.

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 guess so. I was originally a little confused at the semantics, but it seems reasonable, to allow updating a whole sub-object without listing all the fields

s.NotNil(descResp.GetPendingActivities())
s.Len(descResp.GetPendingActivities(), 1)
s.ProtoEqual(updatedPriority, descResp.GetPendingActivities()[0].GetPriority())
s.ProtoEqual(updatedPriority, descResp.GetPendingActivities()[0].GetActivityOptions().GetPriority())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Other activity options appear to always match the activity's fields 1:1.

@@ -148,6 +148,7 @@ func processActivityOptionsUpdate(
ScheduleToStartTimeout: ai.ScheduleToStartTimeout,
StartToCloseTimeout: ai.StartToCloseTimeout,
HeartbeatTimeout: ai.HeartbeatTimeout,
Priority: ai.Priority,

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.

hmm, this is mergeInto, so mergeActivityOptions will write directly into ai.Priority?
shouldn't we expand it like RetryPolicy? or use common.CloneProto (on both)?

@stephanos stephanos Nov 12, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good call 👍 (there is no ai.RetryPolicy, though)

Comment on lines +244 to +246
if _, ok := updateFields["retryPolicy"]; ok {
mergeInto.RetryPolicy = mergeFrom.RetryPolicy
}

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 guess so. I was originally a little confused at the semantics, but it seems reasonable, to allow updating a whole sub-object without listing all the fields

Comment on lines +137 to +139
if prio, ok := proto.Clone(priority).(*commonpb.Priority); ok {
opts.Priority = prio
}

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.

Suggested change
if prio, ok := proto.Clone(priority).(*commonpb.Priority); ok {
opts.Priority = prio
}
opts.Priority = common.CloneProto(priority)

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.

(and change the one on line 130 also)

@@ -155,5 +188,10 @@ func mergeWorkflowExecutionOptions(
}
mergeInto.VersioningOverride = mergeFrom.GetVersioningOverride()
}

if _, ok := updateFields["versioningOverride"]; ok {

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.

move this one before the ones that do sub-fields so they're consistent? (even though it doesn't matter in this case)

}

if _, ok := updateFields["priority.priorityKey"]; ok {
mergeInto.Priority = cmp.Or(mergeInto.Priority, &commonpb.Priority{})

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.

hmm, maybe this should do an if like the updateactivityoptions one to avoid the extra allocation? (I'm not sure it does an extra allocation but it looks like it)

if you want a generic helper to initialize a pointer if it's nil, I'd be okay with that. I've wanted it in various places but it feels a little un-go-like so I've just done if statements or local helpers

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

let's go with a simple if 👍

Stamp: task.event.Data.GetStamp(),
Priority: task.event.Data.GetPriority(),

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.

keep them in the same order as the declaration?

}
}
s.Equal(1+obsoleteWorkflowTaskCount, obsoleteActivityTaskCount, "Expected 1 activity task to be obsolete")
}

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.

nice test, clear and thorough. the metrics stuff doesn't add any flakiness, I hope?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't expect any; it's all in-memory and only checked in latency insensitive places AFAICT

@stephanos
stephanos force-pushed the update-prio branch 17 times, most recently from 0991911 to 1a3b5f2 Compare December 2, 2025 01:14
@stephanos
stephanos enabled auto-merge (squash) December 2, 2025 01:15
@stephanos
stephanos disabled auto-merge December 2, 2025 16:06
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.

3 participants