Lightweight coding agent that runs in your terminal
Rust
Restore elapsed time for replayed in-progress turns (#54047)
Eric Traut764a70fc113d
diff --git a/codex-rs/tui/src/chatwidget/protocol.rs b/codex-rs/tui/src/chatwidget/protocol.rsindex 0065ef473b..b68e13a2dd 100644--- a/codex-rs/tui/src/chatwidget/protocol.rs+++ b/codex-rs/tui/src/chatwidget/protocol.rs@@ -102,7 +102,11 @@ impl ChatWidget {self.last_non_retry_error = None;if !matches!(replay_kind, Some(ReplayKind::ResumeInitialMessages)) {self.warning_display_state.startup_complete = true;- self.on_task_started();+ if from_replay {+ self.on_replayed_task_started(notification.turn.started_at);+ } else {+ self.on_task_started();+ }}}ServerNotification::TurnCompleted(notification) => {diff --git a/codex-rs/tui/src/chatwidget/replay.rs b/codex-rs/tui/src/chatwidget/replay.rsindex 1ebff8fcb3..8f573351ca 100644--- a/codex-rs/tui/src/chatwidget/replay.rs+++ b/codex-rs/tui/src/chatwidget/replay.rs@@ -146,7 +146,7 @@ impl ChatWidget {self.warning_display_state.startup_complete = true;self.turn_lifecycle.last_turn_id = Some(turn_id.clone());self.last_non_retry_error = None;- self.on_task_started();+ self.on_replayed_task_started(started_at);}let trailing_reasoning_id = (status == TurnStatus::InProgress).then(|| items.last())diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__replayed_in_progress_turn.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__replayed_in_progress_turn.snapindex 4661f024d7..126e67cc09 100644--- a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__replayed_in_progress_turn.snap+++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__replayed_in_progress_turn.snap@@ -1,8 +1,8 @@---source: tui/src/chatwidget/tests/history_replay.rs-expression: "normalize_completion_timestamps(& (render_bottom_popup(&chat, 80)))"+expression: "timer.replace_all(&normalize_snapshot_paths(render_bottom_popup(&chat, 80)),\n\"(<elapsed> •\")"----• Working (0s • esc to interrupt)+• Working (<elapsed> • esc to interrupt)› Ask Codex to do anythingdiff --git a/codex-rs/tui/src/chatwidget/tests/history_replay.rs b/codex-rs/tui/src/chatwidget/tests/history_replay.rsindex 93662ffac4..26388ec042 100644--- a/codex-rs/tui/src/chatwidget/tests/history_replay.rs+++ b/codex-rs/tui/src/chatwidget/tests/history_replay.rs@@ -1631,15 +1631,38 @@ async fn live_reasoning_summary_drops_empty_parts_without_losing_content() {async fn thread_snapshot_replayed_turn_started_marks_task_running() {let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;- replay_turn_started(&mut chat, ReplayKind::ThreadSnapshot);+ let started_at = chrono::Utc::now().timestamp() - 125;+ chat.handle_server_notification(+ ServerNotification::TurnStarted(TurnStartedNotification {+ thread_id: "thread-1".to_string(),+ turn: AppServerTurn {+ started_at: Some(started_at),+ ..app_server_turn(+ "turn-1",+ AppServerTurnStatus::InProgress,+ /*duration_ms*/ None,+ /*error*/ None,+ )+ },+ }),+ Some(ReplayKind::ThreadSnapshot),+ );drain_insert_history(&mut rx);assert!(chat.bottom_pane.is_task_running());- let status = chat- .bottom_pane- .status_widget()- .expect("status indicator should be visible");- assert_eq!(status.header(), "Working");+ let before = chrono::Utc::now().timestamp() - started_at;+ let elapsed = chat.bottom_pane.status_elapsed().unwrap().as_secs() as i64;+ let after = chrono::Utc::now().timestamp() - started_at;+ // The wire timestamp has second precision; reads may be separated by any CI delay.+ assert!(+ (before - 1..=after).contains(&elapsed),+ "{elapsed} not in {before}..={after}"+ );+ let timer = regex_lite::Regex::new(r"\(\d+(?:h \d+m \d+s|m \d+s|s) •").unwrap();+ insta::assert_snapshot!(+ timer.replace_all(render_bottom_first_row(&chat, /*width*/ 80).trim(), "(<elapsed> •"),+ @"• Working (<elapsed> • esc to interrupt)"+ );}#[tokio::test]@@ -1655,9 +1678,11 @@ async fn replayed_in_progress_turn_marks_task_running() {let (mut chat, mut rx, mut op_rx) =make_chatwidget_manual(/*model_override*/ None).await;chat.thread_id = Some(ThreadId::new());+ let started_at = chrono::Utc::now().timestamp() - 125;chat.replay_thread_turns(vec![AppServerTurn {items_view,+ started_at: Some(started_at),..app_server_turn("turn-1",AppServerTurnStatus::InProgress,@@ -1676,9 +1701,20 @@ async fn replayed_in_progress_turn_marks_task_running() {),(true, Some("turn-1")),);+ let before = chrono::Utc::now().timestamp() - started_at;+ let elapsed = chat.bottom_pane.status_elapsed().unwrap().as_secs() as i64;+ let after = chrono::Utc::now().timestamp() - started_at;+ assert!(+ (before - 1..=after).contains(&elapsed),+ "{elapsed} not in {before}..={after}"+ );+ let timer = regex_lite::Regex::new(r"\(\d+(?:h \d+m \d+s|m \d+s|s) •").unwrap();assert_chatwidget_snapshot!("replayed_in_progress_turn",- normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 80)),+ timer.replace_all(+ &normalize_snapshot_paths(render_bottom_popup(&chat, /*width*/ 80)),+ "(<elapsed> •"+ ),);chat.handle_key_event(KeyEvent::new(KeyCode::Char('c'), KeyModifiers::CONTROL));diff --git a/codex-rs/tui/src/chatwidget/turn_runtime.rs b/codex-rs/tui/src/chatwidget/turn_runtime.rsindex 575410965b..2b394230f8 100644--- a/codex-rs/tui/src/chatwidget/turn_runtime.rs+++ b/codex-rs/tui/src/chatwidget/turn_runtime.rs@@ -114,6 +114,16 @@ impl ChatWidget {self.request_redraw();}+ pub(super) fn on_replayed_task_started(&mut self, started_at: Option<i64>) {+ self.on_task_started();+ if let Some(started_at) = started_at {+ let elapsed_secs = chrono::Utc::now().timestamp().saturating_sub(started_at);+ self.bottom_pane.reset_status_timer(Duration::from_secs(+ elapsed_secs.try_into().unwrap_or_default(),+ ));+ }+ }+pub(super) fn on_task_complete(&mut self,last_agent_message: Option<String>,