@@ -423,7 +423,7 @@ fn main() -> Result<()> {
423423 } ;
424424 let admitted_isolation_backend =
425425 std:: env:: var ( openshell_core:: sandbox_env:: ADMITTED_ISOLATION_BACKEND ) . ok ( ) ;
426- Box :: pin ( openshell_supervisor:: run_sandbox (
426+ let result = Box :: pin ( openshell_supervisor:: run_sandbox (
427427 command,
428428 workdir,
429429 args. timeout ,
@@ -445,9 +445,8 @@ fn main() -> Result<()> {
445445 admitted_isolation_backend,
446446 args. main_exit_marker ,
447447 ) )
448- . await
449- . map ( supervisor_exit_status)
450- . or_else ( workspace_validation_exit)
448+ . await ;
449+ supervisor_exit ( result)
451450 }
452451 SupervisorRole :: NetworkProxy => {
453452 let listen = args. listen . unwrap_or_else ( || ( [ 127 , 0 , 0 , 1 ] , 3128 ) . into ( ) ) ;
@@ -488,31 +487,27 @@ fn otlp_span_filter(log_level: &str) -> EnvFilter {
488487 EnvFilter :: new ( format ! ( "info,openshell={level}" ) )
489488}
490489
491- /// Exit with the reserved status when the sandbox rejects the image working
492- /// directory, so the compute driver can report the specific failure.
493- fn workspace_validation_exit ( error : miette:: Report ) -> Result < i32 > {
494- use openshell_core:: driver_utils:: SUPERVISOR_EXIT_WORKSPACE_VALIDATION_FAILED ;
495- if error
496- . downcast_ref :: < openshell_supervisor:: WorkspaceValidationFailed > ( )
497- . is_none ( )
498- {
499- return Err ( error) ;
500- }
501- error ! ( "Image workspace validation failed" ) ;
502- eprintln ! ( "{error:?}" ) ;
503- Ok ( SUPERVISOR_EXIT_WORKSPACE_VALIDATION_FAILED )
504- }
505-
506- /// The supervisor exits with the workload's status after the workload exits.
507- /// Keep the reserved workspace-validation status for workspace rejections, so
508- /// drivers do not misreport a workload that itself exited with it. The gateway
509- /// receives the workload's exact status separately.
510- fn supervisor_exit_status ( workload_status : i32 ) -> i32 {
490+ /// Choose the supervisor's exit status for a sandbox run.
491+ ///
492+ /// The reserved status tells the compute driver that the sandbox rejected the
493+ /// image working directory. After the workload exits, the supervisor exits
494+ /// with the workload's status, so a workload that itself exits with the
495+ /// reserved status is reported as 1 instead. The gateway receives the
496+ /// workload's exact status separately.
497+ fn supervisor_exit ( result : Result < i32 > ) -> Result < i32 > {
511498 use openshell_core:: driver_utils:: SUPERVISOR_EXIT_WORKSPACE_VALIDATION_FAILED ;
512- if workload_status == SUPERVISOR_EXIT_WORKSPACE_VALIDATION_FAILED {
513- 1
514- } else {
515- workload_status
499+ match result {
500+ Ok ( SUPERVISOR_EXIT_WORKSPACE_VALIDATION_FAILED ) => Ok ( 1 ) ,
501+ Err ( error)
502+ if error
503+ . downcast_ref :: < openshell_supervisor:: WorkspaceValidationFailed > ( )
504+ . is_some ( ) =>
505+ {
506+ error ! ( "Image workspace validation failed" ) ;
507+ eprintln ! ( "{error:?}" ) ;
508+ Ok ( SUPERVISOR_EXIT_WORKSPACE_VALIDATION_FAILED )
509+ }
510+ other => other,
516511 }
517512}
518513
@@ -530,7 +525,7 @@ mod tests {
530525 }
531526
532527 #[ test]
533- fn workspace_validation_failure_exits_with_reserved_status ( ) {
528+ fn only_workspace_validation_failure_exits_with_reserved_status ( ) {
534529 use miette:: WrapErr as _;
535530 use openshell_core:: driver_utils:: {
536531 SUPERVISOR_EXIT_WORKSPACE_VALIDATION_FAILED , WORKSPACE_VALIDATION_ERROR_CONTEXT ,
@@ -546,34 +541,31 @@ mod tests {
546541 "process error: boundary process leaf: start process supervisor leaf: {sandbox_error:?}"
547542 ) ) ;
548543 assert_eq ! (
549- workspace_validation_exit ( error) . expect( "reserved exit status" ) ,
544+ supervisor_exit ( Err ( error) ) . expect( "reserved exit status" ) ,
550545 SUPERVISOR_EXIT_WORKSPACE_VALIDATION_FAILED
551546 ) ;
552547 assert ! (
553- workspace_validation_exit ( openshell_supervisor:: start_agent_error(
548+ supervisor_exit ( Err ( openshell_supervisor:: start_agent_error(
554549 "connect failed" . into( )
555- ) )
550+ ) ) )
556551 . is_err( )
557552 ) ;
558553 // Only an agent start failure carries the rejection, even when another
559554 // error's text contains the same words.
560555 assert ! (
561- workspace_validation_exit ( miette:: miette!(
556+ supervisor_exit ( Err ( miette:: miette!(
562557 "policy sync failed: {WORKSPACE_VALIDATION_ERROR_CONTEXT}"
563- ) )
558+ ) ) )
564559 . is_err( )
565560 ) ;
566- }
567561
568- #[ test]
569- fn workload_exit_does_not_use_reserved_workspace_status ( ) {
570- use openshell_core:: driver_utils:: SUPERVISOR_EXIT_WORKSPACE_VALIDATION_FAILED ;
562+ // A workload's own exit with the reserved status is not a rejection.
571563 assert_eq ! (
572- supervisor_exit_status ( SUPERVISOR_EXIT_WORKSPACE_VALIDATION_FAILED ) ,
564+ supervisor_exit ( Ok ( SUPERVISOR_EXIT_WORKSPACE_VALIDATION_FAILED ) ) . unwrap ( ) ,
573565 1
574566 ) ;
575- assert_eq ! ( supervisor_exit_status ( 0 ) , 0 ) ;
576- assert_eq ! ( supervisor_exit_status ( 143 ) , 143 ) ;
567+ assert_eq ! ( supervisor_exit ( Ok ( 0 ) ) . unwrap ( ) , 0 ) ;
568+ assert_eq ! ( supervisor_exit ( Ok ( 143 ) ) . unwrap ( ) , 143 ) ;
577569 }
578570
579571 #[ test]
0 commit comments