Show completion timestamps after successful TUI turns (#43558)

## What changed

Replace horizontal turn separators with dim completion metadata after the final answer, including plain conversational answers. Show local completion times such as `done 2:32 PM`, adding the date for other days and the year for other years. Retain `Worked for` durations above sixty seconds and runtime metrics, and wrap metadata on narrow terminals.

Restore saved completion metadata when resuming conversations or loading older history. Keep each footer after its turn's items and deduplicate it across repeated notifications and overlapping pages. Only live completions fall back to the current time when a saved timestamp is unavailable. Failed, interrupted, and in-progress turns do not receive success footers.

Avoid submitting queued input or emitting completion notifications while replaying history.

## Testing

Add unit and snapshot coverage for timestamp formatting, duration thresholds, muted styling, narrow layouts, live and replayed completions, missing metadata, and pagination boundaries with overlapping pages.

GitOrigin-RevId: 308c35c6720720da43c9a391aa5a68c1b231c9a5
This commit is contained in:
Felipe Coury authored and copyberry committed 2026-09-07 19:01:08 +00:00
1 parent 769a6a5bcd
commit 333c41eef6
42 files changed
+1112 -202

No files matched your search

@@ -0,0 +1,169 @@
//! Completed older pages keep each footer after its answer, including overlapping pages.
use super::session_lifecycle_requests::start_recording_app_server;
use super::*;
use app_test_support::create_fake_paginated_rollout;
use app_test_support::rollout_path;
use chrono::TimeZone;
use codex_app_server_protocol::ThreadItemsListResponse;
use codex_protocol::items::AgentMessageContent;
use codex_protocol::items::AgentMessageItem;
use codex_protocol::items::TurnItem;
use codex_protocol::items::UserMessageItem;
use codex_protocol::protocol::ItemCompletedEvent;
use codex_protocol::protocol::TurnCompleteEvent;
use codex_protocol::user_input::UserInput as CoreUserInput;
use codex_state::SqliteConfig;
#[tokio::test]
async fn older_pagination_completion_footers_follow_answers_without_overlap_duplicates()
-> Result<()> {
let mut app = make_test_app().await;
let codex_home = tempdir()?;
app.config.codex_home = codex_home.path().to_path_buf().abs();
app.config.sqlite = SqliteConfig::new_for_testing(codex_home.path().abs());
app.local_settings.tui.terminal_resize_reflow_max_rows = Some(2);
let completed_at = chrono::Local
.with_ymd_and_hms(
/*year*/ 2000, /*month*/ 9, /*day*/ 6, /*hour*/ 14,
/*min*/ 32, /*sec*/ 0,
)
.single()
.expect("unambiguous local completion time");
let timestamp = completed_at.to_rfc3339();
let filename_timestamp = "2000-09-06T14-32-00";
let thread_id = create_fake_paginated_rollout(
codex_home.path(),
filename_timestamp,
&timestamp,
"completed pagination",
Some(app.config.model_provider_id.as_str()),
/*git_info*/ None,
)
.map_err(|error| color_eyre::eyre::eyre!(error))?;
let path = rollout_path(codex_home.path(), filename_timestamp, &thread_id);
let thread_id = ThreadId::from_string(&thread_id)?;
let mut records = std::fs::read_to_string(&path)?
.lines()
.take(/*n*/ 1)
.map(serde_json::from_str::<serde_json::Value>)
.collect::<Result<Vec<_>, _>>()?;
for (index, name) in ["Oldest", "Middle", "Newest"].into_iter().enumerate() {
let turn_id = format!("turn-{index}");
let finished = completed_at.timestamp() + index as i64 * 60;
let mut events = vec![EventMsg::TurnStarted(TurnStartedEvent {
turn_id: turn_id.clone(),
trace_id: None,
started_at: Some(finished - 125),
model_context_window: None,
collaboration_mode_kind: Default::default(),
})];
let items = [
TurnItem::UserMessage(UserMessageItem {
id: format!("prompt-{index}"),
client_id: None,
content: vec![CoreUserInput::Text {
text: format!("{name} prompt"),
text_elements: Vec::new(),
}],
}),
TurnItem::AgentMessage(AgentMessageItem {
id: format!("answer-{index}"),
content: vec![AgentMessageContent::Text {
text: format!("{name} answer"),
}],
phase: None,
memory_citation: None,
delivery: None,
questions: None,
}),
];
events.extend(items.into_iter().map(|item| {
EventMsg::ItemCompleted(ItemCompletedEvent {
thread_id,
turn_id: turn_id.clone(),
item,
started_at_ms: None,
completed_at_ms: finished * 1_000,
})
}));
events.push(EventMsg::TurnComplete(TurnCompleteEvent {
turn_id,
last_agent_message: Some(format!("{name} answer")),
error: None,
started_at: Some(finished - 125),
completed_at: Some(finished),
duration_ms: Some(125_000),
time_to_first_token_ms: None,
}));
for event in events {
records.push(serde_json::json!({
"timestamp": timestamp,
"ordinal": records.len(),
"type": "event_msg",
"payload": event,
}));
}
}
let records = records
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join("\n");
std::fs::write(path, format!("{records}\n"))?;
let (mut app_server, _requests, proxy) = start_recording_app_server(
&app.config,
/*blocked_thread_list*/ None,
/*failed_thread_name*/ None,
)
.await?;
let started = app_server
.resume_thread(
&app.local_settings,
app.config.clone(),
thread_id,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
)
.await?;
app.enqueue_primary_thread_session(started.session, started.turns)
.await?;
// Snapshot only the prepended pages; the newest turn is already hydrated in the store.
app.local_settings.tui.terminal_resize_reflow_max_rows = None;
let mut tui = crate::tui::test_support::make_test_tui()?;
app.open_transcript_overlay(&mut tui);
let mut overlapping_answer = None;
let mut snapshots = Vec::new();
for limit in [1, 100] {
let cursor = app_server
.begin_older_history_page(thread_id)
.expect("older page");
let mut page: ThreadItemsListResponse = app_server
.thread_items_page(
thread_id,
/*turn_id*/ None,
Some(cursor.clone()),
limit,
)
.await?;
if let Some(answer) = overlapping_answer.take() {
// The later response repeats the preceding page's completed answer.
page.data.insert(/*index*/ 0, answer);
} else {
overlapping_answer = page.data.first().cloned();
}
app.handle_older_history_page(&mut tui, &mut app_server, thread_id, &cursor, Ok(page))
.await?;
snapshots.push(
app.render_transcript_lines_for_reflow(/*width*/ 80)
.lines
.iter()
.map(rendered_line_text)
.collect::<Vec<_>>()
.join("\n"),
);
}
insta::assert_snapshot!(snapshots.join("\n\n--- next overlapping page ---\n\n"));
app_server.shutdown().await?;
proxy.await??;
Ok(())
}
+10 -3
View File
@@ -2,6 +2,7 @@ use super::*;
use crate::app::safety_buffering::SafetyBufferedRetry;
use crate::app::session_lifecycle::ThreadAttachPresentation;
use crate::chatwidget::UserMessage;
use crate::chatwidget::tests::helpers::normalize_completion_timestamps;
use codex_app_server_client::AppServerEvent;
use codex_app_server_protocol::ModelSafetyBufferingUpdatedNotification;
use codex_model_provider_info::ModelProviderInfo;
@@ -894,9 +895,15 @@ goals = true
let mut replayed_history = String::new();
while let Ok(event) = app_event_rx.try_recv() {
if let AppEvent::InsertHistoryCell(cell) = event {
replayed_history.push_str(&lines_to_single_string(
&cell.transcript_lines(/*width*/ 80),
));
let rendered = lines_to_single_string(&cell.transcript_lines(/*width*/ 80));
if cell
.as_any()
.is::<crate::history_cell::FinalMessageSeparator>()
{
replayed_history.push_str(&normalize_completion_timestamps(rendered));
} else {
replayed_history.push_str(&rendered);
}
}
}
assert_eq!(
@@ -0,0 +1,26 @@
---
source: tui/src/app/tests/pagination_completion_tests.rs
expression: "snapshots.join(\"\\n\\n--- next overlapping page ---\\n\\n\")"
---
Earlier messages are available — press ctrl + t to view the full transcript
• Middle answer
Worked for 2m 5s · done Sep 6, 2000 at 2:33 PM
--- next overlapping page ---
› Oldest prompt
• Oldest answer
Worked for 2m 5s · done Sep 6, 2000 at 2:32 PM
› Middle prompt
• Middle answer
Worked for 2m 5s · done Sep 6, 2000 at 2:33 PM
@@ -4,4 +4,4 @@ expression: rendered_retry
---
› Handle the safety-buffered request
Keep the accepted steer
⚠ Full-history hydration is deprecated for paginated threads; omit `includeTurns` or set it to `false`, then page with `thread/turns/list` and `thread/items/list`.• done
⚠ Full-history hydration is deprecated for paginated threads; omit `includeTurns` or set it to `false`, then page with `thread/turns/list` and `thread/items/list`.• done done [completion time]