Fix a bug where the draft thread was being spuriously dropped from the sidebar (#52936)

Mikayla Maki created

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- N/A

Change summary

crates/sidebar/src/sidebar.rs | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

Detailed changes

crates/sidebar/src/sidebar.rs 🔗

@@ -709,19 +709,25 @@ impl Sidebar {
         // Derive active_entry from the active workspace's agent panel.
         // Draft is checked first because a conversation can have a session_id
         // before any messages are sent. However, a thread that's still loading
-        // also appears as a "draft" (no messages yet), so when we already have
-        // an eager Thread write for this workspace we preserve it. A session_id
-        // on a non-draft is a positive Thread signal. The remaining case
-        // (conversation exists, not draft, no session_id) is a genuine
-        // mid-load — keep the previous value.
+        // also appears as a "draft" (no messages yet).
         if let Some(active_ws) = &active_workspace {
             if let Some(panel) = active_ws.read(cx).panel::<AgentPanel>(cx) {
                 if panel.read(cx).active_thread_is_draft(cx)
                     || panel.read(cx).active_conversation_view().is_none()
                 {
+                    let conversation_parent_id = panel
+                        .read(cx)
+                        .active_conversation_view()
+                        .and_then(|cv| cv.read(cx).parent_id(cx));
                     let preserving_thread =
-                        matches!(&self.active_entry, Some(ActiveEntry::Thread { .. }))
-                            && self.active_entry_workspace() == Some(active_ws);
+                        if let Some(ActiveEntry::Thread { session_id, .. }) = &self.active_entry {
+                            self.active_entry_workspace() == Some(active_ws)
+                                && conversation_parent_id
+                                    .as_ref()
+                                    .is_some_and(|id| id == session_id)
+                        } else {
+                            false
+                        };
                     if !preserving_thread {
                         self.active_entry = Some(ActiveEntry::Draft(active_ws.clone()));
                     }