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:
Benjamin Carlsson
2026-11-10 18:19:11 +00:00
committed by copyberry
parent 627b579219
commit df82e2fe0a
16 changed files with 698 additions and 78 deletions
+47 -3
View File
@@ -89,6 +89,7 @@ use codex_http_client::RouteAwareClientPool;
use futures::StreamExt;
use futures::stream::BoxStream;
use http_body_util::BodyExt;
use prost::Message;
use std::io;
use std::time::Duration;
use tonic::body::Body;
@@ -217,7 +218,7 @@ impl Client {
http::uri::PathAndQuery::from_static(
"/oaiproto.codex_app_server_backend.ThreadService/Resume",
),
ProstCodec::<ResumeRequest, wire::ResumeResponse>::default(),
ProstCodec::<ResumeRequest, wire::EmptyResponse>::default(),
),
)
.await
@@ -226,6 +227,49 @@ impl Client {
Ok(())
}
/// Archives a conversation using the current account, without opening an attachment.
pub async fn archive_thread(&self, thread_id: &str) -> Result<(), MutationError> {
if thread_id.trim().is_empty() {
return Err(MutationError::InvalidRequest);
}
let payload = self
.mutate(
wire::ThreadIdRequest {
thread_id: thread_id.to_owned(),
},
"/oaiproto.codex_app_server_backend.ThreadService/ArchiveThread",
)
.await?;
wire::EmptyResponse::decode(payload)
.map_err(|_| MutationError::OutcomeUnknown(Error::InvalidResponse))?;
Ok(())
}
/// Restores an archived conversation without resuming it.
pub async fn unarchive_thread(&self, thread_id: &str) -> Result<ThreadSnapshot, MutationError> {
if thread_id.trim().is_empty() {
return Err(MutationError::InvalidRequest);
}
let payload = self
.mutate(
wire::ThreadIdRequest {
thread_id: thread_id.to_owned(),
},
"/oaiproto.codex_app_server_backend.ThreadService/UnarchiveThread",
)
.await?;
let response = wire::UnarchiveResponse::decode(payload)
.map_err(|_| MutationError::OutcomeUnknown(Error::InvalidResponse))?;
let raw_thread = response
.thread
.ok_or(MutationError::OutcomeUnknown(Error::InvalidResponse))?;
let thread = ThreadSnapshot::decode(raw_thread).map_err(MutationError::OutcomeUnknown)?;
if thread.id != thread_id {
return Err(MutationError::OutcomeUnknown(Error::InvalidResponse));
}
Ok(thread)
}
/// Live events only, without history or automatic reconnect. The stream terminates
/// on its first error. Setup is bounded; there is no idle or total stream deadline.
pub async fn attach(
@@ -233,7 +277,7 @@ impl Client {
thread_id: &str,
) -> Result<BoxStream<'static, Result<Event, Error>>, Error> {
let mut grpc = self.grpc.clone();
let mut request = tonic::Request::new(wire::AttachRequest {
let mut request = tonic::Request::new(wire::ThreadIdRequest {
thread_id: thread_id.to_owned(),
});
*request.metadata_mut() =
@@ -245,7 +289,7 @@ impl Client {
http::uri::PathAndQuery::from_static(
"/oaiproto.codex_app_server_backend.ThreadService/Attach",
),
ProstCodec::<wire::AttachRequest, wire::AttachResponse>::default(),
ProstCodec::<wire::ThreadIdRequest, wire::AttachResponse>::default(),
),
)
.await