Persist pending input user events (#10656)

- Persist user-message events for mid-turn injected input by emitting
user message turn items when pending input is recorded.
This commit is contained in:
Ahmed Ibrahim 2026-02-04 11:47:10 -08:00 committed by GitHub
parent ae4de43ccc
commit 7a253076fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 6 deletions

View file

@ -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()

View file

@ -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;