dapr / dapr/js-sdk

feat(workflows): Add workflow versioning patch support

Open
#799 0 comments 0 reactions 0 assignees View on GitHub
area/workflow enhancement sdk-parity
Dominant language
JavaScript
Stars
217
Forks
104
PR merge metrics
No merged PRs in 30d

Description

## Summary

Implement patch-based workflow versioning in the Dapr JS SDK, allowing developers to make backward-compatible changes to running workflow definitions without breaking in-flight instances.

## Background

When a workflow definition is modified after instances are already running, replaying the history of those instances against the new code can produce non-determinism errors. Patch-based versioning solves this by allowing developers to branch logic based on whether an instance was started before or after a change.

This is sometimes called "version gates" — a mechanism to say "if this instance has already passed this point in execution, use the old logic; otherwise, use the new logic."

## Proposed API

```typescript
// In WorkflowContext:

/**
* Returns true if the current instance should execute the new code path
* identified by `patchName`. Returns false for instances that were started
* before this patch was introduced (to preserve replay compatibility).
*/
isPatched(patchName: string): boolean;
```
## Usage Example
```ts
function* myWorkflow(ctx: WorkflowContext, input: OrderInput) {
// Original logic:
const result = yield ctx.callActivity(processOrder, input);

// Added later — new validation step. Old in-flight instances skip this.
if (ctx.isPatched("add-validation-step")) {
yield ctx.callActivity(validateOrder, result);
}

yield ctx.callActivity(shipOrder, result);
}
```

## Acceptance Criteria
- [ ] WorkflowContext.isPatchEnabled(patchName: string): boolean is implemented
- [ ] In-flight instances that have never seen the patch name return false
- [ ] New instances or instances that haven't yet reached the patch point return true
- [ ] The patch is recorded in the orchestration history so subsequent replays are deterministic
- [ ] Unit and e2e tests cover both old-instance and new-instance paths
- [ ] Documentation with usage examples

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.