@@ -131,7 +131,7 @@ describe("runGenerationGuardedDeliver", () => {
131131} ) ;
132132
133133describe ( "settleCompactionContinuationHop" , ( ) => {
134- test ( "a superseded hop requeues instead of delivering to the outgoing agent" , async ( ) => {
134+ test ( "a superseded hop does not deliver to the outgoing agent" , async ( ) => {
135135 let generation = 1 ;
136136 const stillCurrent = ( ) => generation === 1 ;
137137 let delivered = 0 ;
@@ -195,6 +195,45 @@ describe("settleCompactionContinuationHop", () => {
195195 expect ( runs ) . toBe ( 1 ) ;
196196 } ) ;
197197
198+ test ( "an accepted hop stays accepted if generation flips after deliver" , async ( ) => {
199+ let generation = 1 ;
200+ const result = await settleCompactionContinuationHop ( {
201+ stillCurrent : ( ) => generation === 1 ,
202+ deliver : async ( ) => {
203+ generation = 2 ;
204+ return { status : "accepted" as const } ;
205+ } ,
206+ onSuperseded : ( ) => {
207+ throw new Error ( "accepted hop must not be relabeled superseded" ) ;
208+ } ,
209+ } ) ;
210+ expect ( result ) . toEqual ( { status : "accepted" } ) ;
211+ } ) ;
212+
213+ test ( "a closed hop that goes stale does not retry deliver" , async ( ) => {
214+ let generation = 1 ;
215+ let attempts = 0 ;
216+ const result = await settleCompactionContinuationHop ( {
217+ stillCurrent : ( ) => generation === 1 ,
218+ deliver : async ( ) => {
219+ attempts += 1 ;
220+ generation = 2 ;
221+ return {
222+ status : "not-delivered" as const ,
223+ reason : "agent-closed" as const ,
224+ detail : "agent is closed" ,
225+ } ;
226+ } ,
227+ onSuperseded : ( ) => undefined ,
228+ } ) ;
229+ expect ( result ) . toEqual ( {
230+ status : "not-delivered" ,
231+ reason : "superseded" ,
232+ detail : "session identity changed before delivery" ,
233+ } ) ;
234+ expect ( attempts ) . toBe ( 1 ) ;
235+ } ) ;
236+
198237 test ( "continuation enqueued then interrupt rebuild queued does not auto-deliver to the replacement agent" , async ( ) => {
199238 const { enqueue, enqueuePreemptible, abortInFlight, awaitTail } =
200239 createSessionOperationQueue ( ) ;
@@ -393,6 +432,34 @@ describe("settleCompactionContinuationHop", () => {
393432 await awaitTail ( ) ;
394433 expect ( delivered ) . toEqual ( [ 1 , 2 ] ) ;
395434 } ) ;
435+
436+ test ( "an interrupt-stale hop does not report not-delivered" , async ( ) => {
437+ const { enqueue, enqueuePreemptible, abortInFlight, awaitTail } =
438+ createSessionOperationQueue ( ) ;
439+ const deliveryGeneration = createDeliveryGeneration ( ) ;
440+ const notices : string [ ] = [ ] ;
441+
442+ enqueueCompactionContinuationHop ( {
443+ enqueue : enqueuePreemptible ,
444+ captureGeneration : ( ) => deliveryGeneration . capture ( ) ,
445+ deliver : async ( ) => ( { status : "accepted" as const } ) ,
446+ onResult : ( result ) => {
447+ if ( result . status === "accepted" ) return ;
448+ notices . push ( result . detail ) ;
449+ } ,
450+ } ) ;
451+
452+ startInterruptRebuild ( {
453+ deliveryGeneration,
454+ markSendAborted : ( ) => undefined ,
455+ abortInFlight,
456+ enqueue,
457+ rebuild : async ( ) => undefined ,
458+ } ) ;
459+
460+ await awaitTail ( ) ;
461+ expect ( notices ) . toEqual ( [ ] ) ;
462+ } ) ;
396463} ) ;
397464
398465describe ( "deliveryResultNotice" , ( ) => {
0 commit comments