From b277a654facca3dbfa5413bab68235f947f759ee Mon Sep 17 00:00:00 2001 From: Ahmed Ibrahim Date: Fri, 22 Aug 2025 19:54:58 -0700 Subject: [PATCH] rust --- codex-rs/core/src/codex.rs | 3 ++- codex-rs/core/src/exec.rs | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index ea6ae8ce7c..c683978c37 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -142,6 +142,7 @@ pub struct CodexSpawnOk { } pub(crate) const INITIAL_SUBMIT_ID: &str = ""; +pub(crate) const SUBMISSION_CHANNEL_CAPACITY: usize = 64; // Model-formatting limits: clients get full streams; only formatted summary is capped. pub(crate) const MODEL_FORMAT_MAX_BYTES: usize = 10 * 1024; // 10 KiB @@ -157,7 +158,7 @@ impl Codex { auth_manager: Arc, initial_history: Option>, ) -> CodexResult { - let (tx_sub, rx_sub) = async_channel::bounded(64); + let (tx_sub, rx_sub) = async_channel::bounded(SUBMISSION_CHANNEL_CAPACITY); let (tx_event, rx_event) = async_channel::unbounded(); let user_instructions = get_user_instructions(&config).await; diff --git a/codex-rs/core/src/exec.rs b/codex-rs/core/src/exec.rs index e90e9061e2..d74ec9fcd3 100644 --- a/codex-rs/core/src/exec.rs +++ b/codex-rs/core/src/exec.rs @@ -34,6 +34,11 @@ const DEFAULT_TIMEOUT_MS: u64 = 10_000; // for these. const SIGKILL_CODE: i32 = 9; const TIMEOUT_CODE: i32 = 64; +const EXIT_CODE_SIGNAL_BASE: i32 = 128; // conventional shell: 128 + signal + +// I/O buffer sizing +const READ_CHUNK_SIZE: usize = 8192; // bytes per read +const AGGREGATE_BUFFER_INITIAL_CAPACITY: usize = 8 * 1024; // 8 KiB #[derive(Debug, Clone)] pub struct ExecParams { @@ -299,13 +304,13 @@ async fn consume_truncated_output( // timeout child.start_kill()?; // Debatable whether `child.wait().await` should be called here. - synthetic_exit_status(128 + TIMEOUT_CODE) + synthetic_exit_status(EXIT_CODE_SIGNAL_BASE + TIMEOUT_CODE) } } } _ = tokio::signal::ctrl_c() => { child.start_kill()?; - synthetic_exit_status(128 + SIGKILL_CODE) + synthetic_exit_status(EXIT_CODE_SIGNAL_BASE + SIGKILL_CODE) } }; @@ -314,7 +319,7 @@ async fn consume_truncated_output( drop(agg_tx); - let mut combined_buf = Vec::with_capacity(8 * 1024); + let mut combined_buf = Vec::with_capacity(AGGREGATE_BUFFER_INITIAL_CAPACITY); while let Ok(chunk) = agg_rx.recv().await { append_all(&mut combined_buf, &chunk); } @@ -337,8 +342,8 @@ async fn read_capped( is_stderr: bool, aggregate_tx: Option>>, ) -> io::Result>> { - let mut buf = Vec::with_capacity(8 * 1024); - let mut tmp = [0u8; 8192]; + let mut buf = Vec::with_capacity(AGGREGATE_BUFFER_INITIAL_CAPACITY); + let mut tmp = [0u8; READ_CHUNK_SIZE]; // No caps: append all bytes