Fix #2595: explicit DeliveryOptions.SagaId on saga Start cascades should win#2597
Merged
jeremydmiller merged 1 commit intomainfrom Apr 27, 2026
Merged
Conversation
Fixes #2595. When a saga's static `Start` method generated its own saga id inside the method body and cascaded a message tagged with an explicit `DeliveryOptions { SagaId = ... }`, Wolverine silently overwrote that explicit value with the inbound envelope's `SagaId`. A downstream reply that auto-propagated `envelope.SagaId` then routed to the wrong saga and failed with `UnknownSagaException`. Root cause: `MessageContext.TrackEnvelopeCorrelation` ran *after* `DeliveryOptions.Override` had already stamped the explicit `SagaId` on the outbound envelope, and unconditionally clobbered it with the context's `_sagaId` (which was sourced from the inbound envelope). Fix: reorder the precedence so an explicit `SagaId` on the outbound envelope wins. The fallback chain (`_sagaId` → inbound `Envelope.SagaId`) is preserved unchanged for the default "inherit from context" case, so existing saga compliance tests are unaffected. Also fixes the analogous case for replies (`RespondToSenderAsync(reply, new DeliveryOptions { SagaId = ... })`) which exercised the same code path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced Apr 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Startcascades silently drop explicitDeliveryOptions.SagaId#2595Startcascaded a message tagged with an explicitDeliveryOptions { SagaId = ... }, the explicit value was silently overwritten by the inbound envelope'sSagaId(or the context's_sagaId). A downstream reply that auto-propagatedenvelope.SagaIdthen routed to the wrong saga and failed withUnknownSagaException.MessageContext.TrackEnvelopeCorrelationso that an explicitSagaIdalready set on the outbound envelope (e.g. fromDeliveryOptions.Override, which runs first) wins over the context default. Falls through to the previous chain (_sagaId→ inboundEnvelope.SagaId) when no explicit value was set.Notes
RespondToSenderAsync(reply, new DeliveryOptions { SagaId = ... })had the same bug — the explicit value was clobbered. Same precedence reorder fixes both.DeliveryOptions.SagaId, just inherit-from-context) is byte-for-byte identical to today, so the existing saga compliance suites pass unchanged.Test plan
Bug_2595_explicit_delivery_options_sagaid_should_win(Marten + sagaStartcascade with explicitDeliveryOptions.SagaId) — fails on main, passes with fixdotnet test src/Testing/CoreTests— 1360/1360 passdotnet test src/Persistence/MartenTests --filter "Saga|saga|Bug_310|Bug_756|Bug_2595"— 65/65 pass🤖 Generated with Claude Code