Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions codex-rs/core/src/unified_exec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub(crate) use process::SpawnLifecycleHandle;
pub(crate) use process::UnifiedExecProcess;

pub(crate) const MIN_YIELD_TIME_MS: u64 = 250;
pub(crate) const WINDOWS_INITIAL_EXEC_YIELD_TIME_FLOOR_MS: u64 = 2_000;
// Minimum yield time for an empty `write_stdin`.
pub(crate) const MIN_EMPTY_YIELD_TIME_MS: u64 = 5_000;
pub(crate) const MAX_YIELD_TIME_MS: u64 = 30_000;
Expand Down Expand Up @@ -163,6 +164,11 @@ struct ProcessEntry {
}

pub(crate) fn clamp_yield_time(yield_time_ms: u64) -> u64 {
let yield_time_ms = if cfg!(windows) {
yield_time_ms.max(WINDOWS_INITIAL_EXEC_YIELD_TIME_FLOOR_MS)
} else {
yield_time_ms
};
yield_time_ms.clamp(MIN_YIELD_TIME_MS, MAX_YIELD_TIME_MS)
}

Expand Down
27 changes: 27 additions & 0 deletions codex-rs/core/src/unified_exec/process_manager_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::*;
use crate::unified_exec::clamp_yield_time;
use pretty_assertions::assert_eq;
use tokio::time::Duration;
use tokio::time::Instant;
Expand Down Expand Up @@ -130,6 +131,32 @@ fn exec_server_process_id_matches_unified_exec_process_id() {
assert_eq!(exec_server_process_id(/*process_id*/ 4321), "4321");
}

#[cfg(windows)]
#[test]
fn initial_exec_yield_time_uses_windows_floor() {
let above_max_yield_time_ms = crate::unified_exec::MAX_YIELD_TIME_MS + 1;

assert_eq!(
clamp_yield_time(/*yield_time_ms*/ 1_000),
crate::unified_exec::WINDOWS_INITIAL_EXEC_YIELD_TIME_FLOOR_MS
);
assert_eq!(clamp_yield_time(/*yield_time_ms*/ 10_000), 10_000);
assert_eq!(
clamp_yield_time(/*yield_time_ms*/ above_max_yield_time_ms),
crate::unified_exec::MAX_YIELD_TIME_MS
);
}

#[cfg(not(windows))]
#[test]
fn initial_exec_yield_time_has_no_platform_floor() {
assert_eq!(clamp_yield_time(/*yield_time_ms*/ 1_000), 1_000);
assert_eq!(
clamp_yield_time(/*yield_time_ms*/ 1),
crate::unified_exec::MIN_YIELD_TIME_MS
);
}

#[tokio::test]
async fn network_denial_fallback_message_names_sandbox_network_proxy() {
let message = network_denial_message_for_session(/*session*/ None, /*deferred*/ None).await;
Expand Down
Loading