Repository navigation
feat(messaging): process inbox messages - #11284
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Unresolved lifecycle, selection-mutation, scheduling, recovery, retention, validation, and outbox-contract issues remain.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 2
Open (3)
What changed in this PR
Adds a non-packable Durable Messaging inbox runtime integrated with Journaling and Durable Jobs, including recoverable ownership, transactional handler processing, retries, deduplication, and dead-lettering.
Changes:
- Adds durable messaging contracts, routing, diagnostics, and configuration.
- Implements journal-backed acceptance, recovery, pump coordination, and handler processing.
- Adds Journaling integration and comprehensive contract and functional tests.
| File | Reviewed change |
|---|---|
test/Orleans.DurableMessaging.Tests/Support/SnapshotProbeTests.cs |
Snapshot probe tests |
test/Orleans.DurableMessaging.Tests/Support/SnapshotProbe.cs |
Snapshot waiting helper |
test/Orleans.DurableMessaging.Tests/Support/ReceiverTestServices.cs |
Test service composition |
test/Orleans.DurableMessaging.Tests/Support/JournaledTestOutbox.cs |
Journal-backed test outbox |
test/Orleans.DurableMessaging.Tests/Support/HandlerProbe.cs |
Handler synchronization helper |
test/Orleans.DurableMessaging.Tests/Support/DurableMessagingMetricProbe.cs |
Metrics test probe |
test/Orleans.DurableMessaging.Tests/Support/DurableMessagingClusterFixture.cs |
Messaging test cluster |
test/Orleans.DurableMessaging.Tests/Support/DurableMessagingBehaviorTestBase.cs |
Shared behavior test base |
test/Orleans.DurableMessaging.Tests/Support/ControlledJournalStorageProvider.cs |
Journal failure injection |
test/Orleans.DurableMessaging.Tests/Support/ControlledDurableJobManager.cs |
Controlled job scheduling |
test/Orleans.DurableMessaging.Tests/Orleans.DurableMessaging.Tests.csproj |
Test project configuration |
test/Orleans.DurableMessaging.Tests/Functional/MessagingRoutingAndDeadLetterTests.cs |
Routing and dead-letter tests |
test/Orleans.DurableMessaging.Tests/Functional/InboxHandlerTransactionTests.cs |
Handler transaction tests |
test/Orleans.DurableMessaging.Tests/Functional/InboxCapacityBehaviorTests.cs |
Capacity behavior tests |
test/Orleans.DurableMessaging.Tests/Functional/InboxCallbackOwnershipTests.cs |
Callback ownership tests |
test/Orleans.DurableMessaging.Tests/Functional/InboxAcceptanceBehaviorTests.cs |
Acceptance behavior tests |
test/Orleans.DurableMessaging.Tests/Functional/DurableMessagingClusterCollection.cs |
Test collection definition |
test/Orleans.DurableMessaging.Tests/Functional/DedupeExpiryBehaviorTests.cs |
Deduplication expiry tests |
test/Orleans.DurableMessaging.Tests/Contracts/HandlerRoutingContractTests.cs |
Handler routing contracts |
test/Orleans.DurableMessaging.Tests/Contracts/DurableMessagingPumpResultsTests.cs |
Pump result contracts |
test/Orleans.DurableMessaging.Tests/Contracts/DurableEnvelopeContractTests.cs |
Envelope contracts |
test/Orleans.DurableMessaging.Tests/Contracts/DeliveryAndOptionsContractTests.cs |
Delivery and options contracts |
test/Orleans.DurableMessaging.Tests/Contracts/ActivationValidationTests.cs |
Activation validation contracts |
src/Orleans.Journaling/IJournaledStateObserver.cs |
Journal lifecycle observer API |
src/Orleans.Journaling/IJournaledStateManager.cs |
Observer registration API |
src/Orleans.Journaling/IJournaledGrainParticipant.cs |
Participant contract |
src/Orleans.Journaling/DurableGrain.cs |
Participant initialization |
src/Orleans.DurableMessaging/RoutePrefixHandler.cs |
Prefix route handler |
src/Orleans.DurableMessaging/RouteKeyHandler.cs |
Exact route handler |
src/Orleans.DurableMessaging/README.md |
Runtime documentation |
src/Orleans.DurableMessaging/Orleans.DurableMessaging.csproj |
Messaging project configuration |
src/Orleans.DurableMessaging/InboxHandlerSelectionContext.cs |
Handler selection context |
src/Orleans.DurableMessaging/InboxHandlerContext.cs |
Handler context implementation |
src/Orleans.DurableMessaging/IInboxHandlerContext.cs |
Handler context API |
src/Orleans.DurableMessaging/IInboxHandler.cs |
Handler contract |
src/Orleans.DurableMessaging/IDurableOutbox.cs |
Outbox contract |
src/Orleans.DurableMessaging/IDurableMessagingDiagnostics.cs |
Diagnostics API |
src/Orleans.DurableMessaging/IDurableInboxExtension.cs |
Inbox extension API |
src/Orleans.DurableMessaging/IDurableInbox.cs |
Inbox API |
src/Orleans.DurableMessaging/DurableMessagingTime.cs |
Time arithmetic helpers |
src/Orleans.DurableMessaging/DurableMessagingStateNames.cs |
Durable state names |
src/Orleans.DurableMessaging/DurableMessagingStateManagerCapabilities.cs |
State manager capability checks |
src/Orleans.DurableMessaging/DurableMessagingPumpResults.cs |
Pump execution results |
src/Orleans.DurableMessaging/DurableMessagingPumpCoordinator.cs |
Pump coordination |
src/Orleans.DurableMessaging/DurableMessagingJobOwnership.cs |
Job ownership metadata |
src/Orleans.DurableMessaging/DurableMessagingInstruments.cs |
Messaging metrics |
src/Orleans.DurableMessaging/DurableMessagingGrainParticipant.cs |
Messaging participant |
src/Orleans.DurableMessaging/DurableMessagingActivationValidator.cs |
Activation validation |
src/Orleans.DurableMessaging/DurableMessageState.cs |
Retry and dead-letter state |
src/Orleans.DurableMessaging/DurableInbox.cs |
Inbox storage and routing |
src/Orleans.DurableMessaging/DurableEnvelopeData.cs |
Deferred payload access |
src/Orleans.DurableMessaging/DurableEnvelope.cs |
Durable envelope model |
src/Orleans.DurableMessaging/DurableDeadLetterRetention.cs |
Dead-letter retention |
src/Orleans.DurableMessaging/DeliveryStatus.cs |
Delivery status values |
src/Orleans.DurableMessaging/DeliveryResult.cs |
Delivery result contract |
src/Orleans.DurableMessaging/CorrelationHandler.cs |
Correlation routing |
src/Orleans.DurableMessaging/Configuration/DurableInboxOptions.cs |
Inbox configuration |
src/api/Orleans.Journaling/Orleans.Journaling.cs |
Generated Journaling API |
Orleans.slnx |
Solution project registration |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Code coverage
Report-only conclusion: improved. The current-main baseline is commit Coverage combines every CI test matrix job, including providers, CodeGen, .NET 10/11, 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 |
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Six unresolved moderate findings and one nit remain, covering state rollback, option validation, shutdown and recovery handling, test-outbox idempotency, and an unused injected field.
Review effort: Lite
Findings: 2
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
One critical build issue and five moderate correctness, lifecycle, and test-isolation issues remain unresolved.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 3
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Six unresolved findings remain, including build-blocking and critical correctness issues.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 5
Open (6)
Composed keys with multi-segment child values lose segments · New Import CancellationToken in the handler context contract · New Remove the unused grain factory dependency Do not dispose the shutdown token while timers can still enter Handler selection does not enforce its read-only boundary Honor idempotent duplicate sends in the test outbox
4d18916 to
b05c432
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Unresolved ownership validation, compilation, and routing/performance issues require changes before approval.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 6
Open (6)
Reject delivery when recovered ownership is invalid · New Import CancellationToken in the handler context contract Composed keys with multi-segment child values lose segments Remove the unused grain factory dependency Do not dispose the shutdown token while timers can still enter Handler selection does not enforce its read-only boundary
Resolved since last review (1)
b05c432 to
c7b6bd9
Compare
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Unresolved ownership-race, retry/dead-letter accounting, deduplication, and shutdown-fault handling issues block approval.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (2)
Resolved since last review (7)
Reject delivery when recovered ownership is invalid Import CancellationToken in the handler context contract Composed keys with multi-segment child values lose segments Remove the unused grain factory dependency Do not dispose the shutdown token while timers can still enter Handler selection does not enforce its read-only boundary Honor idempotent duplicate sends in the test outbox
c7b6bd9 to
67a4a2e
Compare
Apply the coordinator-selected ordering: known equal or earlier sends retain their answer, and expiration precedes the future bound after rollback. New sends and retention extensions remain bounded.
Messaging fails the activation when a failed handler attempt staged changes, so they can't commit with its retry record, and decides that with a staged-change scope around the attempt. A JournaledPersistentState is mutated in place and serialized whole when a write captures it, so its changes never reach the scope: a handler which mutated it and threw would have its partial state committed by the retry write. States which report every change now implement the internal IReportsStagedChanges: the built-in collections, values, and task completion sources, and the messaging inbox. While any other state is registered, every scope reports staged changes, so a failed attempt recovers from the journal instead.
CompactProcessed removes processed records while enumerating them, which Dictionary supports on .NET Core 3.0 and later, and so on both frameworks Messaging targets. The test places expired records first and between retained ones, so compaction keeps enumerating after each removal.
Options validation accepts any positive DeduplicationWindow, including TimeSpan.MaxValue. The floor subtracts the window from the clock's ticks, which stays above long.MinValue for every representable time, and clamps at the minimum time. The test runs delivery, deduplication, and snapshot compaction with that window.
A handler attempt which fails after staging changes fails the activation, so recovery discards those changes, but it also discards the attempt's failure record. The message then reran with the same attempt count, so backoff and InboxRetryTimeout never applied: a handler which always failed after staging looped indefinitely, and so did any failure on a grain whose state can't report its changes. A graceful stop now journals a clean-stop record when messages are pending, and recovery charges one attempt to each due message unless the journal ends with that record. The charge commits before the pump runs a handler, and a recovery which finds a clean stop journals that it resumed, so a later unclean stop is charged. The happy path writes nothing extra; the cost falls on deactivation with pending work and on recovery. A crash also charges due messages which hadn't been dispatched, so attempts can overcount by one per unclean stop. A charge starts a message's retry window but dead-letters only a message whose window an earlier failure started, so one crash never dead-letters a message by itself.
The future bound, its exemption for recorded and floor-expired identities, and equality admission shipped without tests. Pin each branch, including receiver clock rollback, on a Durable Jobs clock which stands still between reading the bound and delivering.
The outbox journals a send's SentAt once and reuses it on every retry, so copies of one message carry one send time. A copy with a later SentAt is a re-send of the same message, and the record of the accepted send already covers it while the gap stays within DeduplicationWindow minus OutboxRetryTimeout, which is nearly the whole window. Re-sending a command after that is the case the contract already leaves to the application: reconcile before sending again. The inbox therefore answers every tracked identity from its record, whatever the delivery's send time, and retains the record for DeduplicationWindow after the send time it accepted. The ExtendSentAt command, the processed-record upsert, and the future bound for recorded identities are removed; the bound applies only to untracked identities the inbox would admit.
…ons out of dead letters Cleanup of code which nothing needs: - The inbox no longer journals each failed attempt's exception text. Nothing read it; dead letters carry the failure message. - Remove MessagingInstruments.CreateForDirectConstruction, which had no callers. - Recovery asserts, rather than re-validates, the inbox's own journaled state: admission validated every message, and replay keys each entry by its own ID. Re-validation would refuse to recover accepted messages after a stricter validator shipped. - Drop the inbox's grain-type check at start: the grain-type configurator wires messaging only for DurableGrain and IMessagingGrain. - DeliverAsync no longer logs and rethrows; its caller receives the exception, and staging and persistence failures are logged where they occur. - Messaging requires JournaledStateManager, so the handler attempt's staged-change scope has no null fallback. - The configurator decides once per grain type whether it is a stateless worker. A message which an inbox sink rejects is now recorded only as processed, with its reason and code. The sender already holds the message and receives the rejection, so the inbox no longer keeps a dead letter with its payload, and inbox dead letters lose their Code. DeadLetter, which only ever described inbox messages, is no longer generic.
… an outcome A handler attempt which throws before Complete or Fail, or returns without either, now always fails messaging for the activation. Staged changes share the grain's pending journal write, so no write may commit them; recovery from the journal discards them, and the interrupted-attempt charge applies backoff and InboxRetryTimeout before the message runs again. With a zero retry timeout, a message dead-letters at its second failure, because recovery can't tell a failed attempt from one which a crash interrupted before it ran. This removes per-flow staged-change tracking: StagedChangeScope, IReportsStagedChanges, and the change reporting in the built-in journaled states. Messaging no longer uses Journaling internals, so it no longer pins Journaling's exact version. The tracking, which keeps a failed attempt that staged nothing from deactivating the grain, moves to a separate pull request.
TryPrepareStates reports whether one synchronous pass prepared every state, and otherwise hands back the first incomplete preparation to await before preparing every state again. This replaces a for loop driven by a ref flag, and documents why the passes converge.
…ters A sink rejection no longer creates an inbox dead letter, so DeliveryResult's code reaches the receiver's processed record.
There was a problem hiding this comment.
🟡 Changes recommended
Approval is blocked by a critical target-framework selection bug that can schedule incorrect or duplicate builds, along with documentation validation that does not correctly handle the new net11.0-only project.
2 open issues
7 resolved since last review
Fence the activation when the sink throws Diagnostics exposes mutable journal-owned messages Docs validation omits the net11.0-only project Validate recovered messages before applying them Clear stale dead letters when completing a reused message ID Clear stale dead letters when reusing an expired message ID Rephrase the staged changes sentence for clarity
Review effort: Lite
Solution-wide test runs pass --framework, which builds each test project with that framework, so a test project which targets only net11.0 fails a net10.0 run with NETSDK1005. A test project now opts out of a run whose framework it doesn't target, so the existing solution commands skip it. - Coverage moves to Linux net11.0, which every test project targets, so projects which target only net11.0 are measured. - GenAPI generates each surface from net10.0, or from net11.0 for a project which targets only newer frameworks; AGENTS.md documents the same selection. The docs API data generator applies the same selection, with framework references per framework. - The docs workflow builds Docs.slnx with each project's own framework, then runs its net10.0 test projects, so net11.0-only snippet projects compile in CI. CompiledDocumentationSnippets aligns Azure.Identity with the repository's Azure.Core so the solution builds (fixes dotnet#11718). - A docs or sample project targets exactly net11.0 with a reasoned OrleansDocumentationTargetFrameworkException, which PROJECT004 and the snippet validator honor. - snippets/compiled-durable/DurableDocumentationSnippets.csproj compiles the snippets of net11.0-only packages. A layer moves its snippet files there from snippets/compiled, keeping their subfolders, and updates the :::code paths.
The durable stack targets net11.0 only, so Messaging and its tests use .NET 11 language and library features, such as unions, without polyfills.
InboxCommand was a record carrying an InboxCommandKind and every field which any kind used. It is now a union of one sealed class per change, so each case carries exactly its data and Apply switches over the cases. Sealed classes serialize as a single object, without a record's base layer. Case identifiers follow declaration order and fix the binary journal format; in JSON each case leads with its kind, which a type classifier reads to select the case.
IInboxWorkSource had one method and named the inbox although it reports work held outside it. IInbox.RegisterWakeup takes the callback which reports how soon a deactivated grain must wake for that work.
IMessagingGrain and DurableGrain marked messaging grains so a per-type configurator could bind the messaging extension at activation setup. Resolving IInbox already declares the inbox state, so the inbox now binds the extension itself. An activation which never resolves its inbox has no messaging extension, and deliveries to it fail instead of reaching an inbox which never recovered. MessagingShared becomes a silo singleton, and the pump rejects stateless workers when the inbox is resolved.
DeliveryResult was a status enum plus optional fields which only some statuses used, and OutboxMessageRetirement repeated that shape. Each is now a union of one sealed class per outcome: a case carries exactly its data, consumers switch over the cases, and a data-free result encodes in four bytes. Cases without data expose a shared instance. Case identifiers follow declaration order.
There was a problem hiding this comment.
🟡 Changes recommended
A critical active finding in .github/scripts/generate-api.proj means framework metadata is not applied to the intended items, potentially causing incorrect or failed API generation builds.
1 open issue
2 resolved since last review
Review effort: Lite



Durable messaging stack: #11282 (contracts, merged as ec2c1bd) → #11284 (inbox) → #11285 (outbox) → #10693 (integration, documentation, samples, NativeAOT smoke, benchmarks, and playground). This layer is based on
main.Problem
An inbox must durably accept commands, run handlers after acknowledgement, and commit business effects and completion together. Identity history must be reclaimable while delayed delivery, lost replies, and clock rollback preserve recorded decisions.
Solution
DeduplicationWindow. A completed record becomes removable once the durable floor covers its acceptedSentAt. Acknowledged snapshots and recovery reclaim it; ordinary and scalar acknowledgements remain constant-time.SentAt. The record keeps the send time the inbox accepted, which covers every retry of a re-send made within the deduplication window.IInbox.RegisterWakeupand the activation pump retain wake-ups. Scheduled work occupies capacity until completion. Bounded handler retry, prepare-write prerequisites, and keep-alive holds preserve recovery and progress.CompleteorFailfails the activation, so no write commits its staged changes. Recovery charges the attempt, which applies backoff andInboxRetryTimeout. Per-flow staged-change tracking, which retries in place when the attempt staged nothing, is proposed separately.IInboxduring construction or activation setup; the inbox binds the grain's messaging extension then, so deliveries reach only an inbox which recovers with the journal. Stateless workers are rejected.DeliveryResult,OutboxMessageRetirement, and the inbox journal commands are C# unions of one record per case; each case carries exactly its data and consumers switch over the cases. Messaging targets net11.0 only.OrleansDocumentationTargetFrameworkException.SentAtfuture-time and expiry checks, so a known identity receives its recorded answer.Rationale
The journal owns atomicity and acknowledgement; the inbox owns admission, recorded outcomes, and accepted send times. The durable floor preserves expiration, and known outcomes survive backward clock movement. #11285 supplies the outbox runtime; this layer remains independently buildable.