@@ -2821,6 +2821,109 @@ it.each([
28212821 }
28222822} ) ;
28232823
2824+ it ( "changes Buzz settings in a fresh run after a retry took over a run taken on" , async ( ) => {
2825+ let waits = 0 ;
2826+ const recovered = deferred < unknown > ( ) ;
2827+ let settled = false ;
2828+ const thread = message ( "5" , "Deploy is stuck" ) ;
2829+ // The first delivery's run, the one in another thread that takes it on
2830+ // again, the first one's retry, and a fresh run in the first conversation.
2831+ const runs = [
2832+ { conversation : CONVERSATION , submission : 1 , placed : true } ,
2833+ { conversation : CONVERSATION + 1 , submission : 2 , placed : true } ,
2834+ // Pi takes the retry as the request it already has, placing nothing.
2835+ { conversation : CONVERSATION , submission : 1 , placed : false } ,
2836+ { conversation : CONVERSATION , submission : 3 , placed : true } ,
2837+ ] ;
2838+ const f = setup ( {
2839+ deliver : ( params , process ) => {
2840+ const run = runs [ f . host . requests ( "deliver" ) . length - 1 ] ;
2841+ if ( ! run ) throw new Error ( "No more deliveries" ) ;
2842+ if ( run . placed )
2843+ process . send ( {
2844+ method : "event" ,
2845+ params : {
2846+ agent : self ,
2847+ conversation : run . conversation ,
2848+ type : "placed" ,
2849+ request : params . request ,
2850+ entry : 1 ,
2851+ } ,
2852+ } ) ;
2853+ return { submission : run . submission , conversation : run . conversation } ;
2854+ } ,
2855+ // Two hosts stop while the first run is waited for, which is given up on;
2856+ // the run taken on again ends while its request is retried.
2857+ wait : ( { submission } , process ) => {
2858+ if ( submission !== 1 ) return new Promise ( ( ) => { } ) ;
2859+ if ( ++ waits > 2 ) return recovered . promise ;
2860+ queueMicrotask ( ( ) => process . exit ( 1 , "Killed\n" ) ) ;
2861+ return new Promise ( ( ) => { } ) ;
2862+ } ,
2863+ unfinished : ( ) => ( {
2864+ submissions :
2865+ f . host . processes . length > 2 && ! settled
2866+ ? [
2867+ {
2868+ submission : 1 ,
2869+ conversation : CONVERSATION ,
2870+ request : f . host . requests ( "deliver" ) [ 0 ] ?. params . request ,
2871+ context : { channel, root : root . id } ,
2872+ } ,
2873+ ]
2874+ : [ ] ,
2875+ } ) ,
2876+ } ) ;
2877+ f . session . read . mockImplementation ( async ( filters ?: { ids ?: string [ ] } [ ] ) =>
2878+ filters ?. [ 0 ] ?. ids ?. includes ( thread . id ) ? [ thread ] : [ root ] ,
2879+ ) ;
2880+ const set = vi . fn ( ( _key : unknown , value : unknown , check : ( ) => void ) => {
2881+ check ( ) ;
2882+ return { key : "example.mood" , value } ;
2883+ } ) ;
2884+ Object . assign ( f . agent , { settings : { list : ( ) => [ ] , get : vi . fn ( ) , set } } ) ;
2885+ try {
2886+ const mention = reply ( "2" , "@Pi look" ) ;
2887+ const first = f . deliver ( { type : "mention" , event : mention } ) ;
2888+ await first . run ;
2889+ await f . settled ( first ) ;
2890+ const other = f . deliver ( {
2891+ type : "mention" ,
2892+ event : message ( "6" , "@Pi too" , {
2893+ created_at : 110 ,
2894+ tags : [
2895+ [ "h" , channel ] ,
2896+ [ "e" , thread . id , "" , "reply" ] ,
2897+ [ "p" , self ] ,
2898+ ] ,
2899+ } ) ,
2900+ } ) ;
2901+ await other . run ;
2902+ await vi . waitFor ( ( ) => expect ( waits ) . toBe ( 3 ) ) ;
2903+ const retry = f . deliver ( { type : "mention" , event : mention } ) ;
2904+ await retry . run ;
2905+ await vi . waitFor ( ( ) => expect ( f . host . requests ( "deliver" ) ) . toHaveLength ( 3 ) ) ;
2906+ settled = true ;
2907+ recovered . resolve ( { status : "done" , answer : 3 , text : "" } ) ;
2908+ await f . settled ( retry ) ;
2909+ const next = f . deliver ( { type : "mention" , event : reply ( "4" , "@Pi again" ) } ) ;
2910+ await next . run ;
2911+ await vi . waitFor ( ( ) => expect ( next . acknowledged ) . toHaveBeenCalled ( ) ) ;
2912+ expect (
2913+ await f . runtime . tool ( {
2914+ agent : self ,
2915+ conversation : CONVERSATION ,
2916+ context : { channel, root : root . id } ,
2917+ name : "settings_set" ,
2918+ arguments : { key : "example.mood" , value : "busy" } ,
2919+ } ) ,
2920+ ) . not . toMatchObject ( { isError : true } ) ;
2921+ expect ( set ) . toHaveReturned ( ) ;
2922+ } finally {
2923+ await f . runtime . dispose ( ) ;
2924+ }
2925+ } ) ;
2926+
28242927it . each ( [
28252928 [ "the delivery it came in" , false ] ,
28262929 [ "a delivery that joined since" , true ] ,
0 commit comments