Commit the events queued by a ProjectionScenario's final step - #5130
Merged
Conversation
Closes #5126 ScenarioAction only flushes the session when the step AFTER it is an assertion: _action(scenario.Session.Events); if (scenario.NextStep is ScenarioAssertion) // null for the last step { await scenario.Session.SaveChangesAsync(ct); await scenario.WaitForNonStaleData(); } NextStep peeks the queue after the current step was dequeued, so it is null on the final step and the branch never runs. Execute's finally then disposes the session, and Marten's dispose does not commit -- so a scenario ending in an append silently lost those events, and an arrange-only scenario was a complete no-op that passed. Flushes once more after the step loop. Unconditional on purpose: SaveChangesAsync returns immediately when the unit of work is empty (DocumentSessionBase checks HasOutstandingWork before doing anything), and WaitForNonStaleData is already a no-op when no daemon is running, so scenarios that already flushed pay nothing. The flush is inside the try and aggregates into ProjectionScenarioException like any other step, so a failing commit reports as a scenario failure rather than escaping raw. Two regression tests, both verified to fail without the fix: a trailing append after an assertion, and a scenario with no assertions at all. None of the eight existing tests covered this because every one of them happens to end with an assertion. net9.0: DaemonTests 262/0/0. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VpDCvJcBDZerieJB4JEHde
This was referenced Aug 4, 2026
Open
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.
Closes #5126
The bug
ScenarioActiononly flushes the session when the step after it is an assertion:NextSteppeeks the queue after the current step was dequeued, so it is null on the final step and the branch never runs.Execute'sfinallythen disposes the session, and Marten's dispose does not commit.Consequences: a scenario ending in an append silently loses those events, and an arrange-only scenario is a complete no-op that passes.
The fix
Flush once more after the step loop. Unconditional on purpose —
SaveChangesAsyncreturns immediately when the unit of work is empty (DocumentSessionBase.SaveChangesAsyncchecksHasOutstandingWorkbefore doing anything) andWaitForNonStaleDatais already a no-op when no daemon is running, so scenarios that already flushed pay nothing for it.The flush sits inside the
tryand aggregates intoProjectionScenarioExceptionlike any other step, so a failing commit is reported as a scenario failure with the rest rather than escaping raw.Tests
Two regression tests, both verified to fail on master before the fix:
trailing_append_is_committed— an append after an assertion, with nothing following itarrange_only_scenario_actually_writes— a scenario with no assertions at allNone of the eight existing tests covered this, because every one of them happens to end with an assertion.
net9.0:
DaemonTests262 / 0 / 0.Not addressed here
The same
NextStep is ScenarioAssertionrule means consecutive actions batch into a single transaction, so a scenario cannot express "two separate commits" — which is what you would want for optimistic concurrency or per-batch projection behaviour. That is a design decision rather than a defect, and it is called out in #5126 and #5127 rather than changed silently here.🤖 Generated with Claude Code
https://claude.ai/code/session_01VpDCvJcBDZerieJB4JEHde