diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 13b49b1c09..a402ef3f58 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -816,6 +816,12 @@ impl Session { } Err(error) => { warn!("failed to prepare undo patch: {error:#}"); + self.clear_last_undo_patch(); + self.notify_background_event( + &context.sub_id, + format!("Undo is unavailable for this turn: {error:#}"), + ) + .await; } } } @@ -827,6 +833,17 @@ impl Session { } Err(error) => { warn!("failed to compute unified diff: {error:#}"); + if *exit_code == 0 { + self.clear_last_undo_patch(); + self + .notify_background_event( + &context.sub_id, + format!( + "Undo is unavailable for this turn: failed to compute diff: {error:#}" + ), + ) + .await; + } } } } diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index 4ad80a03d0..60678b7427 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -1267,21 +1267,21 @@ impl ChatWidget { tx.send(AppEvent::CodexOp(Op::UndoLastTurnDiff)); })]; - let mut items = Vec::new(); - items.push(SelectionItem { + let items = vec![ + SelectionItem { name: "Undo last turn diff".to_string(), description: Some( "Revert files that Codex changed during the most recent turn.".to_string(), ), is_current: false, actions: undo_actions, - }); - items.push(SelectionItem { + }, + SelectionItem { name: "Cancel".to_string(), description: Some("Close without undoing any files.".to_string()), is_current: false, actions: Vec::new(), - }); + }]; self.bottom_pane.show_selection_view( "Undo last Codex turn?".to_string(),