From 7a560903c008289a5f73ea6717dfa4702b1484a7 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 1 Apr 2026 10:55:07 -0400 Subject: [PATCH] Fix unarchive rollback using session_id directly instead of stale metadata 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. --- crates/sidebar/src/sidebar.rs | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/crates/sidebar/src/sidebar.rs b/crates/sidebar/src/sidebar.rs index 602f60d70d8d2f30ebfd3296708d0974fd48a2af..3bb6c9dbef4e1ee986bacd6f9f187b3f2b8f5f74 100644 --- a/crates/sidebar/src/sidebar.rs +++ b/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, window: &mut Window, cx: &mut Context, ) { @@ -2899,6 +2889,7 @@ impl Sidebar { let 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.