Skip to content

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

refactor(storage): enable legacy import features

Steven Enamakel65911daceeb8
diff --git a/Cargo.lock b/Cargo.lock
index 6886e6c151..bf08e3b703 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5476,6 +5476,7 @@ dependencies = [
"tinystoragedrivers-api",
"tinystoragedrivers-bus",
"tinystoragedrivers-busproxy 2.0.2",
+ "tinystoragedrivers-connect",
"tinystoragedrivers-secrets",
"tinystoragedrivers-testkit",
"tinystoragedrivers-types",
diff --git a/crates/openhuman-core/src/core/all.rs b/crates/openhuman-core/src/core/all.rs
index 6fef035c87..45d37a50ef 100644
--- a/crates/openhuman-core/src/core/all.rs
+++ b/crates/openhuman-core/src/core/all.rs
@@ -12,8 +12,8 @@ use std::{
use serde_json::{Map, Value};
-use crate::core::runtime::DispatchCtx;
use crate::core::ControllerSchema;
+use crate::core::runtime::DispatchCtx;
/// A pinned, boxed future returned by a controller handler.
pub type ControllerFuture = Pin<Box<dyn Future<Output = Result<Value, String>> + Send + 'static>>;
@@ -671,8 +671,11 @@ fn build_registered_controllers() -> Vec<GroupedController> {
crate::desktop::notifications::all_notifications_registered_controllers(),
);
// Storage layout v1 -> v2 migration, status and restore
- #[rustfmt::skip]
+ #[cfg(feature = "legacy-import")]
+ {
+ #[rustfmt::skip]
push(&mut controllers, DomainGroup::Config, crate::storage::layout::schemas::all_registered_controllers());
+ }
// Mobile device pairing and management
push(
&mut controllers,
diff --git a/crates/openhuman-core/src/desktop/notifications/store_documents.rs b/crates/openhuman-core/src/desktop/notifications/store_documents.rs
index ba0bac6791..e5142671b4 100644
--- a/crates/openhuman-core/src/desktop/notifications/store_documents.rs
+++ b/crates/openhuman-core/src/desktop/notifications/store_documents.rs
@@ -43,8 +43,10 @@ use crate::config::Config;
use crate::storage::documents::{Repo, compare_and_swap, text, update_or_insert};
use crate::storage::{DocumentStore, DocumentStoreExt, StorageError};
+#[cfg(feature = "legacy-import")]
+use super::storage_schema::legacy_collections;
+use super::storage_schema::specs;
pub(super) use super::storage_schema::{CORE, DEDUP, NOTIFICATIONS, SETTINGS, core_id};
-use super::storage_schema::{legacy_collections, specs};
use crate::storage::schema_support::key_of;
/// The `workspace` key of core notifications in the per-workspace default
diff --git a/crates/openhuman-core/src/integrations/task_sources/store_documents.rs b/crates/openhuman-core/src/integrations/task_sources/store_documents.rs
index 7111bf606e..41a60adcac 100644
--- a/crates/openhuman-core/src/integrations/task_sources/store_documents.rs
+++ b/crates/openhuman-core/src/integrations/task_sources/store_documents.rs
@@ -33,8 +33,10 @@ use crate::integrations::composio::contract::NormalizedTask;
use crate::storage::documents::{Repo, compare_and_swap, text};
use crate::storage::{DocumentStoreExt, StorageError};
+#[cfg(feature = "legacy-import")]
+use super::storage_schema::legacy_collections;
+use super::storage_schema::specs;
pub(super) use super::storage_schema::{INGESTED, SOURCES, ingested_id};
-use super::storage_schema::{legacy_collections, specs};
use crate::storage::schema_support::key_of;
const DOMAIN: &str = "task_sources::store";
diff --git a/crates/openhuman-core/src/security/approval/store_documents.rs b/crates/openhuman-core/src/security/approval/store_documents.rs
index 9f8ec2b4f0..e90125d46d 100644
--- a/crates/openhuman-core/src/security/approval/store_documents.rs
+++ b/crates/openhuman-core/src/security/approval/store_documents.rs
@@ -36,8 +36,10 @@ use tinystoragedrivers::{
CollectionSpec, ErrorKind, Filter, Key, Precondition, Query, Sort, Versioned,
};
+#[cfg(feature = "legacy-import")]
+use super::storage_schema::legacy_collections;
+use super::storage_schema::specs;
pub(super) use super::storage_schema::{APPROVALS, FLOW_TRUST, trust_id};
-use super::storage_schema::{legacy_collections, specs};
use super::types::{
ApprovalAuditEntry, ApprovalDecision, ApprovalSourceContext, ExecutionOutcome, PendingApproval,
diff --git a/crates/openhuman-core/src/security/devices/store_documents.rs b/crates/openhuman-core/src/security/devices/store_documents.rs
index 10edceddaa..4f41639245 100644
--- a/crates/openhuman-core/src/security/devices/store_documents.rs
+++ b/crates/openhuman-core/src/security/devices/store_documents.rs
@@ -21,7 +21,9 @@ use crate::security::devices::types::PairedDevice;
use crate::storage::DocumentStoreExt;
use crate::storage::documents::{Repo, compare_and_swap, text};
-use super::storage_schema::{DEVICES, legacy_collections, spec};
+#[cfg(feature = "legacy-import")]
+use super::storage_schema::legacy_collections;
+use super::storage_schema::{DEVICES, spec};
use crate::storage::schema_support::{key_of, ms_rfc3339};
const DOMAIN: &str = "devices::store";
diff --git a/crates/openhuman-core/src/storage/import/disabled_tests.rs b/crates/openhuman-core/src/storage/import/disabled_tests.rs
new file mode 100644
index 0000000000..39cb0e0247
--- /dev/null
+++ b/crates/openhuman-core/src/storage/import/disabled_tests.rs
@@ -0,0 +1,15 @@
+use super::*;
+
+#[test]
+fn importing_without_the_feature_reports_unavailable_instead_of_success() {
+ let backend: Arc<dyn StorageBackend> =
+ Arc::new(tinystoragedrivers_testkit::MemoryBackend::new());
+ let reports = run_all(&backend, &Config::default());
+
+ assert_eq!(reports.len(), 1);
+ let error = reports[0]
+ .outcome
+ .as_ref()
+ .expect_err("a disabled importer must not claim success");
+ assert!(error.to_string().contains("legacy-import"));
+}
diff --git a/crates/openhuman-core/src/storage/import/mod.rs b/crates/openhuman-core/src/storage/import/mod.rs
index c821f847de..1318ee510b 100644
--- a/crates/openhuman-core/src/storage/import/mod.rs
+++ b/crates/openhuman-core/src/storage/import/mod.rs
@@ -521,6 +521,7 @@ fn import_one(
/// Whether the import of `source` is recorded as done (test and diagnostics
/// helper).
+#[cfg(feature = "legacy-import")]
pub fn is_done(
backend: &Arc<dyn StorageBackend>,
config: &Config,
@@ -538,3 +539,7 @@ pub fn is_done(
#[cfg(all(test, feature = "legacy-import"))]
#[path = "mod_tests.rs"]
mod tests;
+
+#[cfg(all(test, not(feature = "legacy-import")))]
+#[path = "disabled_tests.rs"]
+mod disabled_tests;
diff --git a/crates/openhuman-core/src/storage/layout/credentials.rs b/crates/openhuman-core/src/storage/layout/credentials.rs
index ad96e3caa1..318efbc96b 100644
--- a/crates/openhuman-core/src/storage/layout/credentials.rs
+++ b/crates/openhuman-core/src/storage/layout/credentials.rs
@@ -18,12 +18,15 @@
use std::path::Path;
+#[cfg(feature = "legacy-import")]
use tinystoragedrivers::secrets::SecretStore as _;
+#[cfg(feature = "legacy-import")]
use super::Target;
use super::state::LayoutError;
use crate::security::credentials::http_creds::{self, STORAGE_SECRET_NAME, STORE_FILENAME};
use crate::security::credentials::profiles::{self, PROFILES_FILENAME, PROFILES_SECRET_NAME};
+#[cfg(feature = "legacy-import")]
use crate::storage;
/// The path prefix a profile-level plan entry carries (`@profile/<file>`),
@@ -102,6 +105,7 @@ pub fn candidates(profile_dir: &Path) -> Result<Vec<String>, LayoutError> {
///
/// A write that does not read back identically, or a stored record that does
/// not decrypt with the current key. Nothing is deleted then.
+#[cfg(feature = "legacy-import")]
pub async fn import(target: &Target) -> Result<Vec<String>, LayoutError> {
let mut files = Vec::new();
for (file, secret) in FILES {
@@ -154,6 +158,6 @@ pub async fn import(target: &Target) -> Result<Vec<String>, LayoutError> {
Ok(imported)
}
-#[cfg(test)]
+#[cfg(all(test, feature = "legacy-import"))]
#[path = "credentials_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/storage/layout/mod.rs b/crates/openhuman-core/src/storage/layout/mod.rs
index 1d8277c943..1a2b3d24ab 100644
--- a/crates/openhuman-core/src/storage/layout/mod.rs
+++ b/crates/openhuman-core/src/storage/layout/mod.rs
@@ -39,26 +39,33 @@
pub mod archive;
pub mod credentials;
+#[cfg(feature = "legacy-import")]
pub mod db;
+#[cfg(feature = "legacy-import")]
pub mod legacy;
pub mod plan;
+#[cfg(feature = "legacy-import")]
mod run;
+#[cfg(feature = "legacy-import")]
pub mod schemas;
pub mod state;
+#[cfg(feature = "legacy-import")]
mod status;
use std::path::{Path, PathBuf};
use serde::Serialize;
-pub use run::{auto_migrate, migrate, restore, Options};
+#[cfg(feature = "legacy-import")]
+pub use run::{Options, auto_migrate, migrate, restore};
pub use state::{LayoutError, Step};
-pub use status::{status, Status};
+#[cfg(feature = "legacy-import")]
+pub use status::{Status, status};
+use crate::config::Config;
use crate::config::schema::profile_layout::{
PROFILE_FILES_DIR, PROFILE_STORAGE_FILE, PROFILE_WORKSPACE_DIR,
};
-use crate::config::Config;
/// Directory under the root that holds the archives.
pub const BACKUPS_DIR: &str = "backups";
@@ -199,9 +206,9 @@ pub enum Outcome {
Migrated(Box<Report>),
}
-#[cfg(test)]
+#[cfg(all(test, feature = "legacy-import"))]
mod test_fixtures;
-#[cfg(test)]
+#[cfg(all(test, feature = "legacy-import"))]
#[path = "mod_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/storage/mod.rs b/crates/openhuman-core/src/storage/mod.rs
index ec26e5b068..fb2c5963fc 100644
--- a/crates/openhuman-core/src/storage/mod.rs
+++ b/crates/openhuman-core/src/storage/mod.rs
@@ -134,6 +134,12 @@ impl Blocking {
let runtime = tokio::runtime::Builder::new_multi_thread()
.worker_threads(2)
.enable_all()
+ .on_thread_start(|| {
+ // Futures spawned from a bridge request may be
+ // polled on runtime workers rather than the owner
+ // thread, and must obey the same re-entrancy guard.
+ ON_STORAGE_RUNTIME.with(|active| active.set(true));
+ })
.build();
match runtime {
Ok(runtime) => {