Skip to content

Add compensation workflow pattern example - #952

Merged
WhitWaldo merged 2 commits into
dapr:mainfrom
Babyy-dev:examples/workflow-compensation
Nov 21, 2026
Merged

WhitWaldo merged 2 commits into
dapr:mainfrom
Babyy-dev:examples/workflow-compensation

Conversation

@Babyy-dev

Copy link
Copy Markdown
Contributor

Description

Adds a JS example of the workflow compensation (saga) pattern, matching the Java SDK compensation example.

examples/workflow/authoring/src/compensation.ts books a flight, a hotel and a car. After each booking succeeds, its cancellation activity is added to a list. bookCar fails on purpose. Its failure surfaces as an error at the yield, so the workflow catches it and runs the registered cancellations in reverse order (hotel, then flight). Each cancellation gets a RetryPolicy, and a failed cancellation is logged without stopping the remaining ones. The workflow then completes with "Trip booking failed, compensation applied".

The example uses the same client and runtime setup as activity-sequence.ts, and logs from the workflow through the replay-safe ctx.logger.

Also:

  • start:compensation / start:dapr:compensation scripts in examples/workflow/authoring/package.json
  • a "Compensation example" section in the authoring README, linking the Java example and the workflow patterns docs

Issue reference

Please reference the issue this PR will close: #702

Checklist

  • Code compiles correctly: tsc on the authoring examples reports no errors in compensation.ts, and eslint and prettier pass.
  • Created/updated tests: example only. To check the behaviour, I ran the workflow through the SDK's OrchestrationExecutor with a history of flight ✓, hotel ✓, car ✗. It scheduled cancelHotel, then cancelFlight, then completed with the compensation result. Happy to add that as a unit test if useful.
  • Extended the documentation: README section added.

Signed-off-by: Babyy-dev <rishabh1raj567@gmail.com>
@Babyy-dev
Babyy-dev requested review from a team as code owners November 20, 2026 16:44

@WhitWaldo WhitWaldo 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.

Looks good to me - thank you for your contribution!

@WhitWaldo
WhitWaldo added this pull request to the merge queue Nov 21, 2026
@WhitWaldo
WhitWaldo removed this pull request from the merge queue due to a manual request Nov 21, 2026
@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.48%. Comparing base (00aa5a9) to head (bf96a85).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #952   +/-   ##
=======================================
  Coverage   85.48%   85.48%           
=======================================
  Files         160      160           
  Lines        5884     5884           
  Branches     1222     1222           
=======================================
  Hits         5030     5030           
  Misses        664      664           
  Partials      190      190           
Flag Coverage Δ
e2e 21.53% <ø> (ø)
unit 85.31% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@WhitWaldo
WhitWaldo merged commit d92e1a6 into dapr:main Nov 21, 2026
9 of 10 checks passed
@marcduiker

Copy link
Copy Markdown
Contributor

@holopin-bot @Babyy-dev sdk-badge Thank you! Here's a digital badge as a small token of appreciation.

@holopin-bot

holopin-bot Bot commented Nov 23, 2026

Copy link
Copy Markdown

Congratulations @Babyy-dev, the maintainer of this repository has issued you a badge! Here it is: https://holopin.io/claim/cmwt2xx9l0003l308ukv55kvd

This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account.
Or if you're new to Holopin, you can simply sign up with GitHub, which will do the trick!

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.

Add Compensation Workflow Pattern Example

3 participants