assistant2: Don't block ThreadStore initialization on reloading the threads (#23728)

This PR changes the `ThreadStore` constructor to not block on reloading
the threads before we finish initializing it.

This allows us to make the constructor synchronous instead of
asynchronous.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-01-27 12:59:28 -05:00 committed by GitHub
parent 9705764892
commit f096a28a19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 41 deletions

View file

@ -119,12 +119,10 @@ impl AssistantPanel {
cx.spawn(|mut cx| async move { cx.spawn(|mut cx| async move {
let tools = Arc::new(ToolWorkingSet::default()); let tools = Arc::new(ToolWorkingSet::default());
log::info!("[assistant2-debug] initializing ThreadStore"); log::info!("[assistant2-debug] initializing ThreadStore");
let thread_store = workspace let thread_store = workspace.update(&mut cx, |workspace, cx| {
.update(&mut cx, |workspace, cx| { let project = workspace.project().clone();
let project = workspace.project().clone(); ThreadStore::new(project, tools.clone(), cx)
ThreadStore::new(project, tools.clone(), cx) })??;
})?
.await?;
log::info!("[assistant2-debug] finished initializing ThreadStore"); log::info!("[assistant2-debug] finished initializing ThreadStore");
let slash_commands = Arc::new(SlashCommandWorkingSet::default()); let slash_commands = Arc::new(SlashCommandWorkingSet::default());

View file

@ -34,45 +34,39 @@ impl ThreadStore {
project: Entity<Project>, project: Entity<Project>,
tools: Arc<ToolWorkingSet>, tools: Arc<ToolWorkingSet>,
cx: &mut App, cx: &mut App,
) -> Task<Result<Entity<Self>>> { ) -> Result<Entity<Self>> {
cx.spawn(|mut cx| async move { let this = cx.new(|cx| {
let this = cx.new(|cx: &mut Context<Self>| { let context_server_factory_registry = ContextServerFactoryRegistry::default_global(cx);
let context_server_factory_registry = let context_server_manager = cx.new(|cx| {
ContextServerFactoryRegistry::default_global(cx); ContextServerManager::new(context_server_factory_registry, project.clone(), cx)
let context_server_manager = cx.new(|cx| { });
ContextServerManager::new(context_server_factory_registry, project.clone(), cx)
});
let executor = cx.background_executor().clone(); let executor = cx.background_executor().clone();
let database_future = executor let database_future = executor
.spawn({ .spawn({
let executor = executor.clone(); let executor = executor.clone();
let database_path = paths::support_dir().join("threads/threads-db.0.mdb"); let database_path = paths::support_dir().join("threads/threads-db.0.mdb");
async move { ThreadsDatabase::new(database_path, executor) } async move { ThreadsDatabase::new(database_path, executor) }
}) })
.then(|result| future::ready(result.map(Arc::new).map_err(Arc::new))) .then(|result| future::ready(result.map(Arc::new).map_err(Arc::new)))
.boxed() .boxed()
.shared(); .shared();
let this = Self { let this = Self {
project, project,
tools, tools,
context_server_manager, context_server_manager,
context_server_tool_ids: HashMap::default(), context_server_tool_ids: HashMap::default(),
threads: Vec::new(), threads: Vec::new(),
database_future, database_future,
}; };
this.register_context_server_handlers(cx); this.register_context_server_handlers(cx);
this.reload(cx).detach_and_log_err(cx);
this this
})?; });
log::info!("[assistant2-debug] reloading threads"); Ok(this)
this.update(&mut cx, |this, cx| this.reload(cx))?.await?;
log::info!("[assistant2-debug] finished reloading threads");
Ok(this)
})
} }
/// Returns the number of threads. /// Returns the number of threads.