Skip to content

Commit de08b8a

Browse files
Fixed notify handler so it passes correct input_messages details (openai#6143)
This fixes bug openai#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.
1 parent 8105479 commit de08b8a

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

codex-rs/core/src/codex.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,19 +1773,14 @@ pub(crate) async fn run_task(
17731773
sess.clone_history().await.get_history_for_prompt()
17741774
};
17751775

1776-
let turn_input_messages: Vec<String> = turn_input
1776+
let turn_input_messages = turn_input
17771777
.iter()
1778-
.filter_map(|item| match item {
1779-
ResponseItem::Message { content, .. } => Some(content),
1778+
.filter_map(|item| match parse_turn_item(item) {
1779+
Some(TurnItem::UserMessage(user_message)) => Some(user_message),
17801780
_ => None,
17811781
})
1782-
.flat_map(|content| {
1783-
content.iter().filter_map(|item| match item {
1784-
ContentItem::OutputText { text } => Some(text.clone()),
1785-
_ => None,
1786-
})
1787-
})
1788-
.collect();
1782+
.map(|user_message| user_message.message())
1783+
.collect::<Vec<String>>();
17891784
match run_turn(
17901785
Arc::clone(&sess),
17911786
Arc::clone(&turn_context),

codex-rs/core/tests/suite/user_notification.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ use core_test_support::skip_if_no_network;
1111
use core_test_support::test_codex::TestCodex;
1212
use core_test_support::test_codex::test_codex;
1313
use core_test_support::wait_for_event;
14+
use pretty_assertions::assert_eq;
15+
use serde_json::Value;
16+
use serde_json::json;
1417
use tempfile::TempDir;
1518
use wiremock::matchers::any;
1619

@@ -61,6 +64,12 @@ echo -n "${@: -1}" > $(dirname "${0}")/notify.txt"#,
6164

6265
// We fork the notify script, so we need to wait for it to write to the file.
6366
fs_wait::wait_for_path_exists(&notify_file, Duration::from_secs(5)).await?;
67+
let notify_payload_raw = tokio::fs::read_to_string(&notify_file).await?;
68+
let payload: Value = serde_json::from_str(&notify_payload_raw)?;
69+
70+
assert_eq!(payload["type"], json!("agent-turn-complete"));
71+
assert_eq!(payload["input-messages"], json!(["hello world"]));
72+
assert_eq!(payload["last-assistant-message"], json!("Done"));
6473

6574
Ok(())
6675
}

0 commit comments

Comments
 (0)