From fd95d89146661880b8ccb0b70d89658679b2adc5 Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Wed, 25 Nov 2026 18:04:20 +0000 Subject: [PATCH] Skip reasoning effort animations during TUI thread replay (#63998) ## Why Switching back to a thread restores its current settings before replaying older updates. Those updates can trigger reasoning effort animations and leave the status line temporarily showing an older effort level. ## What changed Set the composer's reasoning effort baseline before refreshing it for each replayed settings update. The status line reflects the replayed effort immediately, and live changes still animate. ## Testing Add a regression test that replays earlier effort changes after restoring a thread, checks the displayed effort, and verifies that a subsequent live change starts the animation. GitOrigin-RevId: 3daadc7b8b5917eba1055940c67399b8ab729eda --- codex-rs/tui/src/chatwidget.rs | 1 - codex-rs/tui/src/chatwidget/protocol.rs | 2 +- codex-rs/tui/src/chatwidget/settings.rs | 37 ++++++++++------ .../tui/src/chatwidget/tests/app_server.rs | 44 +++++++++++++++++++ 4 files changed, 69 insertions(+), 15 deletions(-) diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index 5f887a5a9d..e419698b81 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -106,7 +106,6 @@ use codex_app_server_protocol::SkillMetadata; use codex_app_server_protocol::ThreadGoal as AppThreadGoal; use codex_app_server_protocol::ThreadGoalStatus as AppThreadGoalStatus; use codex_app_server_protocol::ThreadItemPayload; -use codex_app_server_protocol::ThreadSettings; use codex_app_server_protocol::ThreadSettingsUpdatedNotification; use codex_app_server_protocol::ThreadTokenUsage; use codex_app_server_protocol::ToolRequestUserInputParams; diff --git a/codex-rs/tui/src/chatwidget/protocol.rs b/codex-rs/tui/src/chatwidget/protocol.rs index 3d2a741939..ba65494e15 100644 --- a/codex-rs/tui/src/chatwidget/protocol.rs +++ b/codex-rs/tui/src/chatwidget/protocol.rs @@ -99,7 +99,7 @@ impl ChatWidget { self.on_thread_goal_cleared(notification.thread_id.as_str()); } ServerNotification::ThreadSettingsUpdated(notification) => { - self.on_thread_settings_updated(notification); + self.apply_thread_settings(notification, replay_kind); } ServerNotification::TurnStarted(notification) => { self.turn_lifecycle.has_turn_history = true; diff --git a/codex-rs/tui/src/chatwidget/settings.rs b/codex-rs/tui/src/chatwidget/settings.rs index b818a6c9b4..550fa928a8 100644 --- a/codex-rs/tui/src/chatwidget/settings.rs +++ b/codex-rs/tui/src/chatwidget/settings.rs @@ -439,18 +439,7 @@ impl ChatWidget { &mut self, notification: ThreadSettingsUpdatedNotification, ) { - let Ok(thread_id) = ThreadId::from_string(¬ification.thread_id) else { - tracing::warn!( - thread_id = notification.thread_id, - "ignoring app-server ThreadSettingsUpdated with invalid thread_id" - ); - return; - }; - if self.thread_id != Some(thread_id) { - return; - } - - self.apply_thread_settings(notification.thread_settings); + self.apply_thread_settings(notification, /*replay_kind*/ None); } #[cfg(test)] @@ -535,7 +524,23 @@ impl ChatWidget { self.refresh_open_model_picker(); } - fn apply_thread_settings(&mut self, mut settings: ThreadSettings) { + pub(super) fn apply_thread_settings( + &mut self, + notification: ThreadSettingsUpdatedNotification, + replay_kind: Option, + ) { + let Ok(thread_id) = ThreadId::from_string(¬ification.thread_id) else { + tracing::warn!( + thread_id = notification.thread_id, + "ignoring app-server ThreadSettingsUpdated with invalid thread_id" + ); + return; + }; + if self.thread_id != Some(thread_id) { + return; + } + + let mut settings = notification.thread_settings; self.invalidate_permission_discovery(); if let Some(environments) = &settings.environments { self.primary_environment_cwd = @@ -617,6 +622,12 @@ impl ChatWidget { self.queue_unavailable_daybreak_disable(&settings.model); } settings.collaboration_mode.settings.model = settings.model; + // A thread switch replays earlier effort changes after restoring the session. + // Establish each replayed tier before refreshing the composer so only live changes animate. + if replay_kind.is_some() { + self.bottom_pane + .set_active_reasoning_effort_baseline(settings.effort.as_ref()); + } settings.collaboration_mode.settings.reasoning_effort = settings.effort; self.thread_settings_confirmed = true; self.set_effective_collaboration_mode(settings.collaboration_mode); diff --git a/codex-rs/tui/src/chatwidget/tests/app_server.rs b/codex-rs/tui/src/chatwidget/tests/app_server.rs index 1a4153487a..306d48c77c 100644 --- a/codex-rs/tui/src/chatwidget/tests/app_server.rs +++ b/codex-rs/tui/src/chatwidget/tests/app_server.rs @@ -845,6 +845,50 @@ async fn thread_settings_updated_updates_visible_state_without_transcript() { assert_eq!(chat.current_model(), "gpt-5.4"); } +#[tokio::test] +async fn thread_settings_updated_during_replay_restores_effort_without_animating() { + let (mut chat, _rx, _op_rx) = make_chatwidget_manual(Some("gpt-5.2")).await; + let thread_id = ThreadId::new(); + chat.local_settings.tui.status_line = Some(vec!["model-with-reasoning".to_string()]); + let mut session = configured_thread_session(thread_id); + session.reasoning_effort = Some(ReasoningEffortConfig::Ultra); + chat.handle_thread_session(session); + chat.show_welcome_banner = false; + + let settings = |effort| { + let mut update = thread_settings_for_test("gpt-5.2", thread_id); + update.thread_settings.collaboration_mode.mode = ModeKind::Default; + update.thread_settings.service_tier = None; + update.thread_settings.effort = Some(effort); + ServerNotification::ThreadSettingsUpdated(update) + }; + crate::terminal_palette::with_test_palette(/*colors*/ None, || { + // Switching back restores the current session before replaying older settings. + let replay = Some(ReplayKind::ThreadSnapshot); + chat.handle_server_notification(settings(ReasoningEffortConfig::High), replay); + chat.handle_server_notification(settings(ReasoningEffortConfig::Max), replay); + assert!(render_bottom_popup(&chat, /*width*/ 80).contains("max")); + chat.handle_server_notification(settings(ReasoningEffortConfig::Ultra), replay); + insta::assert_snapshot!(render_bottom_popup(&chat, /*width*/ 80), @" + ยป Ask Codex to do anything + + gpt-5.2 ultra + ? for shortcuts + "); + + // A live change still starts by showing the outgoing Ultra status line. + chat.handle_server_notification( + settings(ReasoningEffortConfig::Max), + /*replay_kind*/ None, + ); + assert_eq!( + chat.current_reasoning_effort(), + Some(ReasoningEffortConfig::Max) + ); + assert!(render_bottom_popup(&chat, /*width*/ 80).contains("ultra")); + }); +} + #[tokio::test] async fn thread_settings_updated_preserves_default_settings_for_plan_mode() { let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(Some("gpt-5.2")).await;