Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

chore: clamp min yield time for empty write_stdin (#9156)

jif-oai32b1795ff470
diff --git a/codex-rs/core/src/unified_exec/mod.rs b/codex-rs/core/src/unified_exec/mod.rs
index e84b63098a..a30ba364ca 100644
--- a/codex-rs/core/src/unified_exec/mod.rs
+++ b/codex-rs/core/src/unified_exec/mod.rs
@@ -45,6 +45,8 @@ pub(crate) use errors::UnifiedExecError;
pub(crate) use process::UnifiedExecProcess;
pub(crate) const MIN_YIELD_TIME_MS: u64 = 250;
+// 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;
pub(crate) const DEFAULT_MAX_OUTPUT_TOKENS: usize = 10_000;
pub(crate) const UNIFIED_EXEC_OUTPUT_MAX_BYTES: usize = 1024 * 1024; // 1 MiB
diff --git a/codex-rs/core/src/unified_exec/process_manager.rs b/codex-rs/core/src/unified_exec/process_manager.rs
index 80f0a4841e..a50efeb70b 100644
--- a/codex-rs/core/src/unified_exec/process_manager.rs
+++ b/codex-rs/core/src/unified_exec/process_manager.rs
@@ -26,6 +26,8 @@ use crate::truncate::approx_token_count;
use crate::truncate::formatted_truncate_text;
use crate::unified_exec::ExecCommandRequest;
use crate::unified_exec::MAX_UNIFIED_EXEC_PROCESSES;
+use crate::unified_exec::MAX_YIELD_TIME_MS;
+use crate::unified_exec::MIN_EMPTY_YIELD_TIME_MS;
use crate::unified_exec::ProcessEntry;
use crate::unified_exec::ProcessStore;
use crate::unified_exec::UnifiedExecContext;
@@ -263,7 +265,14 @@ impl UnifiedExecProcessManager {
}
let max_tokens = resolve_max_tokens(request.max_output_tokens);
- let yield_time_ms = clamp_yield_time(request.yield_time_ms);
+ let yield_time_ms = {
+ let time_ms = clamp_yield_time(request.yield_time_ms);
+ if request.input.is_empty() {
+ time_ms.clamp(MIN_EMPTY_YIELD_TIME_MS, MAX_YIELD_TIME_MS)
+ } else {
+ time_ms
+ }
+ };
let start = Instant::now();
let deadline = start + Duration::from_millis(yield_time_ms);
let collected = Self::collect_output_until_deadline(
diff --git a/codex-rs/core/tests/suite/unified_exec.rs b/codex-rs/core/tests/suite/unified_exec.rs
index 2e2fd34e67..1bb4ba8ad1 100644
--- a/codex-rs/core/tests/suite/unified_exec.rs
+++ b/codex-rs/core/tests/suite/unified_exec.rs
@@ -902,21 +902,21 @@ async fn unified_exec_terminal_interaction_captures_delayed_output() -> Result<(
// and a final long poll to capture the second marker.
let first_poll_call_id = "uexec-delayed-poll-1";
let first_poll_args = json!({
- "chars": "",
+ "chars": "x",
"session_id": 1000,
"yield_time_ms": 10,
});
let second_poll_call_id = "uexec-delayed-poll-2";
let second_poll_args = json!({
- "chars": "",
+ "chars": "x",
"session_id": 1000,
"yield_time_ms": 4000,
});
let third_poll_call_id = "uexec-delayed-poll-3";
let third_poll_args = json!({
- "chars": "",
+ "chars": "x",
"session_id": 1000,
"yield_time_ms": 6000,
});
@@ -1037,7 +1037,7 @@ async fn unified_exec_terminal_interaction_captures_delayed_output() -> Result<(
.iter()
.map(|ev| ev.stdin.as_str())
.collect::<Vec<_>>(),
- vec!["", "", ""],
+ vec!["x", "x", "x"],
"terminal interactions should reflect the three stdin polls"
);