@@ -1807,6 +1807,19 @@ mod linux {
18071807 }
18081808
18091809 fn wait ( & self , process_id : & str ) -> Response {
1810+ let exec = lock ( & self . exec_handles )
1811+ . get ( process_id)
1812+ . map ( |handle| handle. process . clone ( ) ) ;
1813+ if let Some ( process) = exec {
1814+ // Wait independently of the output attachment. Retain the
1815+ // process, not the registry lock, while its exit is pending.
1816+ return match self . process_runtime . block_on ( process. wait ( ) ) {
1817+ Ok ( status) => Response :: Exited {
1818+ status : status. into ( ) ,
1819+ } ,
1820+ Err ( error) => guest_error ( BoundaryErrorKind :: Process , error. to_string ( ) ) ,
1821+ } ;
1822+ }
18101823 let process = match self . running_process ( process_id) {
18111824 Ok ( process) => process,
18121825 Err ( response) => return response,
@@ -3530,6 +3543,15 @@ mod linux {
35303543 } ) ;
35313544 assert_eq ! ( output, "reconnected" ) ;
35323545 drop ( exec) ;
3546+ for _ in 0 ..2 {
3547+ assert_eq ! (
3548+ boundary. wait( & exec_id) ,
3549+ Response :: Exited {
3550+ status: ExitStatusWire :: Exited ( 0 ) ,
3551+ } ,
3552+ "exec status must remain available after its output attachment closes"
3553+ ) ;
3554+ }
35333555 let Response :: Attached { snapshot } = boundary. attach ( policy. clone ( ) ) else {
35343556 panic ! ( "reconnect attach did not return a session snapshot" ) ;
35353557 } ;
@@ -3773,6 +3795,15 @@ mod linux {
37733795 boundary. signal_exec( & retained_id, SignalWire :: Kill ) ,
37743796 Response :: Signaled
37753797 ) ;
3798+ for _ in 0 ..2 {
3799+ assert_eq ! (
3800+ boundary. wait( & retained_id) ,
3801+ Response :: Exited {
3802+ status: ExitStatusWire :: Signaled ( libc:: SIGKILL ) ,
3803+ } ,
3804+ "independent waits must preserve a retained exec's signal status"
3805+ ) ;
3806+ }
37763807 lock ( & boundary. exec_handles ) . remove ( & retained_id) ;
37773808 assert ! (
37783809 boundary
@@ -3790,6 +3821,46 @@ mod linux {
37903821 std:: thread:: sleep ( Duration :: from_millis ( 10 ) ) ;
37913822 }
37923823 assert ! ( process. has_exited( ) , "canonical process did not exit" ) ;
3824+ assert_eq ! (
3825+ boundary. wait( & process. process_id( ) ) ,
3826+ Response :: Exited {
3827+ status: ExitStatusWire :: Exited ( 0 ) ,
3828+ }
3829+ ) ;
3830+ for exit_code in [ 0 , 7 ] {
3831+ let spec = ExecSpecWire {
3832+ program : "/bin/sh" . to_string ( ) ,
3833+ args : vec ! [ "-c" . to_string( ) , format!( "exit {exit_code}" ) ] ,
3834+ env : Vec :: new ( ) ,
3835+ workdir : None ,
3836+ pty : false ,
3837+ } ;
3838+ let request = RequestEnvelope :: new (
3839+ "sandbox-retained" . to_string ( ) ,
3840+ "a" . repeat ( 32 ) ,
3841+ Request :: Exec { spec : spec. clone ( ) } ,
3842+ )
3843+ . expect ( "build exec status request" ) ;
3844+ let exec = boundary
3845+ . start_exec ( & request. request_id , & request. payload_digest , spec)
3846+ . expect ( "start exec after canonical exit" ) ;
3847+ for _ in 0 ..2 {
3848+ assert_eq ! (
3849+ boundary. wait( & exec. process_id) ,
3850+ Response :: Exited {
3851+ status: ExitStatusWire :: Exited ( exit_code) ,
3852+ } ,
3853+ "wait must work independently of attachment consumption and main exit"
3854+ ) ;
3855+ }
3856+ }
3857+ assert ! ( matches!(
3858+ boundary. wait( "generation-retained:exec:unknown" ) ,
3859+ Response :: Error {
3860+ kind: BoundaryErrorKind :: Invalid ,
3861+ ..
3862+ }
3863+ ) ) ;
37933864
37943865 let mut session = process_runtime
37953866 . block_on (
0 commit comments