Run transaction participants when SaveChangesAsync has only participants pending#161
Merged
Merged
Conversation
…nts pending DocumentSessionBase.SaveChangesAsync used to early-return when _workTracker.HasOutstandingWork() returned false. _workTracker tracks document operations and event streams - it does NOT include ITransactionParticipants registered via AddTransactionParticipant. A session that has only registered participants (no doc ops, no streams) therefore had SaveChangesAsync skip the entire pipeline - the SQL transaction was never begun, and every queued participant's BeforeCommitAsync silently never ran. Wolverine's GH-2941 surfaced this: Wolverine.Polecat's outbox path for scheduled cascades (DeliveryMessage<T>.DelayedFor(...) emitted by a [ReadAggregate] or [DocumentExists]-decorated handler with no document writes) hits Session.StoreIncoming(...), which registers a StoreIncomingEnvelopeParticipant whose BeforeCommitAsync inserts the scheduled envelope row into wolverine_incoming_envelopes. With no document ops on the session, that participant never ran and the scheduled message was silently lost. Fix: extend the early-return guard to also account for queued transaction participants. Listeners and other commit-time side effects continue to run via the normal pipeline once the transaction is begun. New test: Bug_save_changes_runs_participants_only pins the contract that ITransactionParticipant.BeforeCommitAsync runs (and runs with a real SqlTransaction) when only a participant is registered. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
The bug
DocumentSessionBase.SaveChangesAsyncearly-returns when_workTracker.HasOutstandingWork()is false._workTrackertracks document operations + event streams — it does not includeITransactionParticipants registered viaAddTransactionParticipant. A session that has only registered participants (no doc ops, no streams) therefore hadSaveChangesAsyncskip the entire pipeline; the SQL transaction was never begun, and every queued participant'sBeforeCommitAsyncsilently never ran.How it surfaced
Wolverine's GH-2941.
Wolverine.Polecat's outbox path for scheduled cascades (aDeliveryMessage<T>.DelayedFor(...)emitted by a[ReadAggregate]or[DocumentExists]-decorated handler with no document writes) hitsSession.StoreIncoming(...), which registers aStoreIncomingEnvelopeParticipantwhoseBeforeCommitAsyncinserts the scheduled envelope row intowolverine_incoming_envelopes. With no document ops on the session, that participant never ran and the scheduled message was silently lost.Fix
Extend the early-return guard to also account for queued transaction participants. Listeners and other commit-time side effects continue to run via the normal pipeline once the transaction is begun.
Test
New regression test
Bug_save_changes_runs_participants_onlypins the contract thatITransactionParticipant.BeforeCommitAsyncruns (and runs with a realSqlTransaction) when only a participant is registered.🤖 Generated with Claude Code