Skip to content

Add trampolining API for versioned continue-as-new#2216

Open
THardy98 wants to merge 5 commits intomasterfrom
pr/trampolining
Open

Add trampolining API for versioned continue-as-new#2216
THardy98 wants to merge 5 commits intomasterfrom
pr/trampolining

Conversation

@THardy98
Copy link
Contributor

@THardy98 THardy98 commented Mar 5, 2026

Summary

  • Add dedicated GetTargetWorkflowDeploymentVersionChanged() on WorkflowInfo for detecting when a workflow's target deployment version has changed
  • Add ContinueAsNewVersioningBehavior type with AutoUpgrade option for ContinueAsNewError/ContinueAsNewErrorOptions
  • Add ContinueAsNewSuggestedReason enum and GetContinueAsNewSuggestedReasons() on WorkflowInfo
  • Add test suite support via SetContinueAsNewSuggestedReasons() and SetTargetWorkflowDeploymentVersionChanged()
  • Integration test demonstrating the full trampolining flow (v1 pinned workflow detects version change → CAN with AutoUpgrade → completes on v2)

How this differs from #2171

This PR implements the API change from temporalio/api#709, which replaces the approach in #2171.

Problem with #2171's approach: It expanded SuggestContinueAsNew with a TargetWorkerDeploymentVersionChanged reason. Users with existing if suggestContinueAsNew { doCAN() } code in Pinned workflows would get stuck in infinite CAN loops, since the default CAN behavior for Pinned workflows is to stay Pinned on the same version.

This PR's approach: Adds a separate targetWorkerDeploymentVersionChanged boolean flag on WorkflowInfo, keeping version-change detection completely independent from the continue-as-new-suggested mechanism. This makes upgrade-on-CAN fully opt-in on both the detection and action sides:

  • Detection: workflows must explicitly check GetTargetWorkflowDeploymentVersionChanged()
  • Action: workflows must explicitly pass InitialVersioningBehavior: ContinueAsNewVersioningBehaviorAutoUpgrade

Part of: temporalio/features#738

Test plan

  • Integration test TestContinueAsNewWithVersionUpgrade validates full trampolining flow
  • Unit compilation check

🤖 Generated with Claude Code

@THardy98 THardy98 requested a review from a team as a code owner March 5, 2026 20:33
Copy link
Contributor

@carlydf carlydf left a comment

Choose a reason for hiding this comment

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

approved once a few comments that still reference the previous trampolining implementation are fixed

- ContinueAsNewVersioningBehavior/InitialVersioningBehavior: "Upgrade-on-Continue-as-New is currently experimental"
- ContinueAsNewSuggestedReason: "ContinueAsNewSuggestedReasons are currently experimental"
- Update test comment to reflect new GetTargetWorkflowDeploymentVersionChanged() API

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@THardy98 THardy98 requested a review from carlydf March 6, 2026 17:55
Copy link
Contributor

@yuandrew yuandrew left a comment

Choose a reason for hiding this comment

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

Requested small docs improvements, but looks good otherwise

// If the source workflow was Pinned, the new workflow will start Pinned to the same Build ID.
// If the source workflow had a Pinned Versioning Override, the new workflow will inherit that Versioning Override.
//
// Exposed as: [go.temporal.io/sdk/workflow.ContinueAsNewVersioningBehaviorUnspecified]
Copy link
Contributor

Choose a reason for hiding this comment

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

This "Exposed as:" should be only on internal/ files. Please remove any instances in this file

// first workflow task completes, use whatever Versioning Behavior the workflow is annotated with in the workflow
// code.
//
// Note that if the previous workflow had a Pinned override, that override will be inherited by the new workflow
Copy link
Contributor

@yuandrew yuandrew Mar 6, 2026

Choose a reason for hiding this comment

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

Should we do Note: here to match the other notes?

// GetContinueAsNewSuggestedReasons returns a list of reasons why continue as new is suggested,
// if the server is configured to suggest continue as new and it is suggested.
// This value may change throughout the life of the workflow.
// Note: ContinueAsNewSuggestedReasons are currently experimental.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a extra empty // line so the Note renders on a separate line?


const (
// ContinueAsNewSuggestedReasonUnspecified - The reason is unknown.
// Exposed as: [go.temporal.io/sdk/workflow.ContinueAsNewSuggestedReasonUnspecified]
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have an extra // line to the "Exposed as" line renders as its own line? I should probably make the doclink tool enforce this

Copy link
Contributor

Choose a reason for hiding this comment

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

Both here and in all of the other places in this file

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