mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Support archiving and restoring cloud threads (#60635)
## What changed - Add cloud archive and unarchive requests and support listing archived threads. - Detach successfully archived threads and emit archive notifications. Report loaded cloud threads from live attachments rather than cached resume metadata, including after archive failures. - Scope resume picker archive state and transcript previews by backend and thread so archiving a cloud session preserves a local session with the same ID. - Limit cloud task archive cleanup to the selected thread, preserving child agents and their active session state, and update the confirmation text accordingly. ## Testing Add regression coverage for archive acknowledgments, archived-thread discovery and restoration, attachment state after archive failures, same-ID sessions across backends, and preservation of attached child agents. GitOrigin-RevId: bd155be85ee911375d4d326b18f9b5abe8e82b3d
This commit is contained in:
committed by
copyberry
parent
627b579219
commit
df82e2fe0a
@@ -1,4 +1,4 @@
|
||||
//! Server RPCs own lifecycle outcomes; successful actions invalidate dashboard group caches.
|
||||
//! Server RPCs own lifecycle outcomes; cache cleanup follows the backend's removal scope.
|
||||
//! Keep the dashboard browsable during RPCs while deferring task notifications.
|
||||
//! Removing the current root leaves an unattached dashboard, even when it is empty.
|
||||
|
||||
@@ -202,6 +202,15 @@ impl App {
|
||||
.filter(|name| !name.is_empty())
|
||||
.unwrap_or("Untitled task");
|
||||
let (title, description, label) = match action {
|
||||
AgentsOverviewAction::Archive
|
||||
if self.app_server_target == crate::AppServerTarget::Cloud =>
|
||||
{
|
||||
(
|
||||
format!("Archive “{name}”?"),
|
||||
"This stops any running work in this task and archives it. Child agents stay unchanged. Its history can be restored from the resume picker.",
|
||||
"Archive task",
|
||||
)
|
||||
}
|
||||
AgentsOverviewAction::Archive => (
|
||||
format!("Archive “{name}”?"),
|
||||
"This stops any running work in this task and its child agents, then archives them. Their history can be restored from the resume picker.",
|
||||
@@ -278,6 +287,10 @@ impl App {
|
||||
if self.windows_sandbox_blocks_thread_switch() {
|
||||
return Ok(());
|
||||
}
|
||||
// Cloud archives only the selected thread; Local lifecycle actions include descendants.
|
||||
let removes_subtree = action != AgentsOverviewAction::Archive
|
||||
|| app_server.thread_params_mode()
|
||||
!= crate::app_server_session::ThreadParamsMode::Cloud;
|
||||
// The overview may lack intermediate ancestors, or even the primary's metadata.
|
||||
let mut removes_primary = self.primary_thread_id == Some(thread_id);
|
||||
let mut attempted = false;
|
||||
@@ -296,13 +309,17 @@ impl App {
|
||||
state.rename_target = None;
|
||||
}
|
||||
self.repaint_agents_overview();
|
||||
let voice_result = self
|
||||
.stop_voice_for_removed_thread(app_server, thread_id)
|
||||
.await;
|
||||
let voice_result = if removes_subtree || self.voice_owner_thread_id() == Some(thread_id) {
|
||||
self.stop_voice_for_removed_thread(app_server, thread_id)
|
||||
.await
|
||||
} else {
|
||||
Ok(())
|
||||
};
|
||||
let operation = async {
|
||||
let result = async {
|
||||
voice_result?;
|
||||
if let Some(primary) = primary_thread_id
|
||||
if removes_subtree
|
||||
&& let Some(primary) = primary_thread_id
|
||||
&& primary != thread_id
|
||||
{
|
||||
removes_primary = app_server
|
||||
@@ -369,8 +386,11 @@ impl App {
|
||||
self.agents_overview.refresh_notifications.clear();
|
||||
}
|
||||
if result.is_ok() {
|
||||
// Invalidate cached details for the displayed group, without inferring child outcomes.
|
||||
let mut removed = self.known_thread_subtree(thread_id);
|
||||
let mut removed = if removes_subtree {
|
||||
self.known_thread_subtree(thread_id)
|
||||
} else {
|
||||
HashSet::from([thread_id])
|
||||
};
|
||||
if let Some(primary) = self.primary_thread_id
|
||||
&& removes_primary
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::*;
|
||||
use crate::app::agents_overview_discovery::list_pinned_threads;
|
||||
use crate::app::tests::test_thread_session;
|
||||
use crate::app_event::AgentsOverviewAction;
|
||||
use codex_app_server_protocol::ClientRequest;
|
||||
use codex_app_server_protocol::RequestId;
|
||||
@@ -66,6 +67,120 @@ async fn pin_action_updates_shared_section_state() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn cloud_archive_preserves_attached_child_and_other_tasks() -> Result<()> {
|
||||
use codex_app_server_client::AppServerClient;
|
||||
use codex_app_server_client::CloudClient;
|
||||
use codex_app_server_client::CloudOperation;
|
||||
use serde_json::json;
|
||||
|
||||
let mut app = make_test_app().await;
|
||||
app.app_server_target = AppServerTarget::Cloud;
|
||||
let parent = ThreadId::new();
|
||||
let child = ThreadId::new();
|
||||
let other = ThreadId::new();
|
||||
let threads = HashMap::from([
|
||||
(
|
||||
parent,
|
||||
Some(overview_thread(
|
||||
parent,
|
||||
/*parent_thread_id*/ None,
|
||||
"Cloud parent",
|
||||
ThreadStatus::Idle,
|
||||
)),
|
||||
),
|
||||
(
|
||||
child,
|
||||
Some(overview_thread(
|
||||
child,
|
||||
Some(parent),
|
||||
"Cloud child",
|
||||
ThreadStatus::Active {
|
||||
active_flags: Vec::new(),
|
||||
},
|
||||
)),
|
||||
),
|
||||
(
|
||||
other,
|
||||
Some(overview_thread(
|
||||
other,
|
||||
/*parent_thread_id*/ None,
|
||||
"Other task",
|
||||
ThreadStatus::Idle,
|
||||
)),
|
||||
),
|
||||
]);
|
||||
app.agents_overview.threads = threads.clone();
|
||||
app.primary_thread_id = Some(child);
|
||||
app.active_thread_id = Some(child);
|
||||
app.chat_widget
|
||||
.handle_thread_session(test_thread_session(child, app.config.cwd.to_path_buf()));
|
||||
app.chat_widget
|
||||
.apply_external_edit("Keep child draft".into());
|
||||
let draft = app.chat_widget.capture_thread_input_state();
|
||||
crate::chatwidget::activate_voice_for_thread(&mut app.chat_widget, child);
|
||||
|
||||
app.confirm_agents_overview_action(parent, AgentsOverviewAction::Archive);
|
||||
insta::assert_snapshot!(render_bottom_popup(&app.chat_widget, /*width*/ 80), @"
|
||||
Archive “Cloud parent”?
|
||||
› Ke This stops any running work in this task and archives it. Child
|
||||
agents stay unchanged. Its history can be restored from the resume
|
||||
gp picker.
|
||||
|
||||
|
||||
› 1. Cancel
|
||||
2. Archive task
|
||||
|
||||
enter select · esc back
|
||||
");
|
||||
app.chat_widget.handle_key_event(KeyCode::Esc.into());
|
||||
|
||||
let (client, mut commands, _events) = CloudClient::channel(/*capacity*/ 1);
|
||||
let mut session = AppServerSession::new(
|
||||
crate::backend_id::BackendId::new(),
|
||||
AppServerClient::Cloud(client),
|
||||
crate::app_server_session::ThreadParamsMode::Cloud,
|
||||
);
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
tui.pause_events();
|
||||
let (result, ()) = tokio::join!(
|
||||
Box::pin(app.run_agents_overview_action(
|
||||
&mut tui,
|
||||
&mut session,
|
||||
parent,
|
||||
AgentsOverviewAction::Archive
|
||||
)),
|
||||
async {
|
||||
let command = commands.recv().await.expect("archive request");
|
||||
let CloudOperation::Request(request) = command.operation else {
|
||||
panic!("expected archive request");
|
||||
};
|
||||
assert!(
|
||||
matches!(*request, ClientRequest::ThreadArchive { params, .. } if params.thread_id == parent.to_string())
|
||||
);
|
||||
command.response.send(Ok(Ok(json!({})))).unwrap();
|
||||
},
|
||||
);
|
||||
result?;
|
||||
let mut expected = threads;
|
||||
expected.remove(&parent);
|
||||
assert_eq!(app.agents_overview.threads, expected);
|
||||
assert_eq!(
|
||||
(
|
||||
app.primary_thread_id,
|
||||
app.current_displayed_thread_id(),
|
||||
app.chat_widget.thread_id()
|
||||
),
|
||||
(Some(child), Some(child), Some(child))
|
||||
);
|
||||
assert_eq!(app.chat_widget.capture_thread_input_state(), draft);
|
||||
assert_eq!(app.voice_owner_thread_id(), Some(child));
|
||||
if let Some(refresh) = app.agents_overview.refresh_task.take() {
|
||||
refresh.abort();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn archive_confirmation_number_keys_act_immediately() {
|
||||
for key in ['1', '2'] {
|
||||
|
||||
Reference in New Issue
Block a user