Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Persist pending input user events (#10656)

Ahmed Ibrahim7a253076fef8
diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs
index 5368b8b062..b1d2fdf45e 100644
--- a/codex-rs/core/src/codex.rs
+++ b/codex-rs/core/src/codex.rs
@@ -3579,19 +3579,35 @@ 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_input = sess
+ let pending_response_items = sess
.get_pending_input()
.await
.into_iter()
.map(ResponseItem::from)
.collect::<Vec<ResponseItem>>();
+ if !pending_response_items.is_empty() {
+ for response_item in pending_response_items {
+ if let Some(TurnItem::UserMessage(user_message)) = parse_turn_item(&response_item) {
+ // todo(aibrahim): move pending input to be UserInput only to keep TextElements. context: https://github.com/openai/codex/pull/10656#discussion_r2765522480
+ sess.record_user_prompt_and_emit_turn_item(
+ turn_context.as_ref(),
+ &user_message.content,
+ response_item,
+ )
+ .await;
+ } else {
+ sess.record_conversation_items(
+ &turn_context,
+ std::slice::from_ref(&response_item),
+ )
+ .await;
+ }
+ }
+ }
+
// Construct the input that we will send to the model.
- let sampling_request_input: Vec<ResponseItem> = {
- sess.record_conversation_items(&turn_context, &pending_input)
- .await;
- sess.clone_history().await.for_prompt()
- };
+ let sampling_request_input: Vec<ResponseItem> = { sess.clone_history().await.for_prompt() };
let sampling_request_input_messages = sampling_request_input
.iter()
diff --git a/codex-rs/core/tests/suite/pending_input.rs b/codex-rs/core/tests/suite/pending_input.rs
index ad662d901b..1fcff4da3b 100644
--- a/codex-rs/core/tests/suite/pending_input.rs
+++ b/codex-rs/core/tests/suite/pending_input.rs
@@ -125,6 +125,11 @@ async fn injected_user_input_triggers_follow_up_request_with_deltas() {
let _ = gate_completed_tx.send(());
+ let _ = wait_for_event(&codex, |event| {
+ matches!(event, EventMsg::UserMessage(message) if message.message == "second prompt")
+ })
+ .await;
+
wait_for_event(&codex, |event| matches!(event, EventMsg::TurnComplete(_))).await;
let requests = server.requests().await;