Skip to content

Fix cascading message SagaId propagation with Separated mode#2060

Merged
jeremydmiller merged 1 commit into
JasperFx:mainfrom
scrodde:cascading-messaages-saga-id
Jan 23, 2026
Merged

Fix cascading message SagaId propagation with Separated mode#2060
jeremydmiller merged 1 commit into
JasperFx:mainfrom
scrodde:cascading-messaages-saga-id

Conversation

@scrodde

@scrodde scrodde commented Jan 22, 2026

Copy link
Copy Markdown
Contributor

When a saga handler returns a cascading message, the Sagaid wasn't being set on the MessageContext, so outbound messages had no SagaId attached. This caused IndeterminateSagaStateIdException when the cascaded message tried to correlate back to the saga.

Workaround 1
Explicitly set the Saga identity on the cascaded message by any of the supported ways documented here https://wolverinefx.net/guide/durability/sagas.html#saga-message-identity

Workaround 2
Publish directly using IMessageContext.PublishAsync and using DeliveryOptions { SagaId }

public async Task Handle(ThingUpdated updated, IMessageContext context)
{
    Updates++;
    Debug.WriteLine(context.Envelope.Destination);
    await context.PublishAsync(new AnotherThingHappened(), new()
    {
        SagaId = Id.ToString()
    });
}

Solution

The SagaId extracted from the incoming message wasn't being set on MessageContext._sagaId, so when cascading messages were enqueued the outbound envelope had no SagaId.

Changes:

  1. Added SetSagaId(object sagaId) method to MessageContext to allow generated code to set the saga ID for correlation
  2. Created SetSagaIdFrame - generates context.SetSagaId(sagaId) for existing saga handler paths where sagaId variable is available
  3. Created SetSagaIdFromSagaFrame - generates context.SetSagaId(saga.Id) for Start method paths where only the saga object is available

@scrodde scrodde changed the title Cix cascading message SagaId propagation with Separated mode Fix cascading message SagaId propagation with Separated mode Jan 22, 2026
@jeremydmiller jeremydmiller merged commit 9119efc into JasperFx:main Jan 23, 2026
1 check passed
This was referenced Jan 26, 2026
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