@@ -1241,6 +1241,8 @@ impl App<'_> {
12411241
12421242 if pid == 0 {
12431243 // Child process
1244+ crate :: logging:: disable_streaming ( ) ;
1245+ crate :: logging:: clear_logs ( ) ;
12441246 unsafe {
12451247 libc:: setsid ( ) ;
12461248 // Reset common signals to default so the child process terminates cleanly and instantly on signals.
@@ -1274,7 +1276,10 @@ impl App<'_> {
12741276 ) ;
12751277 let elapsed = thread_start. elapsed ( ) ;
12761278
1277- let data = result. map ( |r| ( r, elapsed) ) ;
1279+ log:: info!( "Child process completed" ) ;
1280+ let child_logs = crate :: logging:: take_logs ( ) ;
1281+
1282+ let data = ( result. map ( |r| ( r, elapsed) ) , child_logs) ;
12781283 if let Ok ( serialized) = serde_json:: to_vec ( & data) {
12791284 let mut file = unsafe { std:: fs:: File :: from_raw_fd ( write_fd) } ;
12801285 use std:: io:: Write ;
@@ -1289,8 +1294,6 @@ impl App<'_> {
12891294 }
12901295 }
12911296
1292- log:: info!( "Child process completed" ) ;
1293-
12941297 // Use _exit to avoid running atexit handlers in the child process.
12951298 unsafe {
12961299 libc:: _exit ( 0 ) ;
@@ -1307,18 +1310,33 @@ impl App<'_> {
13071310 . spawn ( move || {
13081311 let mut file = unsafe { std:: fs:: File :: from_raw_fd ( read_fd) } ;
13091312 let mut len_buf = [ 0u8 ; 8 ] ;
1310- let res = if std:: io:: Read :: read_exact ( & mut file, & mut len_buf) . is_err ( ) {
1313+ let payload: Option < (
1314+ Option < ( ActiveSuggestionsBuilder , std:: time:: Duration ) > ,
1315+ Vec < String > ,
1316+ ) > = if std:: io:: Read :: read_exact ( & mut file, & mut len_buf) . is_err ( ) {
13111317 None
13121318 } else {
13131319 let len = u64:: from_ne_bytes ( len_buf) ;
13141320 let mut data_buf = vec ! [ 0u8 ; len as usize ] ;
13151321 if std:: io:: Read :: read_exact ( & mut file, & mut data_buf) . is_ok ( ) {
1316- serde_json:: from_slice ( & data_buf) . ok ( ) . flatten ( )
1322+ serde_json:: from_slice ( & data_buf) . ok ( )
13171323 } else {
13181324 None
13191325 }
13201326 } ;
1321- let _ = tx. send ( res) ;
1327+
1328+ let ( completion_res, child_logs) = if let Some ( ( res, logs) ) = payload {
1329+ ( res, logs)
1330+ } else {
1331+ ( None , vec ! [ ] )
1332+ } ;
1333+
1334+ // Replay child logs inside the parent process
1335+ for log_line in child_logs {
1336+ crate :: logging:: log_raw_entry ( log_line) ;
1337+ }
1338+
1339+ let _ = tx. send ( completion_res) ;
13221340
13231341 // Reap the child process to prevent zombie processes
13241342 unsafe {
0 commit comments