@@ -537,6 +537,65 @@ test("inventory refreshes preserve the original per-run target budget", async ()
537537 ) ;
538538} ) ;
539539
540+ test ( "inventory refreshes preserve cleanup counters when later target discovery fails" , async ( ) => {
541+ const scenario = await automaticReconcileScenario ( {
542+ rows : [
543+ row (
544+ "closed-one" ,
545+ "publication:closed-one" ,
546+ 1 ,
547+ "retry_exhausted" ,
548+ true ,
549+ "eligible" ,
550+ "openclaw/repo#1" ,
551+ ) ,
552+ row (
553+ "closed-two" ,
554+ "publication:closed-two" ,
555+ 2 ,
556+ "retry_exhausted" ,
557+ true ,
558+ "eligible" ,
559+ "openclaw/repo#2" ,
560+ ) ,
561+ row (
562+ "open-three" ,
563+ "publication:open-three" ,
564+ 3 ,
565+ "retry_exhausted" ,
566+ true ,
567+ "eligible" ,
568+ "openclaw/repo#3" ,
569+ ) ,
570+ row (
571+ "invalid" ,
572+ "publication:invalid" ,
573+ 4 ,
574+ "tuple_protocol_invalid" ,
575+ false ,
576+ "invalid_dead_letter_item" ,
577+ null ,
578+ ) ,
579+ ] ,
580+ closedNumbers : [ 1 , 2 ] ,
581+ skipCleanupAtResolution : 2 ,
582+ failTargetAfterCleanup : 3 ,
583+ maxTargets : 3 ,
584+ maxRecoveries : 1 ,
585+ } ) ;
586+
587+ assert . equal ( scenario . first . code , 0 , scenario . first . stderr ) ;
588+ const summary = JSON . parse ( scenario . first . stdout ) ;
589+ assert . equal ( summary . resolved_rows , 2 ) ;
590+ assert . equal ( summary . closed_rows , 1 ) ;
591+ assert . equal ( summary . invalid_rows , 1 ) ;
592+ assert . equal ( scenario . inventoryRequests , 2 ) ;
593+ assert . deepEqual (
594+ scenario . resolutions . map ( ( resolution ) => resolution . ids ) ,
595+ [ [ "closed-one" ] , [ "closed-two" ] , [ "invalid" ] ] ,
596+ ) ;
597+ } ) ;
598+
540599test ( "automatic recovery rechecks pressure immediately after duplicate cleanup" , async ( ) => {
541600 const scenario = await automaticReconcileScenario ( {
542601 rows : [
@@ -1432,8 +1491,9 @@ async function automaticReconcileScenario(options) {
14321491 return ;
14331492 }
14341493 if (
1435- options . failedRepository &&
1436- request . url . includes ( `/${ options . failedRepository } /issues/` )
1494+ ( options . failedRepository &&
1495+ request . url . includes ( `/${ options . failedRepository } /issues/` ) ) ||
1496+ ( options . failTargetAfterCleanup === number && resolutions . length >= 2 )
14371497 ) {
14381498 response . writeHead ( 503 , { "content-type" : "application/json" } ) ;
14391499 response . end ( JSON . stringify ( { error : "temporary" } ) ) ;
@@ -1511,8 +1571,8 @@ async function automaticReconcileScenario(options) {
15111571 return ;
15121572 }
15131573 resolutions . push ( body ) ;
1514- if ( duplicateSkipsRemaining > 0 ) {
1515- duplicateSkipsRemaining -= 1 ;
1574+ if ( duplicateSkipsRemaining > 0 || options . skipCleanupAtResolution === resolutions . length ) {
1575+ if ( duplicateSkipsRemaining > 0 ) duplicateSkipsRemaining -= 1 ;
15161576 for ( const id of body . ids ) {
15171577 const selected = rows . find ( ( entry ) => entry . dead_letter_id === id ) ;
15181578 if ( selected ) selected . status = "resolved" ;
0 commit comments