fix(sessions): reject a StreamEvents resume cursor ahead of the stream with InvalidArgument (SES-006, #256)

This commit is contained in:
Joseph Doherty
2026-12-03 09:48:27 -05:00
parent 9756ab843e
commit 09da8063a9
6 changed files with 108 additions and 0 deletions
@@ -534,6 +534,19 @@ public sealed class SessionEventDistributor : IAsyncDisposable
{
EvictAged();
// A cursor above every sequence this session has produced cannot have come from this
// session's stream (a stale cursor from an earlier session, or a corrupted one). Resuming
// from it would attach a stream whose live filter drops every event until the session
// catches up, with nothing replayed and no gap signalled — a silently dead stream. Refuse
// it before anything is registered so the client learns of the mistake at attach time.
if (afterSequence > _highestSequenceSeen)
{
throw new SessionManagerException(
SessionManagerErrorCode.InvalidResumeCursor,
$"after_worker_sequence {afterSequence} is ahead of the newest event ({_highestSequenceSeen}) session {_sessionId} has produced; "
+ "resume with the last worker_sequence this session delivered, or use 0 for a fresh stream.");
}
List<MxEvent> newer = [];
ulong highestReplayed = afterSequence;