The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(storage): update flow import logic for legacy support
Steven Enamakel86dc1a10e214
diff --git a/crates/openhuman-core/src/flows/catalog_storage.rs b/crates/openhuman-core/src/flows/catalog_storage.rsindex 617e382413..724778f876 100644--- a/crates/openhuman-core/src/flows/catalog_storage.rs+++ b/crates/openhuman-core/src/flows/catalog_storage.rs@@ -156,12 +156,12 @@ pub(crate) async fn register_backend_scope(}))}).await- .map_err(|error| format!("CatalogStorage migration registration task did not finish: {error}"))?+ .map_err(|error| {+ format!("CatalogStorage migration registration task did not finish: {error}")+ })?}-async fn register_scope(- documents: DocScope,-) -> Result<Arc<CatalogStorageRegistration>, String> {+async fn register_scope(documents: DocScope) -> Result<Arc<CatalogStorageRegistration>, String> {let key = documents.key();let path = path_for(&key);let runtime = crate::modules::runtime::runtime()diff --git a/crates/openhuman-core/src/modules/tinyflows.rs b/crates/openhuman-core/src/modules/tinyflows.rsindex 862cfd4a93..7b2bd3557e 100644--- a/crates/openhuman-core/src/modules/tinyflows.rs+++ b/crates/openhuman-core/src/modules/tinyflows.rs@@ -160,9 +160,7 @@ mod imp {}/// Catalog proxy used only while migrations or bounded legacy imports run.- pub(crate) async fn catalog_proxy_for_migration(- config: &Config,- ) -> Result<Proxy, String> {+ pub(crate) async fn catalog_proxy_for_migration(config: &Config) -> Result<Proxy, String> {ensure(config).await?;let runtime = runtime::runtime().awaitdiff --git a/crates/openhuman-core/src/storage/import/tinyflows.rs b/crates/openhuman-core/src/storage/import/tinyflows.rsindex 50e756b942..546d88aea4 100644--- a/crates/openhuman-core/src/storage/import/tinyflows.rs+++ b/crates/openhuman-core/src/storage/import/tinyflows.rs@@ -34,8 +34,9 @@ use crate::storage::{Scope, StorageBackend};type CatalogMigrationKey = (PathBuf, String);-static CATALOG_MIGRATIONS: LazyLock<Mutex<HashMap<CatalogMigrationKey, Result<(), String>>>> =- LazyLock::new(Default::default);+static CATALOG_MIGRATIONS: LazyLock<+ Mutex<HashMap<CatalogMigrationKey, std::result::Result<(), String>>>,+> = LazyLock::new(Default::default);/// The marker name of the flow catalog (flows, revisions, runs, state,/// suggestions, drafts) and checkpoints.@@ -197,7 +198,11 @@ async fn migrate_catalog_storage(.context("migrate the TinyFlows catalog storage")}-fn record_catalog_migration(config: &Config, scope: &Scope, outcome: Result<(), String>) {+fn record_catalog_migration(+ config: &Config,+ scope: &Scope,+ outcome: std::result::Result<(), String>,+) {let key = (config.workspace_dir.clone(), scope.as_str().to_owned());CATALOG_MIGRATIONS.lock()@@ -216,10 +221,7 @@ fn catalog_migration_ready(config: &Config, scope: &Scope) -> bool {)}-fn flow_import_marker_done(- backend: &Arc<dyn StorageBackend>,- config: &Config,-) -> Result<bool> {+fn flow_import_marker_done(backend: &Arc<dyn StorageBackend>, config: &Config) -> Result<bool> {let markers = Repo::on(backend,&crate::storage::tenant_scope(None),@@ -230,6 +232,18 @@ fn flow_import_marker_done(import_state::is_done(&markers, MARKER_OWNER, &step)}+#[cfg(feature = "flows")]+pub(crate) fn legacy_flow_import_pending(+ backend: &Arc<dyn StorageBackend>,+ config: &Config,+ scope: &Scope,+) -> Result<bool> {+ if scope != &Scope::local() || !flow_sources_present(&config.workspace_dir.join("flows")) {+ return Ok(false);+ }+ Ok(!flow_import_marker_done(backend, config)?)+}+/// Make the acting scope safe for workflow calls, retrying a failed Catalog/// migration before allowing access. A pending local legacy import gates only/// the local workflow scope; other domains and other storage scopes continue.@@ -246,15 +260,13 @@ pub(crate) async fn ensure_flow_scope_ready(config: &Config) -> std::result::Resrecord_catalog_migration(config, &scope, result.clone());result?;}- if scope == Scope::local() && flow_sources_present(&config.workspace_dir.join("flows")) {- let done = flow_import_marker_done(&backend, config)- .map_err(|error| format!("check the legacy flow import marker: {error:#}"))?;- if !done {- return Err(- "legacy flow import is incomplete for this workspace; workflow access is paused until it succeeds"- .to_owned(),- );- }+ if legacy_flow_import_pending(&backend, config, &scope)+ .map_err(|error| format!("check the legacy flow import marker: {error:#}"))?+ {+ return Err(+ "legacy flow import is incomplete for this workspace; workflow access is paused until it succeeds"+ .to_owned(),+ );}Ok(())}@@ -284,6 +296,7 @@ async fn migrate_owner_stores(config: Config,) -> (Vec<Report>, bool) {let scopes = crate::storage::boot::scopes_to_migrate(&backend).await;+ #[cfg(feature = "flows")]let local = Scope::local();#[cfg(feature = "flows")]let mut local_catalog_ready = false;@@ -306,10 +319,7 @@ async fn migrate_owner_stores(if let Err(error) = catalog {reports.push(finish(FLOWS_DOMAIN,- Err(error.context(format!(- "migrate the catalog for scope {}",- scope.as_str()- ))),+ Err(error.context(format!("migrate the catalog for scope {}", scope.as_str()))),));}}@@ -317,10 +327,7 @@ async fn migrate_owner_stores(if let Err(error) = migrate_schedule_storage(&backend, &config, &scope).await {reports.push(finish(CRON_DOMAIN,- Err(error.context(format!(- "migrate the schedule for scope {}",- scope.as_str()- ))),+ Err(error.context(format!("migrate the schedule for scope {}", scope.as_str()))),));}}@@ -348,13 +355,10 @@ fn import_flows_after_migration(let config = config.clone();let totals = Arc::new(Mutex::new(ImportTotals::default()));crate::storage::block_on_anyhow(async move {- let registration = crate::flows::catalog_storage::register_backend_scope(- &config,- backend,- scope,- )- .await- .map_err(anyhow::Error::msg)?;+ let registration =+ crate::flows::catalog_storage::register_backend_scope(&config, backend, scope)+ .await+ .map_err(anyhow::Error::msg)?;let storage = registration.storage();let proxy = crate::modules::tinyflows::catalog_proxy_for_migration(&config).await@@ -515,16 +519,12 @@ fn agent_cron_dirs(workspace: &Path) -> Vec<(String, PathBuf)> {pub fn run_with(backend: &Arc<dyn StorageBackend>, config: &Config) -> Vec<Report> {let backend_for_migration = Arc::clone(backend);let config_for_migration = config.clone();- let (mut reports, local_catalog_ready) =- match crate::storage::block_on_anyhow(async move {- Ok(migrate_owner_stores(backend_for_migration, config_for_migration).await)- }) {- Ok(result) => result,- Err(error) => (- vec![finish(FLOWS_DOMAIN, Err(error))],- false,- ),- };+ let (mut reports, local_catalog_ready) = match crate::storage::block_on_anyhow(async move {+ Ok(migrate_owner_stores(backend_for_migration, config_for_migration).await)+ }) {+ Ok(result) => result,+ Err(error) => (vec![finish(FLOWS_DOMAIN, Err(error))], false),+ };#[cfg(feature = "flows")]if local_catalog_ready {reports.push(finish(diff --git a/crates/openhuman-core/src/storage/import/tinyflows_tests.rs b/crates/openhuman-core/src/storage/import/tinyflows_tests.rsindex 479822290d..37e2a4e3f6 100644--- a/crates/openhuman-core/src/storage/import/tinyflows_tests.rs+++ b/crates/openhuman-core/src/storage/import/tinyflows_tests.rs@@ -346,6 +346,13 @@ fn an_invalid_flow_record_keeps_the_import_open_for_retry() {);let retry = import_flows(&backend, &Scope::local(), &config).unwrap();assert!(matches!(retry, Outcome::Incomplete { skipped: 1, .. }));+ assert!(legacy_flow_import_pending(&backend, &config, &Scope::local()).unwrap());+ assert!(!legacy_flow_import_pending(+ &backend,+ &config,+ &crate::storage::scope_for_profile("another-profile"),+ )+ .unwrap());assert_eq!(tree(dir.path()), before, "the legacy files were modified");}@@ -375,6 +382,41 @@ fn a_workspace_without_legacy_files_imports_nothing_and_leaves_no_marker() {assert!(written(import_flows(&backend, &Scope::local(), &with_files).unwrap()) > 0);}+#[tokio::test]+async fn catalog_and_schedule_owner_migrations_cover_existing_scopes() {+ let (_dir, config) = workspace();+ let backend = backend();+ let profile = crate::storage::scope_for_profile("migration-profile");+ let profile_scope = backend.for_scope(&profile).unwrap();+ profile_scope+ .documents()+ .ensure_collection(&tinystoragedrivers::CollectionSpec::new(+ "profile.migration-sentinel",+ ))+ .await+ .unwrap();++ let (reports, local_catalog_ready) = migrate_owner_stores(Arc::clone(&backend), config).await;+ assert!(local_catalog_ready);+ assert!(reports.is_empty(), "{reports:?}");++ for scope in [Scope::local(), profile] {+ let scoped = backend.for_scope(&scope).unwrap();+ assert!(scoped+ .documents()+ .get("flows.definitions", "missing")+ .await+ .unwrap()+ .is_none());+ assert!(scoped+ .documents()+ .get("cron.jobs", "missing")+ .await+ .unwrap()+ .is_none());+ }+}+#[test]fn an_agents_cron_database_lands_in_that_agents_scope() {let (dir, config) = workspace();