From 1ffa95ee8a02ec68f6ccd758998bcb7d4b32bcdb Mon Sep 17 00:00:00 2001 From: felixxia-oai Date: Wed, 14 Oct 2026 21:00:03 +0000 Subject: [PATCH] Wait for readiness in the SIGTERM cancellation test (#54099) ## What changed Wait for the subprocess readiness marker before cancelling in `process_exec_tool_call_cancellation_allows_sigterm_cleanup`, removing the one-second polling cutoff. Poll readiness alongside execution under the existing five-second timeout, then cancel and await execution if that timeout expires so cleanup completes before the test fails. GitOrigin-RevId: ba47dad9ba87fb5dc3bd087380811655387f825a --- codex-rs/core/src/exec_tests.rs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/codex-rs/core/src/exec_tests.rs b/codex-rs/core/src/exec_tests.rs index f86df094b8..87d730a56a 100644 --- a/codex-rs/core/src/exec_tests.rs +++ b/codex-rs/core/src/exec_tests.rs @@ -1526,16 +1526,12 @@ while :; do sleep 1; done"# ); let cancel_token = CancellationToken::new(); let cancel_tx = cancel_token.clone(); - tokio::spawn(async move { - for _ in 0..50 { - if ready_marker.exists() { - cancel_tx.cancel(); - return; - } + let cancel_when_ready = async { + while !ready_marker.exists() { tokio::time::sleep(Duration::from_millis(20)).await; } cancel_tx.cancel(); - }); + }; let params = ExecParams { command, cwd: cwd.clone(), @@ -1550,8 +1546,7 @@ while :; do sleep 1; done"# arg0: None, }; - let result = timeout( - Duration::from_secs(5), + let execution = async { process_exec_tool_call( params, &PermissionProfile::Disabled, @@ -1561,10 +1556,22 @@ while :; do sleep 1; done"# /*codex_self_exe*/ &None, /*use_legacy_landlock*/ false, /*stdout_stream*/ None, - ), - ) - .await - .expect("cancellation should stop the process promptly"); + ) + .await + }; + tokio::pin!(execution); + let result = timeout(Duration::from_secs(5), async { + tokio::select! { + result = &mut execution => result, + () = cancel_when_ready => (&mut execution).await, + } + }) + .await; + if result.is_err() { + cancel_tx.cancel(); + let _ = execution.await; + } + let result = result.expect("cancellation should stop the process promptly"); let output = result.expect("cancellation should return a non-timeout exec result"); assert!(!output.timed_out); assert_eq!(