Skip to content

feat(durable-messaging): add envelope and routing contracts - #11282

Open
ReubenBond wants to merge 22 commits into
dotnet:mainfrom
ReubenBond:rb-probable-train
Open

ReubenBond wants to merge 22 commits into
dotnet:mainfrom
ReubenBond:rb-probable-train

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

Problem

Durable Messaging needs shared envelope, routing and handler contracts so inbox, outbox and hosting can be reviewed as focused layers.

Solution

Provide serialized envelopes, hierarchical correlation keys, delivery outcomes, validated options, inbox/outbox interfaces and typed handler-routing helpers in the eventual Microsoft.Orleans.DurableMessaging assembly.

Outgoing messages use explicit preparation before shared state changes. IDurableOutbox.PrepareSendAsync(IReadOnlyList<DurableEnvelope>, CancellationToken) copies and validates outgoing intents and acquires their durable wakeup prerequisite. It returns an opaque, activation-local IPreparedOutboxBatch : IDisposable; synchronous Send(IPreparedOutboxBatch) stages the prepared output.

Handlers use PrepareAsync -> ValueTask<Action>: await preparation through context.Outbox, then apply complete business mutations and send the batch from the matching synchronous action. Ordinary callers await each preparation and retain/dispose its batch through the mutation and ordinary journal-write scope. Runtime layers own started acquisitions, late results, actual persistence outcomes and delivery eligibility. Duplicate sends coalesce within their valid scope; caller cancellation preserves owned scheduling through completion.

Rationale and scope

Preparation, synchronous safe-to-commit updates and ordinary atomic journal writes keep application policy with its owner. The Journaling foundation retains its established public API and capture/replay/reset/acknowledgement protocol. A failed initial recovery completes that attempt with its original error and leaves the manager uninitialized. A subsequent explicit InitializeAsync resets and replays the existing instances from the beginning; writes become available after successful recovery. One lifetime work-loop task handles recovery attempts and persistence. After a failed attempt, that same task waits for a queued explicit initialization request; stale signals are consumed while it waits. Initialization admission and owner shutdown are serialized under the manager lock. Registration stays closed after initialization begins, and admitted persistence failures retain terminal handling. Feature owners handle failed writes and cleanup directly. Deletion follows the explicit owner workflow: stop and drain messaging, await actual journal deletion, then dispose or deactivate; subsequent work uses a fresh owner.

This intermediate project stays non-packable while runtime and hosting are assembled. Envelope aliases/member IDs, routing, payload metadata and the DeliverAsync wire manifest are preserved. Contract tests retain the external-consumer boundary and exercise internal adapters through public interfaces and reflection.

Depends on #11326 at 901d42432a8e7daa1308aa7a232f02e3f1adc67a, based on selected main 0bfd95e8561699b3bb7c619b0b0d2378d84395bc. Published head: fb911fa47667b91215371d9f43298c5178619de0; all eleven contracts commits remain equivalent. Review the immutable incremental diff. Inbox, outbox and final composition follow in #11284, #11285 and #10693.

Microsoft Reviewers: Open in CodeFlow

Copilot AI lite review requested due to automatic review settings September 16, 2026 21:43

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Five unresolved findings remain, including two critical HierarchicalKey issues.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 High severity · 1 Medium severity

Open (3)
What changed in this PR

Adds durable messaging contracts, routing helpers, and Journaling lifecycle support for future inbox/outbox runtime layers.

Changes:

  • Adds envelopes, hierarchical keys, delivery outcomes, options, and inbox/outbox interfaces.
  • Adds routing handlers and Journaling observer/participant support.
  • Adds tests, API surfaces, and project/solution wiring.
File Reviewed change
test/​Orleans.Journaling.Tests/​StateManagerTests.cs Tests observer boundaries and recovery fencing.
test/​Orleans.Journaling.Tests/​JournaledGrainParticipantTests.cs Tests participant lifecycle integration.
test/​Orleans.DurableMessaging.Tests/​Orleans.DurableMessaging.Tests.csproj Configures messaging contract tests.
test/​Orleans.DurableMessaging.Tests/​Contracts/​HierarchicalKeyTests.cs Tests hierarchical key behavior.
test/​Orleans.DurableMessaging.Tests/​Contracts/​HandlerRoutingContractTests.cs Tests routing and typed handlers.
test/​Orleans.DurableMessaging.Tests/​Contracts/​DurableEnvelopeContractTests.cs Tests envelope serialization and validation.
test/​Orleans.DurableMessaging.Tests/​Contracts/​DeliveryAndOptionsContractTests.cs Tests delivery results and options.
src/​Orleans.Journaling/​JournaledStateManager.cs Implements observers and recovery generations.
src/​Orleans.Journaling/​IJournaledStateObserver.cs Defines observer callbacks.
src/​Orleans.Journaling/​IJournaledStateManager.cs Adds observer registration. Finding: moderate (1 vote) — null observers are not validated before the compatibility default throws NotSupportedException.
src/​Orleans.Journaling/​IJournaledGrainParticipant.cs Defines grain participants.
src/​Orleans.Journaling/​DurableGrain.cs Initializes participants during activation.
src/​Orleans.DurableMessaging/​RoutePrefixHandler.cs Implements prefix routing.
src/​Orleans.DurableMessaging/​RouteKeyHandler.cs Implements exact routing.
src/​Orleans.DurableMessaging/​README.md Documents messaging contracts.
src/​Orleans.DurableMessaging/​Orleans.DurableMessaging.csproj Defines the intermediate project.
src/​Orleans.DurableMessaging/​InboxHandlerSelectionContext.cs Provides read-only selection context.
src/​Orleans.DurableMessaging/​InboxHandlerContext.cs Implements handler messaging context.
src/​Orleans.DurableMessaging/​IInboxHandlerContext.cs Defines handler context APIs.
src/​Orleans.DurableMessaging/​IInboxHandler.cs Defines typed and untyped handlers.
src/​Orleans.DurableMessaging/​IDurableOutbox.cs Defines outbox contracts.
src/​Orleans.DurableMessaging/​IDurableInboxExtension.cs Defines the grain delivery extension.
src/​Orleans.DurableMessaging/​IDurableInbox.cs Defines inbox contracts.
src/​Orleans.DurableMessaging/​HierarchicalKey.cs Implements hierarchical correlation keys. Findings: moderate (3 votes) — null overload inputs can produce NullReferenceException; critical (1 vote) — child-key enumeration reverses chain order; critical (1 vote) — HashCode.AddBytes is unavailable for the net8.0 target.
src/​Orleans.DurableMessaging/​DurableEnvelopeData.cs Stores deferred serialized data.
src/​Orleans.DurableMessaging/​DurableEnvelopeBuilder.cs Builds serialized envelopes. Finding: moderate (1 vote) — default SenderId can create an invalid deduplication identity.
src/​Orleans.DurableMessaging/​DurableEnvelope.cs Defines the envelope model.
src/​Orleans.DurableMessaging/​DeliveryStatus.cs Defines delivery statuses.
src/​Orleans.DurableMessaging/​DeliveryResult.cs Defines delivery outcomes.
src/​Orleans.DurableMessaging/​CorrelationHandler.cs Implements correlation routing.
src/​Orleans.DurableMessaging/​Configuration/​DurableInboxOptions.cs Defines validated messaging options.
src/​api/​Orleans.Journaling/​Orleans.Journaling.cs Updates the Journaling API surface.
src/​api/​Orleans.DurableMessaging/​Orleans.DurableMessaging.cs Adds the messaging API surface.
Orleans.slnx Registers source and test projects.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Orleans.DurableMessaging/HierarchicalKey.cs
Comment thread src/Orleans.DurableMessaging/HierarchicalKey.cs
Comment thread src/Orleans.DurableMessaging/HierarchicalKey.cs
@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request
Lines 82.92% (116,006 / 139,906)
Branches 72.25% (33,693 / 46,637)

Report-only conclusion: current-main baseline stale.

The newest successful coverage run tested 8efd435, not current main a68e9ed.

Coverage combines every CI test matrix job, including providers, CodeGen, .NET 8/10, Linux, Windows, and macOS, using canonical physical source and branch identities.

The comparison remains report-only while normal line and branch variance is calibrated.

Coverage details

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Unresolved recovery-generation and envelope-builder findings remain.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 High severity · 1 Medium severity

Open (4)
Previously missed (1)

In code that hasn't changed since last review

Low severity Fix article in hierarchical-key validation comment

src/​Orleans.DurableMessaging/​HierarchicalKey.cs:291

The comment uses “an segment separator”, which is grammatically incorrect and makes the validation explanation less clear; change it to “a segment separator”.

Comment thread src/Orleans.Journaling/JournaledStateManager.cs Outdated
Copilot AI review requested due to automatic review settings September 16, 2026 22:43

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

The moderate CorrelationKey nullability issue remains unresolved; the additional comment typo is a minor nit.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Low severity

Open (1)
Resolved since last review (4)

Comment thread src/Orleans.DurableMessaging/HierarchicalKey.cs Outdated
Copilot AI review requested due to automatic review settings September 16, 2026 23:40

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

Two moderate validation issues remain in DurableEnvelopeBuilder.

Review effort: Lite
Findings: None

Resolved since last review (2)

Copilot AI review requested due to automatic review settings September 17, 2026 00:42

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Unresolved contract validation, API compatibility, manifest, and Journaling behavior findings remain.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)

Comment thread src/Orleans.DurableMessaging/IDurableInboxExtension.cs
Comment thread src/Orleans.DurableMessaging/DurableEnvelopeBuilder.cs

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

A moderate nullable-correlation API issue remains unresolved across a broad contract and journaling change.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 17, 2026 03:14

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Unresolved critical shutdown fault-reporting and moderate contract issues remain.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (1)

Comment thread src/Orleans.Journaling/JournaledStateManager.cs Outdated
Copilot AI review requested due to automatic review settings September 17, 2026 07:12

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

The broad journaling lifecycle and Durable Messaging contract changes warrant final human review.

Review effort: Lite
Findings: None

Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 21, 2026 17:48

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

A critical compilation issue and two moderate validation issues remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)

Comment thread src/Orleans.DurableMessaging/IInboxHandlerContext.cs
Copilot AI review requested due to automatic review settings September 21, 2026 21:01

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

The unresolved moderate DurableEnvelopeBuilder validation finding must be addressed, along with the related nullable API mismatch.

Review effort: Lite
Findings: None

Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 21, 2026 21:14

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Three moderate issues remain involving delivery-result serialization coverage, nullable correlation-key usage, and hierarchical-key enumeration performance.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)

Comment thread src/Orleans.DurableMessaging/DurableEnvelopeBuilder.cs

This branch has not been deployed

No deployments
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.

2 participants