Skip to content

Implement scheduling cancellation support for sagas#9490

Merged
PascalSenn merged 5 commits intomainfrom
pse/implement-scheduling-cancelaltion-support-for-sagas
Mar 31, 2026
Merged

Implement scheduling cancellation support for sagas#9490
PascalSenn merged 5 commits intomainfrom
pse/implement-scheduling-cancelaltion-support-for-sagas

Conversation

@PascalSenn
Copy link
Copy Markdown
Member

@PascalSenn PascalSenn commented Mar 30, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 30, 2026 22:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds saga-level support for cancelling previously scheduled messages when a saga reaches a final state, by capturing scheduling tokens during scheduled publish/send and cancelling them on completion.

Changes:

  • Capture scheduling cancellation tokens returned by IMessageBus.SchedulePublishAsync / ScheduleSendAsync and persist them on saga state.
  • Cancel captured tokens when entering a final saga state (with logging on failure).
  • Update/add saga scheduling tests and enhance the test message bus to issue/cancel tokens.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/Mocha/test/Mocha.Sagas.Tests/SagaSchedulingTests.cs Updates existing scheduling tests to assert schedule-token capture (instead of ScheduledTime options).
src/Mocha/test/Mocha.Sagas.Tests/SagaSchedulingCancellationTests.cs Adds new tests verifying tokens are captured and cancelled on saga completion.
src/Mocha/test/Mocha.Sagas.TestHelpers/TestMessageBus.cs Adds token generation for scheduled operations and records cancelled tokens.
src/Mocha/src/Mocha/Sagas/State/SagaStateBase.cs Introduces ScheduleTokens on saga state for persisted cancellation tokens.
src/Mocha/src/Mocha/Sagas/Saga.cs Implements token capture on scheduling and cancellation of tokens on final-state entry (with warning log on exception).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +400 to +404
if (state.ScheduleTokens is { Count: > 0 })
{
var bus = context.GetBus();
foreach (var token in state.ScheduleTokens)
{
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

After attempting cancellation, ScheduleTokens is left intact. If final-state handling is retried (e.g., store delete fails or the message is redelivered), the saga will attempt to cancel the same tokens again and keep persisting them unnecessarily. Consider removing tokens as they are successfully cancelled, or clearing the list once cancellation has been attempted (optionally keeping only failures).

Copilot uses AI. Check for mistakes.
@github-actions github-actions bot added the 📚 documentation This issue is about working on our documentation. label Mar 31, 2026
@PascalSenn PascalSenn merged commit 02c3e09 into main Mar 31, 2026
129 checks passed
@PascalSenn PascalSenn deleted the pse/implement-scheduling-cancelaltion-support-for-sagas branch March 31, 2026 19:09
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (c64226a) to head (a9e84d8).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@     Coverage Diff      @@
##   main   #9490   +/-   ##
============================
============================

☔ View full report in Codecov by Sentry.
📢 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation This issue is about working on our documentation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants