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
@@ -1,5 +1,6 @@
//! Adapts native Cloud requests and the currently open conversation’s reply stream.
//! A replacement becomes active only after its native attachment opens successfully.
//! Loaded-thread queries report reply attachments, not retained resume metadata.
mod auth;
mod events;
@@ -252,6 +253,15 @@ async fn handle_request(
replies: &mut Replies,
output: &mpsc::UnboundedSender<AppServerEvent>,
) -> Result<Value> {
if let protocol::ClientRequest::ThreadLoadedList { .. } = &request {
// The archive RPC can fail after closing Attach. Observe a ready EOF even
// when the RPC result won the worker's select before the stream did.
let _ = tokio::task::unconstrained(replies.forward_next(output)).now_or_never();
return Ok(serde_json::json!({
"data": replies.active.iter().map(|active| &active.thread_id).collect::<Vec<_>>(),
"nextCursor": null,
}));
}
if let protocol::ClientRequest::ThreadRead { params, .. } = &request {
return requests.read_thread(params, replies.thread_status(&params.thread_id));
}
@@ -277,6 +287,24 @@ async fn handle_request(
.await?
{
requests::Response::Value(value) => Ok(value),
requests::Response::Archived(thread_id) => {
replies.detach(&thread_id);
replies.stream_losses.supersede(&thread_id);
if requests
.loaded
.as_ref()
.is_some_and(|loaded| loaded.thread.id == thread_id)
{
requests.loaded = None;
}
send_notification(
output,
protocol::ServerNotification::ThreadArchived(
protocol::ThreadArchivedNotification { thread_id },
),
);
Ok(serde_json::to_value(protocol::ThreadArchiveResponse {})?)
}
requests::Response::Attach(settings) => {
let id = &settings.thread.id;
let result = serde_json::to_value(&settings)?;