agent_ui: Fix empty agent panel state after startup (#53823)

Bennet Bo Fenner 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/agent_ui/src/agent_panel.rs | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)

Detailed changes

crates/agent_ui/src/agent_panel.rs 🔗

@@ -1041,6 +1041,10 @@ impl AgentPanel {
                             cx,
                         );
                     });
+                } else {
+                    panel.update(cx, |panel, cx| {
+                        panel.show_or_create_empty_draft(window, cx);
+                    });
                 }
                 panel
             })?;
@@ -5347,8 +5351,8 @@ mod tests {
             );
         });
 
-        // Workspace B should restore its own agent type, with no thread
-        loaded_b.read_with(cx, |panel, _cx| {
+        // Workspace B should restore its own agent type and seed an empty draft.
+        loaded_b.read_with(cx, |panel, cx| {
             assert_eq!(
                 panel.selected_agent,
                 Agent::Custom {
@@ -5357,8 +5361,12 @@ mod tests {
                 "workspace B agent type should be restored"
             );
             assert!(
-                panel.active_conversation_view().is_none(),
-                "workspace B should have no active thread"
+                panel.active_conversation_view().is_some(),
+                "workspace B should show an empty draft"
+            );
+            assert!(
+                panel.active_thread_is_draft(cx),
+                "workspace B should seed a draft in an empty workspace"
             );
         });
     }
@@ -5420,10 +5428,14 @@ mod tests {
             .expect("panel load should succeed");
         cx.run_until_parked();
 
-        loaded.read_with(cx, |panel, _cx| {
+        loaded.read_with(cx, |panel, cx| {
+            assert!(
+                panel.active_conversation_view().is_some(),
+                "empty workspaces should still show a draft after load"
+            );
             assert!(
-                panel.active_conversation_view().is_none(),
-                "thread without metadata should not be restored"
+                panel.active_thread_is_draft(cx),
+                "thread without metadata should not be restored; the panel should fall back to a fresh draft"
             );
         });
     }
@@ -6377,6 +6389,7 @@ mod tests {
         )
         .await;
         fs.set_branch_name(Path::new("/project/.git"), Some("main"));
+        cx.update(|cx| <dyn Fs>::set_global(fs.clone(), cx));
 
         let project = Project::test(fs.clone(), [Path::new("/project")], cx).await;