From 1e0e55330424ad4d49fb060fa264c904b7a7f7d0 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Mon, 3 Nov 2025 16:23:04 -0600 Subject: [PATCH] Fixed notify handler so it passes correct `input_messages` details (#6143) This fixes bug #6121. The `input_messages` field passed to the notify handler is currently empty because the logic is incorrectly including the OutputText rather than InputText. I've fixed that and added proper filtering to remove messages associated with AGENTS.md and other context injected by the harness. Testing: I wrote a notify handler and verified that the user prompt is correctly passed through to the handler. --- codex-rs/core/src/codex.rs | 15 +++++---------- codex-rs/core/tests/suite/user_notification.rs | 9 +++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 1199c6ca..a2756a7a 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -1773,19 +1773,14 @@ pub(crate) async fn run_task( sess.clone_history().await.get_history_for_prompt() }; - let turn_input_messages: Vec = turn_input + let turn_input_messages = turn_input .iter() - .filter_map(|item| match item { - ResponseItem::Message { content, .. } => Some(content), + .filter_map(|item| match parse_turn_item(item) { + Some(TurnItem::UserMessage(user_message)) => Some(user_message), _ => None, }) - .flat_map(|content| { - content.iter().filter_map(|item| match item { - ContentItem::OutputText { text } => Some(text.clone()), - _ => None, - }) - }) - .collect(); + .map(|user_message| user_message.message()) + .collect::>(); match run_turn( Arc::clone(&sess), Arc::clone(&turn_context), diff --git a/codex-rs/core/tests/suite/user_notification.rs b/codex-rs/core/tests/suite/user_notification.rs index 11deb70f..6fc31370 100644 --- a/codex-rs/core/tests/suite/user_notification.rs +++ b/codex-rs/core/tests/suite/user_notification.rs @@ -11,6 +11,9 @@ use core_test_support::skip_if_no_network; use core_test_support::test_codex::TestCodex; use core_test_support::test_codex::test_codex; use core_test_support::wait_for_event; +use pretty_assertions::assert_eq; +use serde_json::Value; +use serde_json::json; use tempfile::TempDir; use wiremock::matchers::any; @@ -61,6 +64,12 @@ echo -n "${@: -1}" > $(dirname "${0}")/notify.txt"#, // We fork the notify script, so we need to wait for it to write to the file. fs_wait::wait_for_path_exists(¬ify_file, Duration::from_secs(5)).await?; + let notify_payload_raw = tokio::fs::read_to_string(¬ify_file).await?; + let payload: Value = serde_json::from_str(¬ify_payload_raw)?; + + assert_eq!(payload["type"], json!("agent-turn-complete")); + assert_eq!(payload["input-messages"], json!(["hello world"])); + assert_eq!(payload["last-assistant-message"], json!("Done")); Ok(()) }