Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(storage): avoid self-deadlock in async backend init

Steven Enamakel0d9f5be89854
diff --git a/crates/openhuman-core/src/storage/local.rs b/crates/openhuman-core/src/storage/local.rs
index 8a09f63472..fb8cb24c01 100644
--- a/crates/openhuman-core/src/storage/local.rs
+++ b/crates/openhuman-core/src/storage/local.rs
@@ -215,14 +215,20 @@ pub fn backend_for(workspace_dir: &Path) -> Result<Arc<dyn StorageBackend>> {
/// Async counterpart to [`backend_for`] for boot and module-proxy paths that
/// already run inside a future. Cold initialization is delegated to Tokio's
/// blocking pool so the shared OnceCell initializer is driven by the storage
-/// bridge rather than by the caller's runtime. A synchronous store may wait for
-/// that same initializer, including from a current-thread runtime, without
+/// bridge rather than by the caller's runtime. When already on the bridge's
+/// runtime, initialize directly: queueing a synchronous bridge call from a
+/// bridge worker would wait on itself. A synchronous store may wait for the
+/// same initializer, including from a current-thread runtime, without
/// preventing it from making progress.
pub async fn backend_for_async(workspace_dir: &Path) -> Result<Arc<dyn StorageBackend>> {
if let Some(backend) = installed() {
return Ok(backend);
}
let workspace_dir = workspace_dir.to_path_buf();
+ if super::ON_STORAGE_RUNTIME.with(std::cell::Cell::get) {
+ let cell = workspace_backend(&workspace_dir);
+ return initialized_backend(cell, workspace_dir).await;
+ }
tokio::task::spawn_blocking(move || backend_for(&workspace_dir))
.await
.context("join the workspace storage opener")?