He-Pin opened a new pull request, #2815:
URL: https://github.com/apache/pekko/pull/2815

   ## Motivation
   
   When `handleExternalReplicatedEventPersist` receives a replicated event, it 
updates `seenPerReplica` with the event's `originSequenceNr` without validating 
it matches the expected next sequence number. This was flagged as a FIXME 
referencing [akka#29259](https://github.com/akka/akka/issues/29259).
   
   If events arrive out of order (e.g., seqNr 7 arrives when expecting 6), 
`seenPerReplica` advances past the gap, and the missed event (seqNr 6) will 
later be filtered as "already seen" — permanently lost.
   
   ## Modification
   
   - **Replaced the FIXME** with a proper defensive validation check
   - **Added warning log** when `originSequenceNr != expectedSeqNr` for the 
replica
   - **Documented the caller contracts** explaining why only gap events (not 
duplicates) can reach this validation:
     - `onPublishedEvent`: Rejects both duplicates and gaps before calling — 
only exact-match seqNr passes
     - `onReplicatedEvent`: Filters duplicates via `alreadySeen()`, but gaps 
may pass through
   - **Preserved backward compatibility**: Events are still persisted even on 
mismatch (rejecting could stall replication)
   
   ### Design Decision: Why `!=` instead of separate `<` and `>` branches
   
   Cross-review by GPT-5.4 and Sonnet 4.6 independently confirmed that:
   1. The `< expectedSeqNr` (duplicate) branch would be **dead code** — callers 
already filter duplicates
   2. Only the `> expectedSeqNr` (gap) scenario can actually fire
   3. Using a single `!=` check avoids dead code while remaining defensive 
against future caller changes
   
   ## Result
   
   - Operators now get actionable warning logs when sequence number gaps occur 
in replication
   - The warning message includes the expected vs actual seqNr and notes that 
earlier events may be skipped
   - No behavior change for normal operation (exact-match events processed 
silently)
   - All 18 replicated event tests pass (ReplicatedEventSourcingSpec + 
ReplicatedEventPublishingSpec)
   
   ## References
   
   - Resolves FIXME from 
[akka#29259](https://github.com/akka/akka/issues/29259) (which is now Apache 
licensed)
   - Cross-reviewed by GPT-5.4 (found gap advancement risk) and Sonnet 4.6 
(found duplicate branch dead code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to