diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 5cac6b94dd..efc97107c0 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -586,14 +586,7 @@ impl Session { self.record_conversation_items_internal(&responses, false).await; } - let mut msgs = Vec::new(); - for event in items.as_slice().get_events() { - match event.msg { - EventMsg::UserMessage(_) | EventMsg::AgentMessage(_) => msgs.push(event.msg), - _ => {} - } - } - msgs + items.as_slice().get_events() } /// Sends the given event to the client and records it to the rollout (if enabled). diff --git a/codex-rs/core/src/conversation_manager.rs b/codex-rs/core/src/conversation_manager.rs index 3c2615a243..b222e9bb4b 100644 --- a/codex-rs/core/src/conversation_manager.rs +++ b/codex-rs/core/src/conversation_manager.rs @@ -47,7 +47,7 @@ impl InitialHistory { } /// Return all events contained in this initial history. - pub fn get_events(&self) -> Vec { + pub fn get_events(&self) -> Vec { match self { InitialHistory::New => Vec::new(), InitialHistory::Resumed(items) => items.as_slice().get_events(), diff --git a/codex-rs/core/src/rollout/recorder.rs b/codex-rs/core/src/rollout/recorder.rs index 532e23a2d7..7870bafc8a 100644 --- a/codex-rs/core/src/rollout/recorder.rs +++ b/codex-rs/core/src/rollout/recorder.rs @@ -8,6 +8,7 @@ use std::path::PathBuf; use codex_protocol::mcp_protocol::ConversationId; use codex_protocol::protocol::Event; +use codex_protocol::protocol::EventMsg; use serde::Deserialize; use serde::Serialize; use time::OffsetDateTime; @@ -133,7 +134,7 @@ impl From for RolloutItem { /// Convenience helpers to extract typed items from a list of rollout items. pub trait RolloutItemSliceExt { fn get_response_items(&self) -> Vec; - fn get_events(&self) -> Vec; + fn get_events(&self) -> Vec; } impl RolloutItemSliceExt for [RolloutItem] { @@ -146,10 +147,10 @@ impl RolloutItemSliceExt for [RolloutItem] { .collect() } - fn get_events(&self) -> Vec { + fn get_events(&self) -> Vec { self.iter() .filter_map(|it| match it { - RolloutItem::Event(ev) => Some(ev.clone()), + RolloutItem::Event(ev) => Some(ev.msg.clone()), _ => None, }) .collect() diff --git a/codex-rs/core/tests/suite/fork_conversation.rs b/codex-rs/core/tests/suite/fork_conversation.rs index bc9a1ec368..5b9c26a7ae 100644 --- a/codex-rs/core/tests/suite/fork_conversation.rs +++ b/codex-rs/core/tests/suite/fork_conversation.rs @@ -100,19 +100,6 @@ async fn fork_conversation_twice_drops_to_first_message() { } out } - async fn read_response_entries_with_retry( - path: &std::path::Path, - min_len: usize, - ) -> Vec { - for _ in 0..50u32 { - let entries = read_response_entries(path).await; - if entries.len() >= min_len { - return entries; - } - tokio::time::sleep(tokio::time::Duration::from_millis(10)).await; - } - read_response_entries(path).await - } let entries_after_three: Vec = read_response_entries(&base_path).await; // History layout for this test: // [0] user instructions, @@ -160,8 +147,7 @@ async fn fork_conversation_twice_drops_to_first_message() { }) => (*conversation_id, path.clone()), _ => panic!("expected ConversationHistory event after first fork"), }; - let entries_after_first_fork: Vec = - read_response_entries_with_retry(&fork1_path, expected_after_first.len()).await; + let entries_after_first_fork: Vec = read_response_entries(&fork1_path).await; assert_eq!(entries_after_first_fork, expected_after_first); // Fork again with n=1 → drops the (new) last user message, leaving only the first. @@ -185,7 +171,6 @@ async fn fork_conversation_twice_drops_to_first_message() { }) => (*conversation_id, path.clone()), _ => panic!("expected ConversationHistory event after second fork"), }; - let entries_after_second_fork: Vec = - read_response_entries_with_retry(&fork2_path, expected_after_second.len()).await; + let entries_after_second_fork: Vec = read_response_entries(&fork2_path).await; assert_eq!(entries_after_second_fork, expected_after_second); }