From dfb4e002eb3146385e3003f3a1a020ab3178ab31 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Sat, 4 Apr 2026 12:03:25 -0700 Subject: [PATCH] codex: address PR review feedback (#16803) Match section breaks when reconciling completed reasoning snapshots against streamed deltas. --- codex-rs/tui/src/chatwidget.rs | 7 +- ..._missing_prefix_across_section_breaks.snap | 7 ++ .../src/chatwidget/tests/history_replay.rs | 77 +++++++++++++++++++ 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__live_reasoning_item_completed_backfills_missing_prefix_across_section_breaks.snap diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index 32b6ae2fdb..96edfcf98d 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -6016,9 +6016,12 @@ impl ChatWidget { ThreadItem::Reasoning { summary, content, .. } => { - let mut completed_reasoning = summary.join(""); + let mut completed_reasoning = summary.join("\n\n"); if self.config.show_raw_agent_reasoning { - completed_reasoning.push_str(&content.join("")); + if !completed_reasoning.is_empty() && !content.is_empty() { + completed_reasoning.push_str("\n\n"); + } + completed_reasoning.push_str(&content.join("\n\n")); } let streamed_reasoning = format!("{}{}", self.full_reasoning_buffer, self.reasoning_buffer); diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__live_reasoning_item_completed_backfills_missing_prefix_across_section_breaks.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__live_reasoning_item_completed_backfills_missing_prefix_across_section_breaks.snap new file mode 100644 index 0000000000..e4192c4805 --- /dev/null +++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__live_reasoning_item_completed_backfills_missing_prefix_across_section_breaks.snap @@ -0,0 +1,7 @@ +--- +source: tui/src/chatwidget/tests/history_replay.rs +expression: rendered +--- +• prefix middle + + tail diff --git a/codex-rs/tui/src/chatwidget/tests/history_replay.rs b/codex-rs/tui/src/chatwidget/tests/history_replay.rs index f7fb4e219a..e22b800212 100644 --- a/codex-rs/tui/src/chatwidget/tests/history_replay.rs +++ b/codex-rs/tui/src/chatwidget/tests/history_replay.rs @@ -1,4 +1,5 @@ use super::*; +use codex_app_server_protocol::ReasoningSummaryPartAddedNotification; use pretty_assertions::assert_eq; #[tokio::test] @@ -826,6 +827,82 @@ async fn live_reasoning_item_completed_backfills_missing_prefix_before_streamed_ ); } +#[tokio::test] +async fn live_reasoning_item_completed_backfills_missing_prefix_across_section_breaks() { + let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await; + chat.show_welcome_banner = false; + + chat.handle_server_notification( + ServerNotification::TurnStarted(TurnStartedNotification { + thread_id: "thread-1".to_string(), + turn: AppServerTurn { + id: "turn-1".to_string(), + items: Vec::new(), + status: AppServerTurnStatus::InProgress, + error: None, + }, + }), + /*replay_kind*/ None, + ); + let _ = drain_insert_history(&mut rx); + + chat.handle_server_notification( + ServerNotification::ReasoningSummaryTextDelta(ReasoningSummaryTextDeltaNotification { + thread_id: "thread-1".to_string(), + turn_id: "turn-1".to_string(), + item_id: "reasoning-1".to_string(), + delta: "middle".to_string(), + summary_index: 0, + }), + /*replay_kind*/ None, + ); + chat.handle_server_notification( + ServerNotification::ReasoningSummaryPartAdded(ReasoningSummaryPartAddedNotification { + thread_id: "thread-1".to_string(), + turn_id: "turn-1".to_string(), + item_id: "reasoning-1".to_string(), + summary_index: 1, + }), + /*replay_kind*/ None, + ); + chat.handle_server_notification( + ServerNotification::ReasoningSummaryTextDelta(ReasoningSummaryTextDeltaNotification { + thread_id: "thread-1".to_string(), + turn_id: "turn-1".to_string(), + item_id: "reasoning-1".to_string(), + delta: "tail".to_string(), + summary_index: 1, + }), + /*replay_kind*/ None, + ); + + chat.handle_server_notification( + ServerNotification::ItemCompleted(ItemCompletedNotification { + thread_id: "thread-1".to_string(), + turn_id: "turn-1".to_string(), + item: AppServerThreadItem::Reasoning { + id: "reasoning-1".to_string(), + summary: vec!["prefix middle".to_string(), "tail".to_string()], + content: Vec::new(), + }, + }), + /*replay_kind*/ None, + ); + + let rendered = match rx.try_recv() { + Ok(AppEvent::InsertHistoryCell(cell)) => { + lines_to_single_string(&cell.transcript_lines(/*width*/ 80)) + } + other => panic!("expected InsertHistoryCell, got {other:?}"), + }; + assert_eq!(rendered.matches("prefix middle").count(), 1); + assert!(rendered.contains("tail")); + assert_chatwidget_snapshot!( + "live_reasoning_item_completed_backfills_missing_prefix_across_section_breaks", + rendered + ); +} + #[tokio::test] async fn replayed_turn_started_does_not_mark_task_running() { let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;