@@ -322,7 +322,9 @@ export function createMatrixIngressMonitor(options: {
322322 // retried on later drain polls until it lands. While any admission stays
323323 // parked the sync-token store refuses to advance the durable cursor past
324324 // it, so the event is never skipped — and the cursor unfreezes as soon as
325- // the journal append succeeds again instead of needing a restart.
325+ // the journal append succeeds again instead of needing a restart. Later
326+ // accepts queue behind the parked tail without touching the journal, so
327+ // queue rows always land in accept order.
326328 const parkedAdmissions : Array < {
327329 roomId : string ;
328330 event : MatrixRawEvent ;
@@ -399,6 +401,16 @@ export function createMatrixIngressMonitor(options: {
399401 // retries rather than dispatching live around the drain's dedupe and
400402 // lane serialization.
401403 const admission = { roomId, event, facts, receivedAt : Date . now ( ) } ;
404+ // A still-parked predecessor must enter the journal first. Appending
405+ // this newer event now could succeed while the older one is parked, and
406+ // the drain would dispatch the room out of accept order — the queue can
407+ // only order persisted rows. Queue behind the parked tail; the
408+ // poll-driven retry lands both in order.
409+ if ( parkedAdmissions . length > 0 ) {
410+ parkedAdmissions . push ( admission ) ;
411+ scheduleAdmissionRetry ( ) ;
412+ return ;
413+ }
402414 let lastError : unknown ;
403415 for ( const delayMs of [ 0 , 100 , 300 ] ) {
404416 if ( delayMs > 0 ) {
@@ -424,8 +436,9 @@ export function createMatrixIngressMonitor(options: {
424436
425437 return {
426438 accept : ( roomId , event ) => {
427- // Parked retries run first so a recovered queue cannot append a later
428- // event ahead of an earlier parked one.
439+ // Parked retries run first, and admitOnce itself queues behind any
440+ // still-parked predecessor, so journal order always matches accept
441+ // order even while the queue keeps failing.
429442 const admission = admissionTail
430443 . then ( ( ) => retryParkedAdmissions ( ) )
431444 . then ( ( ) => admitOnce ( roomId , event ) ) ;
0 commit comments