From 42266240fde628ef74c2b4e2a54d9bde059cd3e6 Mon Sep 17 00:00:00 2001 From: jif Date: Thu, 24 Sep 2026 15:55:28 +0000 Subject: [PATCH] Fix PID reservation test race and update guardian heartbeat snapshot (#47871) ## Why The PID reservation test could race with the backend's read on Windows by deleting the PID file from its cleanup task. The guardian heartbeat snapshot and environment normalization also needed to match the current permission-context wording. ## What changed - Release the reservation lock and let `stop()` remove the stale PID file, then assert that the file is gone. - Update the guardian heartbeat snapshot and normalization pattern to use `The active permission profile for environment`. GitOrigin-RevId: d9cadae0e5d36cb2e1ab0517e2d7121cf2d0715d --- codex-rs/app-server-daemon/src/backend/pid_tests.rs | 12 ++++++------ .../core/tests/suite/scenarios_guardian_heartbeat.rs | 4 ++-- ...t_repetitions_keep_later_human_authorization.snap | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/codex-rs/app-server-daemon/src/backend/pid_tests.rs b/codex-rs/app-server-daemon/src/backend/pid_tests.rs index cf9c5b4e3b..19d262c097 100644 --- a/codex-rs/app-server-daemon/src/backend/pid_tests.rs +++ b/codex-rs/app-server-daemon/src/backend/pid_tests.rs @@ -109,16 +109,16 @@ async fn stop_waits_for_live_reservation_to_resolve() { .await .expect("open pid lock file"); assert!(try_lock_file(&reservation).expect("lock reservation")); - let cleanup = tokio::spawn(async move { - tokio::time::sleep(Duration::from_millis(50)).await; + let release_reservation = tokio::spawn(async move { + tokio::time::sleep(Duration::from_millis(/*millis*/ 50)).await; + // Let stop() remove the stale PID file under the reservation lock. + // Deleting it here would race with the backend's read on Windows. drop(reservation); - tokio::fs::remove_file(pid_file) - .await - .expect("remove pid file"); }); backend.stop().await.expect("stop"); - cleanup.await.expect("cleanup task"); + release_reservation.await.expect("release reservation task"); + assert!(!pid_file.exists()); } #[tokio::test] diff --git a/codex-rs/core/tests/suite/scenarios_guardian_heartbeat.rs b/codex-rs/core/tests/suite/scenarios_guardian_heartbeat.rs index 6d9dc25437..2ae5b5947a 100644 --- a/codex-rs/core/tests/suite/scenarios_guardian_heartbeat.rs +++ b/codex-rs/core/tests/suite/scenarios_guardian_heartbeat.rs @@ -133,8 +133,8 @@ async fn heartbeat_repetitions_keep_later_human_authorization() -> anyhow::Resul "$1\"\"", ), ( - r#"(For this action on environment )"(?:local|remote)","#, - "$1\"\",", + r#"(The active permission profile for environment )"(?:local|remote)""#, + "$1\"\"", ), (r#"(?m)^(\s*"cwd": )"[^"]*""#, "$1\"\""), ( diff --git a/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__guardian_heartbeat__heartbeat_repetitions_keep_later_human_authorization.snap b/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__guardian_heartbeat__heartbeat_repetitions_keep_later_human_authorization.snap index a02eca419c..3d390552f2 100644 --- a/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__guardian_heartbeat__heartbeat_repetitions_keep_later_human_authorization.snap +++ b/codex-rs/core/tests/suite/snapshots/all__suite__scenarios__guardian_heartbeat__heartbeat_repetitions_keep_later_human_authorization.snap @@ -147,7 +147,7 @@ Scenario: Three scheduled runs share one instruction body, a human overrides its [24] >>> PARENT TURN PERMISSION CONTEXT START - [25] For this action on environment "", the active permission profile has no explicit denied-read paths/globs. + [25] The active permission profile for environment "" has no explicit denied-read paths/globs. [26] >>> PARENT TURN PERMISSION CONTEXT END