Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
agent: Fix issue where new from summary was not working (#54648)
Bennet Bo Fenner4d346e9ebbac
diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rsindex 8a09f939998..e5c6f161022 100644--- a/crates/agent_ui/src/agent_panel.rs+++ b/crates/agent_ui/src/agent_panel.rs@@ -1404,20 +1404,11 @@ impl AgentPanel {) {let session_id = action.from_session_id.clone();- let Some(thread) = ThreadStore::global(cx)- .read(cx)- .entries()- .find(|t| t.id == session_id)- else {+ let Some(content) = Self::initial_content_for_thread_summary(session_id.clone(), cx) else {log::error!("No session found for summarization with id {}", session_id);return;};- let Some(parent_session_id) = thread.parent_session_id else {- log::error!("Session {} has no parent session", session_id);- return;- };-cx.spawn_in(window, async move |this, cx| {this.update_in(cx, |this, window, cx| {this.external_thread(@@ -1425,10 +1416,7 @@ impl AgentPanel {None,None,None,- Some(AgentInitialContent::ThreadSummary {- session_id: parent_session_id,- title: Some(thread.title),- }),+ Some(content),true,"agent_panel",window,@@ -1440,6 +1428,21 @@ impl AgentPanel {.detach_and_log_err(cx);}+ fn initial_content_for_thread_summary(+ session_id: acp::SessionId,+ cx: &App,+ ) -> Option<AgentInitialContent> {+ let thread = ThreadStore::global(cx)+ .read(cx)+ .entries()+ .find(|t| t.id == session_id)?;++ Some(AgentInitialContent::ThreadSummary {+ session_id: thread.id,+ title: Some(thread.title),+ })+ }+fn external_thread(&mut self,agent_choice: Option<crate::Agent>,@@ -5061,6 +5064,89 @@ mod tests {});}+ #[gpui::test]+ async fn test_initial_content_for_thread_summary_uses_own_session_id(cx: &mut TestAppContext) {+ init_test(cx);+ cx.update(|cx| {+ agent::ThreadStore::init_global(cx);+ language_model::LanguageModelRegistry::test(cx);+ });++ let source_session_id = acp::SessionId::new("source-thread-session");+ let source_title: SharedString = "Source Thread Title".into();+ let db_thread = agent::DbThread {+ title: source_title.clone(),+ messages: Vec::new(),+ updated_at: Utc::now(),+ detailed_summary: None,+ initial_project_snapshot: None,+ cumulative_token_usage: Default::default(),+ request_token_usage: HashMap::default(),+ model: None,+ profile: None,+ imported: false,+ subagent_context: None,+ speed: None,+ thinking_enabled: false,+ thinking_effort: None,+ draft_prompt: None,+ ui_scroll_position: None,+ };++ let thread_store = cx.update(|cx| ThreadStore::global(cx));+ thread_store+ .update(cx, |store, cx| {+ store.save_thread(+ source_session_id.clone(),+ db_thread,+ PathList::default(),+ cx,+ )+ })+ .await+ .expect("saving source thread should succeed");+ cx.run_until_parked();++ thread_store.read_with(cx, |store, _cx| {+ let entry = store+ .thread_from_session_id(&source_session_id)+ .expect("saved thread should be listed in the store");+ assert!(+ entry.parent_session_id.is_none(),+ "saved thread is a root thread with no parent session"+ );+ });++ let content = cx+ .update(|cx| {+ AgentPanel::initial_content_for_thread_summary(source_session_id.clone(), cx)+ })+ .expect("initial content should be produced for a root thread");++ match content {+ AgentInitialContent::ThreadSummary { session_id, title } => {+ assert_eq!(+ session_id, source_session_id,+ "thread-summary mention should use the source thread's own session id"+ );+ assert_eq!(title, Some(source_title.clone()));+ }+ _ => panic!("expected AgentInitialContent::ThreadSummary"),+ }++ // Unknown session ids should still produce no content.+ let missing = cx.update(|cx| {+ AgentPanel::initial_content_for_thread_summary(+ acp::SessionId::new("does-not-exist"),+ cx,+ )+ });+ assert!(+ missing.is_none(),+ "unknown session ids should not produce initial content"+ );+ }+#[gpui::test]async fn test_cleanup_retained_threads_keeps_five_most_recent_idle_loadable_threads(cx: &mut TestAppContext,