Avoid legacy transcript reads in the agents overview (#61709)

## Why

Listing even one turn of a legacy thread replays its entire rollout. Overview refreshes should avoid that work just to populate previews.

## What changed

- Fetch saved prompt and reply previews only for threads with paginated history.
- Update legacy prompt previews from user-message notifications and preserve them across refreshes and reverts.
- Retain the latest observed reply preview when a thread closes.

## Testing

Extend overview tests to reject legacy turn-list requests, verify paginated previews, preserve live prompts across stale refreshes and reverts, and retain reply previews after thread closure.

GitOrigin-RevId: 85130adda155c5ea93c5a5c2b3f89a945170ba51
This commit is contained in:
Eric Traut
2026-11-16 00:03:21 +00:00
committed by copyberry
parent e51c551fb4
commit b048d4a95c
5 changed files with 124 additions and 31 deletions
+15 -6
View File
@@ -274,11 +274,13 @@ impl App {
{
*refill = refill.saturating_sub(1);
}
self.agents_overview
.activity
.entry(thread_id)
.or_default()
.latest_prompt = latest_prompt;
if thread.history_mode == ThreadHistoryMode::Paginated {
self.agents_overview
.activity
.entry(thread_id)
.or_default()
.latest_prompt = latest_prompt;
}
thread.turns.clear();
self.agents_overview.threads.insert(thread_id, Some(thread));
} else {
@@ -298,7 +300,14 @@ impl App {
&& let Ok(thread_id) = ThreadId::from_string(&reverted.thread_id)
{
// Discard stale read results without clearing activity received after the revert.
if let Some(activity) = self.agents_overview.activity.get_mut(&thread_id) {
if self
.agents_overview
.threads
.get(&thread_id)
.and_then(Option::as_ref)
.is_some_and(|thread| thread.history_mode == ThreadHistoryMode::Paginated)
&& let Some(activity) = self.agents_overview.activity.get_mut(&thread_id)
{
activity.latest_prompt = None;
}
self.agents_overview.last_messages.remove(&thread_id);
@@ -6,12 +6,14 @@ use super::App;
use super::ThreadBufferedEvent;
use super::ThreadEventAttachment;
use super::agents_overview_view::AgentsOverviewGroup;
use crate::chatwidget::ChatWidget;
use codex_app_server_protocol::ItemCompletedNotification;
use codex_app_server_protocol::McpServerElicitationRequest;
use codex_app_server_protocol::ServerNotification;
use codex_app_server_protocol::ServerRequest;
use codex_app_server_protocol::Thread;
use codex_app_server_protocol::ThreadActiveFlag;
use codex_app_server_protocol::ThreadHistoryMode;
use codex_app_server_protocol::ThreadItemPayload;
use codex_app_server_protocol::ThreadStatus;
use codex_protocol::ThreadId;
@@ -53,7 +55,7 @@ pub(super) fn preview_text(text: &str) -> String {
pub(super) struct AgentsOverviewActivity {
pub(super) latest_prompt: Option<String>,
reasoning: Option<ReasoningPreview>,
last_message: Option<String>,
pub(super) last_message: Option<String>,
}
struct ReasoningPreview {
@@ -105,6 +107,22 @@ impl App {
.map(|header| preview_text(&header));
had_header || reasoning.header.is_some()
}
ServerNotification::ItemCompleted(ItemCompletedNotification {
item:
codex_app_server_protocol::ThreadItem {
payload: ThreadItemPayload::UserMessage { content, .. },
..
},
..
}) if self.agents_overview.threads[&thread_id]
.as_ref()
.is_some_and(|thread| thread.history_mode == ThreadHistoryMode::Legacy) =>
{
activity.latest_prompt = Some(preview_markdown(
&ChatWidget::user_message_display_from_inputs(content).message,
));
true
}
ServerNotification::ItemCompleted(ItemCompletedNotification {
item:
codex_app_server_protocol::ThreadItem {
@@ -7,6 +7,7 @@ use crate::app_server_session::ThreadParamsMode;
use codex_app_server_client::CloudOperation;
use codex_app_server_protocol::ClientRequest;
use codex_app_server_protocol::JSONRPCMessage;
use codex_app_server_protocol::ThreadHistoryMode;
use futures::SinkExt;
use futures::StreamExt;
use pretty_assertions::assert_eq;
@@ -82,6 +83,7 @@ async fn check_discovery(mixed_sources: bool) -> Result<()> {
}
if index == 23 {
thread.name = None;
thread.history_mode = ThreadHistoryMode::Paginated;
}
thread.updated_at += 24 - index;
thread.recency_at = Some(thread.updated_at);
@@ -182,6 +184,7 @@ async fn check_discovery(mixed_sources: bool) -> Result<()> {
}
}
"thread/read" => {
assert_ne!(params["includeTurns"], true);
let thread = rows
.iter()
.find(|thread| thread.id == params["threadId"])
@@ -190,9 +193,10 @@ async fn check_discovery(mixed_sources: bool) -> Result<()> {
}
"thread/turns/list" if params["threadId"] == rows[23].id => json!({"data": [{
"id":"latest", "status":"completed", "items":[{"type":"userMessage","id":"prompt",
"content":[{"type":"text","text":"A later prompt","textElements":[]}]}]
"content":[{"type":"text","text":"A later prompt","textElements":[]}]},
{"type":"agentMessage","id":"reply","text":"A saved reply"}]
}], "nextCursor":null}),
"thread/turns/list" => json!({"data": [], "nextCursor": null}),
"thread/turns/list" => panic!("overview requested legacy transcript: {params}"),
"thread/archive" | "thread/delete" => {
socket.send(Message::Text(json!({"id": request.id, "error":{"code":-32603,"message":"try again"}}).to_string().into())).await?;
continue;
@@ -379,6 +383,13 @@ async fn check_discovery(mixed_sources: bool) -> Result<()> {
.as_deref(),
Some("A later prompt")
);
assert_eq!(
app.agents_overview
.last_messages
.get(&ids[23])
.map(String::as_str),
Some("A saved reply")
);
// Another CLI inserts a matching session ahead of the exhausted browse cursor.
show_reopened_pin.store(true, Ordering::SeqCst);
view.handle_key_event(KeyCode::Char('/').into());
+49 -6
View File
@@ -823,26 +823,53 @@ async fn shared_overview_keeps_rows_and_replays_changes_over_stale_reads() -> Re
retained_thread.name = Some("New name".to_string());
retained_thread.status = ThreadStatus::NotLoaded;
let expected = HashMap::from([
(retained, Some(retained_thread)),
(retained, Some(retained_thread.clone())),
(created, Some(created_thread)),
]);
assert_eq!(app.agents_overview.threads, expected);
let request_id = Uuid::new_v4();
app.agents_overview.active_refresh = Some((request_id, app_server.backend_id()));
let follow_up = ServerNotification::ItemCompleted(
codex_app_server_protocol::ItemCompletedNotification::new(
retained.to_string(),
"turn".into(),
ThreadItemPayload::UserMessage {
id: "prompt".into(),
client_id: None,
content: vec![codex_app_server_protocol::UserInput::Text {
text: "Current request".into(),
text_elements: Vec::new(),
}],
},
/*started_at_ms*/ None,
/*completed_at_ms*/ 0,
),
);
app.track_agents_overview_notification(&follow_up);
app.apply_agents_overview_thread_refresh(
&app_server,
request_id,
Ok(AgentsOverviewThreadRefresh {
cleared_unread: Vec::new(),
last_messages: HashMap::new(),
threads: HashMap::from([(retained, None)]),
threads: HashMap::from([
(retained, Some((retained_thread, false, None))),
(created, None),
]),
recent_seed_complete: true,
discovery: None,
pinned_thread_ids: None,
}),
);
assert_eq!(app.agents_overview.threads, expected);
assert_eq!(
app.agents_overview.activity[&retained]
.latest_prompt
.as_deref(),
Some("Current request")
);
let request_id = Uuid::new_v4();
app.agents_overview.active_refresh = Some((request_id, app_server.backend_id()));
app.apply_agents_overview_thread_refresh(
@@ -876,6 +903,7 @@ async fn shared_overview_keeps_rows_and_replays_changes_over_stale_reads() -> Re
"new-reasoning",
"**Checking the revised task**",
));
app.track_agents_overview_notification(&follow_up);
let current_request = app.agents_overview.active_refresh.unwrap().0;
for (request_id, last_messages) in [
(old_request, stale_messages.clone()),
@@ -896,6 +924,12 @@ async fn shared_overview_keeps_rows_and_replays_changes_over_stale_reads() -> Re
assert!(app.agents_overview.last_messages.is_empty());
}
assert!(app.agents_overview.activity.contains_key(&retained));
assert_eq!(
app.agents_overview.activity[&retained]
.latest_prompt
.as_deref(),
Some("Current request")
);
assert!(app.agents_overview.active_refresh.is_none());
}
@@ -1027,10 +1061,7 @@ async fn shared_overview_seeds_once_and_retains_locally_resumed_history() -> Res
expected.insert(ids[0]);
let retained: HashSet<_> = app.agents_overview.threads.keys().copied().collect();
assert_eq!(retained, expected);
assert_eq!(
app.agents_overview.last_messages,
HashMap::from([(ids[10], "Found the regression in the parser.".to_string())])
);
assert!(app.agents_overview.last_messages.is_empty());
let thread = app.agents_overview.threads[&ids[10]].as_ref().unwrap();
assert_eq!(thread.status, ThreadStatus::NotLoaded);
@@ -1453,6 +1484,18 @@ async fn agents_overview_details_render_markdown() {
.draw(|frame| view.render(frame.area(), frame.buffer_mut()))
.unwrap();
assert_eq!(terminal.backend().to_string(), cached);
app.track_agents_overview_notification(&ServerNotification::ThreadClosed(
ThreadClosedNotification {
thread_id: thread_id.to_string(),
},
));
assert_eq!(
app.agents_overview
.last_messages
.get(&thread_id)
.map(String::as_str),
Some(message)
);
thread.preview = format!("```\n{}\n```", "long prompt ".repeat(25));
app.agents_overview.activity.clear();
+28 -16
View File
@@ -22,6 +22,7 @@ use codex_app_server_protocol::ClientRequest;
use codex_app_server_protocol::RequestId;
use codex_app_server_protocol::ServerNotification;
use codex_app_server_protocol::Thread;
use codex_app_server_protocol::ThreadHistoryMode;
use codex_app_server_protocol::ThreadItemPayload;
use codex_app_server_protocol::ThreadLoadedListParams;
use codex_app_server_protocol::ThreadLoadedListResponse;
@@ -168,7 +169,16 @@ impl App {
self.agents_overview
.requested_permission_profiles
.remove(&thread_id);
self.agents_overview.activity.remove(&thread_id);
if let Some(message) = self
.agents_overview
.activity
.remove(&thread_id)
.and_then(|activity| activity.last_message)
{
self.agents_overview
.last_messages
.insert(thread_id, message);
}
if let Some(usage) = self.agents_overview.usage.get_mut(&thread_id) {
usage.tokens = None;
}
@@ -495,22 +505,24 @@ impl App {
Ok(response) => {
let mut latest_prompt = None;
let mut last_message = None;
if let Ok(turns) = request_handle
.request_typed::<ThreadTurnsListResponse>(
ClientRequest::ThreadTurnsList {
request_id: RequestId::String(
Uuid::new_v4().to_string(),
),
params: ThreadTurnsListParams {
thread_id: thread_id.to_string(),
cursor: None,
limit: Some(1),
sort_direction: None,
items_view: None,
// Legacy turn listing replays the entire rollout, even for one turn.
if response.thread.history_mode == ThreadHistoryMode::Paginated
&& let Ok(turns) = request_handle
.request_typed::<ThreadTurnsListResponse>(
ClientRequest::ThreadTurnsList {
request_id: RequestId::String(
Uuid::new_v4().to_string(),
),
params: ThreadTurnsListParams {
thread_id: thread_id.to_string(),
cursor: None,
limit: Some(1),
sort_direction: None,
items_view: None,
},
},
},
)
.await
)
.await
&& let Some(turn) = turns.data.first()
{
if let Some(ThreadItemPayload::UserMessage {