mirror of
https://github.com/openai/codex.git
synced 2026-04-24 06:35:50 +00:00
codex: address PR review feedback (#15106)
This commit is contained in:
@@ -286,6 +286,13 @@ impl EventProcessorWithJsonOutput {
|
||||
Some(ExecThreadItem { id, details })
|
||||
}
|
||||
|
||||
fn final_message_from_turn_items(items: &[ThreadItem]) -> Option<String> {
|
||||
items.iter().rev().find_map(|item| match item {
|
||||
ThreadItem::AgentMessage { text, .. } => Some(text.clone()),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
fn thread_started_event(session_configured: &SessionConfiguredEvent) -> ThreadEvent {
|
||||
ThreadEvent::ThreadStarted(ThreadStartedEvent {
|
||||
thread_id: session_configured.session_id.to_string(),
|
||||
@@ -397,6 +404,11 @@ impl EventProcessorWithJsonOutput {
|
||||
}
|
||||
match notification.turn.status {
|
||||
TurnStatus::Completed => {
|
||||
if self.final_message.is_none() {
|
||||
self.final_message = Self::final_message_from_turn_items(
|
||||
notification.turn.items.as_slice(),
|
||||
);
|
||||
}
|
||||
events.push(ThreadEvent::TurnCompleted(TurnCompletedEvent {
|
||||
usage: self.usage_from_last_total(),
|
||||
}));
|
||||
|
||||
@@ -419,6 +419,38 @@ fn token_usage_update_is_emitted_on_turn_completion() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn turn_completion_recovers_final_message_from_turn_items() {
|
||||
let mut processor = EventProcessorWithJsonOutput::new(None);
|
||||
|
||||
let completed =
|
||||
processor.collect_thread_events(TypedExecEvent::TurnCompleted(TurnCompletedNotification {
|
||||
thread_id: "thread-1".to_string(),
|
||||
turn: Turn {
|
||||
id: "turn-1".to_string(),
|
||||
items: vec![ThreadItem::AgentMessage {
|
||||
id: "msg-1".to_string(),
|
||||
text: "final answer".to_string(),
|
||||
phase: None,
|
||||
memory_citation: None,
|
||||
}],
|
||||
status: TurnStatus::Completed,
|
||||
error: None,
|
||||
},
|
||||
}));
|
||||
|
||||
assert_eq!(
|
||||
completed,
|
||||
CollectedThreadEvents {
|
||||
events: vec![ThreadEvent::TurnCompleted(TurnCompletedEvent {
|
||||
usage: Usage::default(),
|
||||
})],
|
||||
status: CodexStatus::InitiateShutdown,
|
||||
}
|
||||
);
|
||||
assert_eq!(processor.final_message.as_deref(), Some("final answer"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn turn_failure_prefers_structured_error_message() {
|
||||
let mut processor = EventProcessorWithJsonOutput::new(None);
|
||||
|
||||
Reference in New Issue
Block a user