codex: address PR review feedback (#15106)

This commit is contained in:
Eric Traut
2026-03-20 00:48:55 -06:00
parent 50b61563c5
commit d4c72ea829
3 changed files with 77 additions and 9 deletions

View File

@@ -313,10 +313,8 @@ impl EventProcessor for EventProcessorWithHumanOutput {
}
TypedExecEvent::TurnCompleted(notification) => match notification.turn.status {
TurnStatus::Completed => {
if self.final_message.is_none() {
self.final_message =
final_message_from_turn_items(notification.turn.items.as_slice());
}
self.final_message =
final_message_from_turn_items(notification.turn.items.as_slice());
self.print_usage();
CodexStatus::InitiateShutdown
}
@@ -561,4 +559,44 @@ mod tests {
);
assert_eq!(processor.final_message.as_deref(), Some("final answer"));
}
#[test]
fn turn_completed_overwrites_stale_final_message_from_turn_items() {
let mut processor = EventProcessorWithHumanOutput {
bold: Style::new(),
cyan: Style::new(),
dimmed: Style::new(),
green: Style::new(),
red: Style::new(),
yellow: Style::new(),
show_agent_reasoning: true,
show_raw_agent_reasoning: false,
last_message_path: None,
final_message: Some("stale answer".to_string()),
last_total_token_usage: None,
};
let status = processor.process_event(TypedExecEvent::TurnCompleted(
codex_app_server_protocol::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!(
status,
crate::event_processor::CodexStatus::InitiateShutdown
);
assert_eq!(processor.final_message.as_deref(), Some("final answer"));
}
}

View File

@@ -406,11 +406,8 @@ 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(),
);
}
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(),
}));

View File

@@ -482,6 +482,39 @@ fn turn_completion_recovers_final_message_from_turn_items() {
assert_eq!(processor.final_message.as_deref(), Some("final answer"));
}
#[test]
fn turn_completion_overwrites_stale_final_message_from_turn_items() {
let mut processor = EventProcessorWithJsonOutput::new(None);
processor.final_message = Some("stale answer".to_string());
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_completion_falls_back_to_final_plan_text() {
let mut processor = EventProcessorWithJsonOutput::new(None);