From a3d27d68c67de0214b86f3d8ad8960b9a29bcc4a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 2 Apr 2026 11:16:25 -0400 Subject: [PATCH] Link all threads on a worktree to the archived record, not just the last When the last thread on a worktree triggers archival, all threads associated with that worktree (including previously archived ones) are linked to the archived worktree record. This way any of them can trigger a restore when unarchived, not just the last one. --- crates/agent_ui/src/thread_metadata_store.rs | 8 ++++++ crates/sidebar/src/sidebar.rs | 28 +++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/crates/agent_ui/src/thread_metadata_store.rs b/crates/agent_ui/src/thread_metadata_store.rs index 06bcf0855aa2d1e85d9ea67a2fd65feffe484b7e..d85c441cb2500c764e80a45ea658929a488f3072 100644 --- a/crates/agent_ui/src/thread_metadata_store.rs +++ b/crates/agent_ui/src/thread_metadata_store.rs @@ -241,6 +241,14 @@ impl ThreadMetadataStore { self.entries().filter(|t| t.archived) } + /// Returns all session IDs for the given path list, including archived threads. + pub fn all_session_ids_for_path( + &self, + path_list: &PathList, + ) -> impl Iterator + '_ { + self.threads_by_paths.get(path_list).into_iter().flatten() + } + /// Returns all threads for the given path list, excluding archived threads. pub fn entries_for_path( &self, diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rs index 6582e320187de8c198818cbc087fda316e35abbd..d7879555c33a160e02cd0f5e4be203c810210e5e 100644 --- a/crates/sidebar/src/sidebar.rs +++ b/crates/sidebar/src/sidebar.rs @@ -3317,12 +3317,28 @@ impl Sidebar { match create_result { Ok(id) => { - // Link the current thread to the archived worktree record. - let link_result = store - .update(cx, |store, cx| { - store.link_thread_to_archived_worktree(session_id.0.to_string(), id, cx) - }) - .await; + // Link all threads on this worktree (including + // previously archived ones) to the archived + // worktree record so any of them can trigger a + // restore later. + let session_ids: Vec = store.update(cx, |store, _cx| { + store + .all_session_ids_for_path(&folder_paths) + .map(|s| s.0.to_string()) + .collect() + }); + let mut link_result: anyhow::Result<()> = Ok(()); + for sid in session_ids { + let result = store + .update(cx, |store, cx| { + store.link_thread_to_archived_worktree(sid, id, cx) + }) + .await; + if let Err(err) = result { + link_result = Err(err); + break; + } + } if let Err(err) = link_result { log::error!("Failed to link thread to archived worktree: {err}");