@@ -669,6 +669,62 @@ describe("agent ask wake delivery", () => {
669669 ) ;
670670 } ) ;
671671
672+ test ( "paused beginSystemContinuation does not mark the turn processing" , async ( ) => {
673+ await withWakeBridge ( ( bridge , sends , shell ) => {
674+ handleCtrlC ( shell ) ;
675+ expect ( isPaused ( shell . session ) ) . toBe ( true ) ;
676+ bridge . beginSystemContinuation ( "mailbox occupancy" ) ;
677+ expect ( bridge . turn . isProcessing ) . toBe ( false ) ;
678+ expect ( shell . session . run ) . not . toBe ( "busy" ) ;
679+ expect ( sends ) . toEqual ( [ ] ) ;
680+ } ) ;
681+ } ) ;
682+
683+ test ( "in-flight mailbox collect after pause does not start a primary" , async ( ) => {
684+ await withWakeBridge ( async ( bridge , sends , shell ) => {
685+ const order : string [ ] = [ ] ;
686+ let release : ( ) => void = ( ) => undefined ;
687+ const hold = new Promise < void > ( ( resolve ) => {
688+ release = resolve ;
689+ } ) ;
690+ const driver = latchAsyncMailboxMail ( bridge , order , hold ) ;
691+ bridge . setMailboxMailDriver ( driver ) ;
692+ bridge . flushMailboxMail ( ) ;
693+ expect ( order ) . toEqual ( [ "mail" ] ) ;
694+ expect ( driver . claimed ( ) ) . toBe ( true ) ;
695+ expect ( bridge . turn . isProcessing ) . toBe ( false ) ;
696+
697+ handleCtrlC ( shell ) ;
698+ expect ( isPaused ( shell . session ) ) . toBe ( true ) ;
699+
700+ release ( ) ;
701+ await hold ;
702+ await Promise . resolve ( ) ;
703+ await Promise . resolve ( ) ;
704+
705+ expect ( order ) . toEqual ( [ "mail" , "begin" ] ) ;
706+ expect ( bridge . turn . isProcessing ) . toBe ( false ) ;
707+ expect ( sends ) . toEqual ( [ ] ) ;
708+ expect ( shell . session . run ) . not . toBe ( "busy" ) ;
709+ expect ( isPaused ( shell . session ) ) . toBe ( true ) ;
710+ expect ( driver . claimed ( ) ) . toBe ( false ) ;
711+ } ) ;
712+ } ) ;
713+
714+ test ( "unpaused interrupt still begins a system continuation" , async ( ) => {
715+ await withWakeBridge ( ( bridge , sends , shell ) => {
716+ bridge . handle ( { type : "inference.start" , data : { } } ) ;
717+ expect ( bridge . turn . isProcessing ) . toBe ( true ) ;
718+ bridge . interrupt ( ) ;
719+ expect ( isPaused ( shell . session ) ) . toBe ( false ) ;
720+ expect ( bridge . turn . isProcessing ) . toBe ( false ) ;
721+ bridge . beginSystemContinuation ( "mailbox occupancy" ) ;
722+ expect ( bridge . turn . isProcessing ) . toBe ( true ) ;
723+ expect ( shell . session . run ) . toBe ( "busy" ) ;
724+ expect ( sends ) . toEqual ( [ ] ) ;
725+ } ) ;
726+ } ) ;
727+
672728 test ( "a wake question with bracket lines does not spoof attachment-echo matching" , async ( ) => {
673729 await withWakeBridge ( ( bridge , sends , shell ) => {
674730 const ask = {
0 commit comments