@@ -84,4 +84,62 @@ describe("channel ingress drain debounce failures", () => {
8484 drain . dispose ( ) ;
8585 } ) ;
8686 } ) ;
87+
88+ it ( "keeps watchdog recovery after retry settlement fails" , async ( ) => {
89+ vi . useFakeTimers ( ) ;
90+ await withTempState ( async ( stateDir ) => {
91+ let clock = 10_000 ;
92+ const queue = createTestIngressQueue ( stateDir , { now : ( ) => clock } ) ;
93+ await queue . enqueue (
94+ "debounced-settlement-failure" ,
95+ { text : "retry me" } ,
96+ { laneKey : "shared" , receivedAt : clock } ,
97+ ) ;
98+ queue . release = async ( ) => {
99+ throw new Error ( "persistent release failure" ) ;
100+ } ;
101+
102+ const sessionError = new Error ( "Session changed while starting work. Retry." ) ;
103+ const debouncer = createInboundDebouncer < { lifecycle : ChannelIngressDispatchLifecycle } > ( {
104+ debounceMs : 0 ,
105+ buildKey : ( ) => "shared" ,
106+ onFlush : ( entries , createFlush ) =>
107+ createFlush ( {
108+ lifecycle : entries [ 0 ] ?. lifecycle ,
109+ dispatch : async ( ) => {
110+ throw sessionError ;
111+ } ,
112+ } ) ,
113+ onError : ( ) => undefined ,
114+ } ) ;
115+ const drain = createChannelIngressDrain < Payload > ( {
116+ queue,
117+ now : ( ) => clock ,
118+ adoptionStallTimeoutMs : 200_000 ,
119+ dispatchClaimedEvent : async ( _event , lifecycle ) => {
120+ await debouncer . enqueue ( { lifecycle } ) ;
121+ return { kind : "deferred" } ;
122+ } ,
123+ } ) ;
124+
125+ expect ( await drain . drainOnce ( ) ) . toEqual ( { started : 1 } ) ;
126+ await vi . advanceTimersByTimeAsync ( 127_000 ) ;
127+ clock += 127_000 ;
128+ await drain . waitForIdle ( ) ;
129+
130+ expect ( ( await queue . listClaims ( ) ) . map ( ( claim ) => claim . id ) ) . toEqual ( [
131+ "debounced-settlement-failure" ,
132+ ] ) ;
133+ expect ( drain . activeLaneKeys ( ) . has ( "shared" ) ) . toBe ( true ) ;
134+
135+ clock += 73_000 ;
136+ await vi . advanceTimersByTimeAsync ( 73_000 ) ;
137+ expect ( await queue . listClaims ( ) ) . toEqual ( [ ] ) ;
138+ expect ( await queue . listFailed ?.( { limit : "all" } ) ) . toMatchObject ( [
139+ { id : "debounced-settlement-failure" , reason : "handler-timeout" } ,
140+ ] ) ;
141+ expect ( drain . activeLaneKeys ( ) . has ( "shared" ) ) . toBe ( false ) ;
142+ drain . dispose ( ) ;
143+ } ) ;
144+ } ) ;
87145} ) ;
0 commit comments