Skip to content

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

refactor(storage): improve storage runtime configuration

Steven Enamakelf540716ab20d
diff --git a/crates/openhuman-core/src/storage/import/mod.rs b/crates/openhuman-core/src/storage/import/mod.rs
index ec97c02f25..51abeef76b 100644
--- a/crates/openhuman-core/src/storage/import/mod.rs
+++ b/crates/openhuman-core/src/storage/import/mod.rs
@@ -49,7 +49,6 @@
//! with `tinyflows-import`; see [`tinyflows`].
pub mod live;
-#[cfg(feature = "legacy-import")]
mod schemas;
#[cfg(feature = "legacy-import")]
pub mod sessions;
@@ -58,36 +57,36 @@ mod snapshot;
#[cfg(feature = "legacy-import")]
pub mod tinyflows;
-#[cfg(feature = "legacy-import")]
pub use schemas::{
all_session_import_controller_schemas, all_session_import_registered_controllers,
};
#[cfg(feature = "legacy-import")]
use std::path::Path;
-#[cfg(feature = "legacy-import")]
use std::sync::Arc;
+use anyhow::Result;
#[cfg(feature = "legacy-import")]
-use anyhow::{anyhow, Context, Result};
+use anyhow::{anyhow, Context};
#[cfg(feature = "legacy-import")]
use sha2::Digest;
+use tinystoragedrivers::CollectionSpec;
#[cfg(feature = "legacy-import")]
-use tinystoragedrivers::{CollectionSpec, ErrorKind, Precondition};
+use tinystoragedrivers::{ErrorKind, Precondition};
#[cfg(feature = "legacy-import")]
use super::documents::Repo;
#[cfg(feature = "legacy-import")]
use super::rusqlite;
#[cfg(feature = "legacy-import")]
-use super::{block_on, StorageBackend};
-#[cfg(feature = "legacy-import")]
+use super::block_on;
+use super::StorageBackend;
use crate::config::Config;
#[cfg(feature = "legacy-import")]
use rusqlite::Connection;
-#[cfg(feature = "legacy-import")]
use serde_json::Value;
+#[cfg(feature = "legacy-import")]
pub use snapshot::Snapshot;
/// One legacy row as a document of the new layout.
@@ -254,6 +253,14 @@ pub async fn run(ctx: &crate::core::runtime::DispatchCtx, config: &Config) -> Ve
}
}
+/// Reports that the legacy import boundary is unavailable in this build.
+/// The stub keeps boot and rebind callers explicit: disabling the feature
+/// never makes a detected legacy source look successfully imported.
+#[cfg(not(feature = "legacy-import"))]
+pub async fn run(_ctx: &crate::core::runtime::DispatchCtx, _config: &Config) -> Vec<Report> {
+ unavailable_report()
+}
+
/// Every importer, in order, over `backend` for `config`'s workspace; from
/// synchronous code.
#[cfg(feature = "legacy-import")]
@@ -264,6 +271,21 @@ pub fn run_all(backend: &Arc<dyn StorageBackend>, config: &Config) -> Vec<Report
reports
}
+#[cfg(not(feature = "legacy-import"))]
+pub fn run_all(_backend: &Arc<dyn StorageBackend>, _config: &Config) -> Vec<Report> {
+ unavailable_report()
+}
+
+#[cfg(not(feature = "legacy-import"))]
+fn unavailable_report() -> Vec<Report> {
+ vec![Report {
+ domain: "legacy-import",
+ outcome: Err(anyhow::anyhow!(
+ "legacy storage import requires the `legacy-import` feature"
+ )),
+ }]
+}
+
/// [`run`] over an explicit backend and source list, from synchronous code.
#[cfg(feature = "legacy-import")]
pub fn run_with(
diff --git a/crates/openhuman-core/src/storage/mod.rs b/crates/openhuman-core/src/storage/mod.rs
index 4111943cbf..6e5d1584a6 100644
--- a/crates/openhuman-core/src/storage/mod.rs
+++ b/crates/openhuman-core/src/storage/mod.rs
@@ -126,7 +126,12 @@ impl Blocking {
std::thread::Builder::new()
.name("openhuman-storage".to_owned())
.spawn(move || {
- let runtime = tokio::runtime::Builder::new_current_thread()
+ // The bridge thread can be idle in `receiver.recv()` between
+ // sync calls. A current-thread runtime would stop polling its
+ // background tasks during that interval, so use a small
+ // multithread runtime dedicated to storage work.
+ let runtime = tokio::runtime::Builder::new_multi_thread()
+ .worker_threads(2)
.enable_all()
.build();
match runtime {
diff --git a/crates/openhuman-core/src/storage/mod_tests.rs b/crates/openhuman-core/src/storage/mod_tests.rs
index b1f08a7bb4..6f44f3643b 100644
--- a/crates/openhuman-core/src/storage/mod_tests.rs
+++ b/crates/openhuman-core/src/storage/mod_tests.rs
@@ -173,6 +173,28 @@ async fn block_on_works_inside_a_multi_thread_runtime() {
);
}
+#[tokio::test(flavor = "current_thread")]
+async fn bridge_runtime_keeps_background_tasks_running_between_sync_calls() {
+ let (release_tx, release_rx) = tokio::sync::oneshot::channel();
+ let (progress_tx, progress_rx) = std::sync::mpsc::channel();
+ block_on(async move {
+ tokio::spawn(async move {
+ if release_rx.await.is_ok() {
+ let _ = progress_tx.send(());
+ }
+ });
+ Ok(())
+ })
+ .unwrap();
+
+ // The bridge has returned to its blocking receive loop. Releasing the
+ // task from the caller must still let the dedicated runtime poll it.
+ release_tx.send(()).unwrap();
+ progress_rx
+ .recv_timeout(std::time::Duration::from_secs(2))
+ .expect("bridge runtime polled its background task while idle");
+}
+
#[test]
fn only_mongodb_is_shared_between_processes() {
assert!(driver_is_shared("mongodb"));