Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Don't block thread creation when PromptStore fails to initialize (#52333)
Richard Feldman4a15e201baff
diff --git a/crates/agent/src/native_agent_server.rs b/crates/agent/src/native_agent_server.rsindex b79cd67b598..bc0f75bcff5 100644--- a/crates/agent/src/native_agent_server.rs+++ b/crates/agent/src/native_agent_server.rs@@ -11,6 +11,7 @@ use language_model::{LanguageModelId, LanguageModelProviderId, LanguageModelRegiuse project::{AgentId, Project};use prompt_store::PromptStore;use settings::{LanguageModelSelection, Settings as _, update_settings_file};+use util::ResultExt as _;use crate::{NativeAgent, NativeAgentConnection, ThreadStore, templates::Templates};@@ -48,11 +49,11 @@ impl AgentServer for NativeAgentServer {cx.spawn(async move |cx| {log::debug!("Creating templates for native agent");let templates = Templates::new();- let prompt_store = prompt_store.await?;+ let prompt_store = prompt_store.await.log_err();log::debug!("Creating native agent entity");- let agent = cx- .update(|cx| NativeAgent::new(thread_store, templates, Some(prompt_store), fs, cx));+ let agent =+ cx.update(|cx| NativeAgent::new(thread_store, templates, prompt_store, fs, cx));// Create the connection wrapperlet connection = NativeAgentConnection(agent);diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rsindex e5c6f161022..3ef0934e2de 100644--- a/crates/agent_ui/src/agent_panel.rs+++ b/crates/agent_ui/src/agent_panel.rs@@ -7123,4 +7123,42 @@ mod tests {);});}++ /// Regression test: NewThread must produce a connected thread even when+ /// the PromptStore fails to initialize (e.g. LMDB permission error).+ /// Before the fix, `NativeAgentServer::connect` propagated the+ /// PromptStore error with `?`, which put every new ConversationView+ /// into LoadError and made it impossible to start any native-agent+ /// thread.+ #[gpui::test]+ async fn test_new_thread_with_prompt_store_error(cx: &mut TestAppContext) {+ let (panel, mut cx) = setup_panel(cx).await;++ // NativeAgentServer::connect needs a global Fs.+ let fs = FakeFs::new(cx.executor());+ cx.update(|_, cx| {+ <dyn fs::Fs>::set_global(fs.clone(), cx);+ });+ cx.run_until_parked();++ // Dispatch NewThread, which goes through the real NativeAgentServer+ // path. In tests the PromptStore LMDB open fails with+ // "Permission denied"; the fix (.log_err() instead of ?) lets+ // the connection succeed anyway.+ panel.update_in(&mut cx, |panel, window, cx| {+ panel.new_thread(&NewThread, window, cx);+ });+ cx.run_until_parked();++ panel.read_with(&cx, |panel, cx| {+ assert!(+ panel.active_conversation_view().is_some(),+ "panel should have a conversation view after NewThread"+ );+ assert!(+ panel.active_agent_thread(cx).is_some(),+ "panel should have an active, connected agent thread"+ );+ });+ }}