diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index cb42f44b1e..93c36b94f0 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -3943,21 +3943,7 @@ impl Session { } } - pub async fn get_pending_input(&self) -> Vec { - let mut active = self.active_turn.lock().await; - match active.as_mut() { - Some(at) => { - let mut ts = at.turn_state.lock().await; - ts.take_pending_input() - } - None => Vec::with_capacity(0), - } - } - - pub(crate) async fn prepend_pending_input( - &self, - input: Vec, - ) -> Result<(), ()> { + pub async fn prepend_pending_input(&self, input: Vec) -> Result<(), ()> { let mut active = self.active_turn.lock().await; match active.as_mut() { Some(at) => { @@ -3969,6 +3955,17 @@ impl Session { } } + pub async fn get_pending_input(&self) -> Vec { + let mut active = self.active_turn.lock().await; + match active.as_mut() { + Some(at) => { + let mut ts = at.turn_state.lock().await; + ts.take_pending_input() + } + None => Vec::with_capacity(0), + } + } + pub async fn has_pending_input(&self) -> bool { let active = self.active_turn.lock().await; match active.as_ref() { @@ -5679,13 +5676,13 @@ pub(crate) async fn run_turn( // Note that pending_input would be something like a message the user // submitted through the UI while the model was running. Though the UI // may support this, the model might not. - let pending_response_items = sess.get_pending_input().await; + let pending_input = sess.get_pending_input().await; let mut blocked_pending_input = false; let mut blocked_pending_input_contexts = Vec::new(); let mut requeued_pending_input = false; let mut accepted_pending_input = Vec::new(); - if !pending_response_items.is_empty() { - let mut pending_input_iter = pending_response_items.into_iter(); + if !pending_input.is_empty() { + let mut pending_input_iter = pending_input.into_iter(); while let Some(pending_input_item) = pending_input_iter.next() { match inspect_pending_input(&sess, &turn_context, pending_input_item).await { PendingInputHookDisposition::Accepted(pending_input) => { diff --git a/codex-rs/core/src/state/turn.rs b/codex-rs/core/src/state/turn.rs index 80576ef4dc..a6ae1ba8ca 100644 --- a/codex-rs/core/src/state/turn.rs +++ b/codex-rs/core/src/state/turn.rs @@ -179,6 +179,15 @@ impl TurnState { self.pending_input.push(input); } + pub(crate) fn prepend_pending_input(&mut self, mut input: Vec) { + if input.is_empty() { + return; + } + + input.append(&mut self.pending_input); + self.pending_input = input; + } + pub(crate) fn take_pending_input(&mut self) -> Vec { if self.pending_input.is_empty() { Vec::with_capacity(0) @@ -189,15 +198,6 @@ impl TurnState { } } - pub(crate) fn prepend_pending_input(&mut self, mut input: Vec) { - if input.is_empty() { - return; - } - - input.append(&mut self.pending_input); - self.pending_input = input; - } - pub(crate) fn has_pending_input(&self) -> bool { !self.pending_input.is_empty() } diff --git a/codex-rs/core/src/tasks/mod.rs b/codex-rs/core/src/tasks/mod.rs index 5888c0b47b..c325681e93 100644 --- a/codex-rs/core/src/tasks/mod.rs +++ b/codex-rs/core/src/tasks/mod.rs @@ -42,6 +42,7 @@ use codex_otel::metrics::names::TURN_NETWORK_PROXY_METRIC; use codex_otel::metrics::names::TURN_TOKEN_USAGE_METRIC; use codex_otel::metrics::names::TURN_TOOL_CALL_METRIC; use codex_protocol::models::ContentItem; +use codex_protocol::models::ResponseInputItem; use codex_protocol::models::ResponseItem; use codex_protocol::protocol::RolloutItem; use codex_protocol::user_input::UserInput; @@ -244,7 +245,7 @@ impl Session { .cancel_git_enrichment_task(); let mut active = self.active_turn.lock().await; - let mut pending_input = Vec::new(); + let mut pending_input = Vec::::new(); let mut should_clear_active_turn = false; let mut token_usage_at_turn_start = None; let mut turn_tool_calls = 0_u64; diff --git a/codex-rs/core/src/tools/js_repl/mod_tests.rs b/codex-rs/core/src/tools/js_repl/mod_tests.rs index 33bbd6f031..413e171d41 100644 --- a/codex-rs/core/src/tools/js_repl/mod_tests.rs +++ b/codex-rs/core/src/tools/js_repl/mod_tests.rs @@ -1831,7 +1831,7 @@ await codex.emitImage({ bytes: png, mimeType: "image/png", detail: null }); detail: None, }] .as_slice() - ); + ); assert!(session.get_pending_input().await.is_empty()); Ok(())