mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Respect paginated history when stopping background tasks (#40787)
## Why Stopping a task from the agents overview may need to look up its active turn. Paginated threads should use the turn history endpoint instead of requesting embedded full history. ## What changed - Read the thread without turns first to determine its history mode. - Fetch the first turn page for paginated threads when the app server supports it. - Fall back to embedded turn history for legacy threads and legacy server negotiation. ## Testing Added coverage for paginated and legacy threads, including fallback after legacy capability negotiation. GitOrigin-RevId: 44d506b19e32c6b3c27fac11fb748c23b8e47b5e
This commit is contained in:
1 parent
98ee29c7cd
commit
37f4bb94c9
3 files changed
+118
-8
No files matched your search
@@ -12,6 +12,7 @@ use crate::chatwidget::ThreadInputStateRestoreMode;
|
||||
use codex_app_server_protocol::RequestId;
|
||||
use codex_app_server_protocol::SessionSource;
|
||||
use codex_app_server_protocol::Thread;
|
||||
use codex_app_server_protocol::ThreadHistoryMode;
|
||||
use codex_app_server_protocol::ThreadItem;
|
||||
use codex_app_server_protocol::ThreadLoadedListParams;
|
||||
use codex_app_server_protocol::ThreadLoadedListResponse;
|
||||
@@ -666,15 +667,34 @@ impl App {
|
||||
) {
|
||||
let active_turn_id = match self.active_turn_id_for_thread(thread_id).await {
|
||||
Some(turn_id) => Some(turn_id),
|
||||
None => match app_server
|
||||
.thread_read(thread_id, /*include_turns*/ true)
|
||||
.await
|
||||
None => match async {
|
||||
let thread = app_server
|
||||
.thread_read(thread_id, /*include_turns*/ false)
|
||||
.await?;
|
||||
let turns = match thread.history_mode {
|
||||
ThreadHistoryMode::Paginated if app_server.supports_paginated_history() => {
|
||||
app_server
|
||||
.thread_turns_page(thread_id, /*cursor*/ None)
|
||||
.await?
|
||||
.data
|
||||
}
|
||||
ThreadHistoryMode::Legacy | ThreadHistoryMode::Paginated => {
|
||||
app_server
|
||||
.thread_read(thread_id, /*include_turns*/ true)
|
||||
.await?
|
||||
.turns
|
||||
}
|
||||
};
|
||||
Ok::<_, color_eyre::Report>(
|
||||
turns
|
||||
.into_iter()
|
||||
.find(|turn| turn.status == TurnStatus::InProgress)
|
||||
.map(|turn| turn.id),
|
||||
)
|
||||
}
|
||||
.await
|
||||
{
|
||||
Ok(thread) => thread
|
||||
.turns
|
||||
.into_iter()
|
||||
.find(|turn| turn.status == TurnStatus::InProgress)
|
||||
.map(|turn| turn.id),
|
||||
Ok(turn_id) => turn_id,
|
||||
Err(error) => {
|
||||
self.chat_widget
|
||||
.add_error_message(format!("Failed to stop background task: {error}"));
|
||||
|
||||
Reference in new issue
Block a user