Improve paginated TUI history loading (#36949)

## Why

Paginated sessions can have visible messages beyond the first item page, so
bounded hydration could leave resumed history or transcript previews empty and
the transcript viewer incomplete.

## What changed

- Scan paginated history until the configured rendered-row budget is filled,
  while retaining the configured scrollback beyond the visible viewport.
- Fully hydrate transcripts opened from the resume picker and build previews
  from bounded item pages, including when non-visible items precede messages.
- Stop pagination on repeated cursors and let `Esc` cancel an in-flight
  transcript load.
- Replay restored token usage for cold metadata-only resumes when its stored
  turn can be identified.

## Testing

- Add coverage for paginated and legacy transcript loading, bounded resume
  hydration, repeated cursors, transcript cancellation, and resize reflow.

GitOrigin-RevId: 2ce69f7d5eae88e2b09a27c333b00b1830ff17bf
This commit is contained in:
Felipe Coury authored and copyberry committed 2026-08-04 19:05:45 +00:00
1 parent 8bfa49e350
commit 3b8d22ec2c
13 files changed
+721 -125

No files matched your search

+7 -9
View File
@@ -28,6 +28,7 @@ use crate::app::App;
use crate::app_event::AppEvent;
use crate::app_server_session::AppServerSession;
use crate::app_server_session::HISTORY_ITEM_PAGE_LIMIT;
use crate::app_server_session::thread_items_page_params;
use crate::bottom_pane::LocalImageAttachment;
use crate::chatwidget::ChatWidget;
use crate::chatwidget::UserMessage;
@@ -40,9 +41,7 @@ use crate::pager_overlay::Overlay;
use crate::tui;
use crate::tui::TuiEvent;
use codex_app_server_protocol::ClientRequest;
use codex_app_server_protocol::SortDirection;
use codex_app_server_protocol::ThreadItem;
use codex_app_server_protocol::ThreadItemsListParams;
use codex_app_server_protocol::ThreadItemsListResponse;
use codex_app_server_protocol::Turn;
use codex_app_server_protocol::TurnStatus;
@@ -114,13 +113,12 @@ impl App {
let result = request_handle
.request_typed::<ThreadItemsListResponse>(ClientRequest::ThreadItemsList {
request_id,
params: ThreadItemsListParams {
thread_id: thread_id.to_string(),
turn_id: None,
cursor: Some(cursor.clone()),
limit: Some(HISTORY_ITEM_PAGE_LIMIT),
sort_direction: Some(SortDirection::Desc),
},
params: thread_items_page_params(
thread_id,
/*turn_id*/ None,
Some(cursor.clone()),
HISTORY_ITEM_PAGE_LIMIT,
),
})
.await
.map_err(|err| err.to_string());