Fix unarchive rollback using session_id directly instead of stale metadata

Richard Feldman created

The thread_metadata was captured after the archive call, so it could
be None (the thread was already excluded from the entries list). This
made the unarchive rollback closure a silent no-op on failure.

Instead, clone the session_id directly for the rollback closure,
which always works regardless of when the archive happened.

Change summary

crates/sidebar/src/sidebar.rs | 21 +++++----------------
1 file changed, 5 insertions(+), 16 deletions(-)

Detailed changes

crates/sidebar/src/sidebar.rs 🔗

@@ -2814,16 +2814,7 @@ impl Sidebar {
             }
         }
 
-        // Capture metadata before archiving in case we need to cancel.
-        let thread_metadata = self.contents.entries.iter().find_map(|entry| {
-            if let ListEntry::Thread(t) = entry {
-                if &t.metadata.session_id == session_id {
-                    return Some(t.metadata.clone());
-                }
-            }
-            None
-        });
-        self.maybe_delete_git_worktree_for_archived_thread(session_id, thread_metadata, window, cx);
+        self.maybe_delete_git_worktree_for_archived_thread(session_id, window, cx);
     }
 
     /// If the thread being archived is associated with a linked git worktree,
@@ -2833,7 +2824,6 @@ impl Sidebar {
     fn maybe_delete_git_worktree_for_archived_thread(
         &self,
         session_id: &acp::SessionId,
-        thread_metadata: Option<ThreadMetadata>,
         window: &mut Window,
         cx: &mut Context<Self>,
     ) {
@@ -2899,6 +2889,7 @@ impl Sidebar {
         let fs = <dyn fs::Fs>::global(cx);
         let worktree_path_str = worktree_path.to_string_lossy().to_string();
         let main_repo_path_str = main_repo_path.to_string_lossy().to_string();
+        let session_id = session_id.clone();
 
         cx.spawn_in(window, async move |_this, cx| {
             if !is_last_thread {
@@ -2909,11 +2900,9 @@ impl Sidebar {
 
             // Helper: unarchive the thread so it reappears in the sidebar.
             let unarchive = |cx: &mut AsyncWindowContext| {
-                if let Some(metadata) = &thread_metadata {
-                    store.update(cx, |store, cx| {
-                        store.unarchive(&metadata.session_id, cx);
-                    });
-                }
+                store.update(cx, |store, cx| {
+                    store.unarchive(&session_id, cx);
+                });
             };
 
             // Helper: undo both WIP commits on the worktree.