Skip to content

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

chore(storage): tidy imports, types, and atomic helpers

Steven Enamakel196eea40ff23
diff --git a/crates/openhuman-core/src/modules/storage_host_invocation.rs b/crates/openhuman-core/src/modules/storage_host_invocation.rs
index c0346da2a4..39d93d1c2f 100644
--- a/crates/openhuman-core/src/modules/storage_host_invocation.rs
+++ b/crates/openhuman-core/src/modules/storage_host_invocation.rs
@@ -64,7 +64,7 @@ impl InvocationStorageBinding {
.unique_name()
.ok_or_else(|| anyhow::anyhow!("module runtime connection has no unique bus name"))?;
let serial = NEXT_INVOCATION
- .fetch_update(Ordering::Relaxed, Ordering::Relaxed, |next| {
+ .try_update(Ordering::Relaxed, Ordering::Relaxed, |next| {
next.checked_add(1)
})
.map_err(|_| anyhow::anyhow!("invocation storage address space is exhausted"))?;
diff --git a/crates/openhuman-core/src/modules/storage_import_tinymcp.rs b/crates/openhuman-core/src/modules/storage_import_tinymcp.rs
index 70d9e72275..93a4e418c8 100644
--- a/crates/openhuman-core/src/modules/storage_import_tinymcp.rs
+++ b/crates/openhuman-core/src/modules/storage_import_tinymcp.rs
@@ -148,7 +148,7 @@ async fn import_into(
.for_scope(scope)
.map_err(|error| anyhow!("open the module scope: {:?}", error.kind()))?;
let markers = crate::storage::documents::Repo::on(
- &backend,
+ backend,
scope,
"storage::import",
crate::storage::import_state::collection_specs,
@@ -174,7 +174,7 @@ async fn import_into(
|condition| {
let claimed_markers = markers.conditioned(condition)?;
let claimed_backend = crate::storage::import_state::backend_with_condition(
- Arc::clone(&backend),
+ Arc::clone(backend),
condition.clone(),
);
let claimed_scoped = claimed_backend
diff --git a/crates/openhuman-core/src/profiles/host_cron_cap_tests.rs b/crates/openhuman-core/src/profiles/host_cron_cap_tests.rs
index f764398798..23a033c891 100644
--- a/crates/openhuman-core/src/profiles/host_cron_cap_tests.rs
+++ b/crates/openhuman-core/src/profiles/host_cron_cap_tests.rs
@@ -1,4 +1,3 @@
-use super::*;
#[cfg(feature = "storage-sqlite")]
use crate::storage::test_support::sqlite_backend;
#[cfg(feature = "storage-sqlite")]
diff --git a/crates/openhuman-core/src/security/devices/storage_schema.rs b/crates/openhuman-core/src/security/devices/storage_schema.rs
index 51eafed423..8f7a9be36a 100644
--- a/crates/openhuman-core/src/security/devices/storage_schema.rs
+++ b/crates/openhuman-core/src/security/devices/storage_schema.rs
@@ -19,7 +19,7 @@ pub(super) const DEVICES: &str = "devices.paired";
/// The v1 name, still written by the legacy `devices.db` importer.
pub(super) const LEGACY_DEVICES: &str = "paired_devices";
/// The body version of [`DEVICES`].
-
+///
/// Converts legacy paired-device rows into the current owner shape.
pub(crate) fn upgrade_records(
records: Vec<crate::storage::import::Record>,
diff --git a/crates/openhuman-core/src/storage/import/layout_db_tests.rs b/crates/openhuman-core/src/storage/import/layout_db_tests.rs
index 2ca8d863af..8e68aeca44 100644
--- a/crates/openhuman-core/src/storage/import/layout_db_tests.rs
+++ b/crates/openhuman-core/src/storage/import/layout_db_tests.rs
@@ -1,6 +1,9 @@
use super::*;
+#[cfg(feature = "storage-sqlite")]
use crate::storage::layout::test_fixtures::{fixture_docs, v1_profile};
-use crate::storage::layout::{legacy, Target};
+#[cfg(feature = "storage-sqlite")]
+use crate::storage::layout::legacy;
+use crate::storage::layout::Target;
use tempfile::TempDir;
#[test]
diff --git a/crates/openhuman-core/src/storage/import/layout_status.rs b/crates/openhuman-core/src/storage/import/layout_status.rs
index 9c27c94956..8960c1ccdb 100644
--- a/crates/openhuman-core/src/storage/import/layout_status.rs
+++ b/crates/openhuman-core/src/storage/import/layout_status.rs
@@ -20,10 +20,12 @@ struct LegacyProgress {
done: bool,
}
+type MigrationProgress = (Vec<(String, u32)>, Option<i64>);
+
/// Reads completed owner versions and the last completion timestamp from a
/// historical Tiny Storage Drivers database without opening it through the
/// current backend or modifying the source file.
-pub(crate) fn read(path: &Path) -> Result<(Vec<(String, u32)>, Option<i64>)> {
+pub(crate) fn read(path: &Path) -> Result<MigrationProgress> {
let snapshot = Snapshot::of(path, "layout-status/source.db")?;
let connection = rusqlite::Connection::open_with_flags(
snapshot.db(),
diff --git a/crates/openhuman-core/src/storage/import/tinyflows_reader/checkpoint_reader.rs b/crates/openhuman-core/src/storage/import/tinyflows_reader/checkpoint_reader.rs
index b07e68c3a7..b8c7247f33 100644
--- a/crates/openhuman-core/src/storage/import/tinyflows_reader/checkpoint_reader.rs
+++ b/crates/openhuman-core/src/storage/import/tinyflows_reader/checkpoint_reader.rs
@@ -346,7 +346,7 @@ fn read_bounded_line<R: BufRead>(reader: &mut R) -> io::Result<Option<(Vec<u8>,
saw_bytes = true;
let newline = available.iter().position(|byte| *byte == b'\n');
let consumed = newline.map_or(available.len(), |index| index + 1);
- let content_len = newline.map_or(consumed, |index| index);
+ let content_len = newline.unwrap_or(consumed);
if !oversized {
if line.len() + content_len > MAX_IMPORT_RECORD_PAYLOAD_BYTES {
oversized = true;
diff --git a/crates/openhuman-core/src/storage/import/tinyflows_reader/flow_reader.rs b/crates/openhuman-core/src/storage/import/tinyflows_reader/flow_reader.rs
index 3989529f1c..41ff3b8105 100644
--- a/crates/openhuman-core/src/storage/import/tinyflows_reader/flow_reader.rs
+++ b/crates/openhuman-core/src/storage/import/tinyflows_reader/flow_reader.rs
@@ -68,7 +68,7 @@ where
if tables.contains("flow_revisions") {
page_rows(&db, "flow revisions", "SELECT id,flow_id,graph_json,name,require_approval,created_at FROM flow_revisions ORDER BY created_at,id LIMIT ?1 OFFSET ?2", |row| {
Ok(LegacyRevisionRecord { id: row.get(0)?, flow_id: row.get(1)?, graph_json: row.get(2)?, name: row.get(3)?, require_approval: row.get::<_, i64>(4)? != 0, created_at: row.get(5)? })
- }, |row| LegacyImportRecord::Revision(row), &mut batches, &mut send).await?;
+ }, LegacyImportRecord::Revision, &mut batches, &mut send).await?;
}
if tables.contains("flow_runs") {
let columns = db.columns("flow_runs").await?;
@@ -94,7 +94,7 @@ where
graph_hash: row.get(9)?,
})
},
- |row| LegacyImportRecord::Run(row),
+ LegacyImportRecord::Run,
&mut batches,
&mut send,
)
@@ -103,12 +103,12 @@ where
if tables.contains("flow_state") {
page_rows(&db, "flow state", "SELECT namespace,key,value FROM flow_state ORDER BY namespace,key LIMIT ?1 OFFSET ?2", |row| {
Ok(LegacyStateRecord { namespace: row.get(0)?, key: row.get(1)?, value_json: row.get(2)? })
- }, |row| LegacyImportRecord::State(row), &mut batches, &mut send).await?;
+ }, LegacyImportRecord::State, &mut batches, &mut send).await?;
}
if tables.contains("flow_suggestions") {
page_rows(&db, "flow suggestions", "SELECT id,title,one_liner,rationale,trigger_hint,steps_json,connections_json,slugs_json,build_prompt,confidence,status,created_at,source_run_id FROM flow_suggestions ORDER BY created_at,id LIMIT ?1 OFFSET ?2", |row| {
Ok(LegacySuggestionRecord { id: row.get(0)?, title: row.get(1)?, one_liner: row.get(2)?, rationale: row.get(3)?, trigger_hint: row.get(4)?, steps_json: row.get(5)?, connections_json: row.get(6)?, slugs_json: row.get(7)?, build_prompt: row.get(8)?, confidence: row.get(9)?, status: row.get(10)?, created_at: row.get(11)?, source_run_id: row.get(12)? })
- }, |row| LegacyImportRecord::Suggestion(row), &mut batches, &mut send).await?;
+ }, LegacyImportRecord::Suggestion, &mut batches, &mut send).await?;
}
}
read_drafts(&dir.join("drafts"), &mut batches, &mut send).await?;
diff --git a/crates/openhuman-core/src/storage/lease_documents.rs b/crates/openhuman-core/src/storage/lease_documents.rs
index cdc9a432df..77cff3a9a6 100644
--- a/crates/openhuman-core/src/storage/lease_documents.rs
+++ b/crates/openhuman-core/src/storage/lease_documents.rs
@@ -421,10 +421,10 @@ impl LeaseStore for DocumentLeases {
)))
}
Err(error) if error.kind() == ErrorKind::NotFound => return Ok(None),
- Err(error) => return Err(LeaseError::Storage(error.into())),
+ Err(error) => return Err(LeaseError::Storage(error)),
}
}
- Err(error) => return Err(LeaseError::Storage(error.into())),
+ Err(error) => return Err(LeaseError::Storage(error)),
}
self.read(key)
.await
diff --git a/crates/openhuman-core/src/storage/local.rs b/crates/openhuman-core/src/storage/local.rs
index dcb01f8494..4d04fe5b0c 100644
--- a/crates/openhuman-core/src/storage/local.rs
+++ b/crates/openhuman-core/src/storage/local.rs
@@ -132,7 +132,7 @@ fn workspace_backend(workspace_dir: &Path) -> WorkspaceBackend {
)
}
-async fn open_default_backend(workspace_dir: PathBuf) -> Result<Arc<dyn StorageBackend>> {
+async fn open_default_backend(_workspace_dir: PathBuf) -> Result<Arc<dyn StorageBackend>> {
#[cfg(test)]
await_test_backend_open_gate().await;
@@ -141,17 +141,17 @@ async fn open_default_backend(workspace_dir: PathBuf) -> Result<Arc<dyn StorageB
let persistent_url = TEST_WORKSPACE_URLS
.lock()
.unwrap_or_else(PoisonError::into_inner)
- .get(&workspace_dir)
+ .get(&_workspace_dir)
.cloned();
if let Some(url) = persistent_url {
- super::config::prepare_default_dir(&workspace_dir).with_context(|| {
+ super::config::prepare_default_dir(&_workspace_dir).with_context(|| {
format!(
"create the storage directory for {}",
- workspace_dir.display()
+ _workspace_dir.display()
)
})?;
return super::open(&url).await.with_context(|| {
- format!("open the default storage for {}", workspace_dir.display())
+ format!("open the default storage for {}", _workspace_dir.display())
});
}
}
@@ -161,26 +161,26 @@ async fn open_default_backend(workspace_dir: PathBuf) -> Result<Arc<dyn StorageB
let backend: Arc<dyn StorageBackend> =
Arc::new(tinystoragedrivers_testkit::MemoryBackend::new());
super::boot::prepare_and_migrate(&backend).await?;
- return Ok(super::fenced_backend::wrap(backend));
+ Ok(super::fenced_backend::wrap(backend))
}
#[cfg(not(test))]
{
- let url = super::config::default_url(&workspace_dir);
- super::config::prepare_default_dir(&workspace_dir).with_context(|| {
+ let url = super::config::default_url(&_workspace_dir);
+ super::config::prepare_default_dir(&_workspace_dir).with_context(|| {
format!(
"create the storage directory for {}",
- workspace_dir.display()
+ _workspace_dir.display()
)
})?;
tracing::debug!(
target: "openhuman::storage",
- workspace = %workspace_dir.display(),
+ workspace = %_workspace_dir.display(),
"[storage::local] opening the workspace default backend (none installed)"
);
super::open(&url)
.await
- .with_context(|| format!("open the default storage for {}", workspace_dir.display()))
+ .with_context(|| format!("open the default storage for {}", _workspace_dir.display()))
}
}
diff --git a/crates/openhuman-core/src/storage/mod.rs b/crates/openhuman-core/src/storage/mod.rs
index 4b186e7905..f994ba3d12 100644
--- a/crates/openhuman-core/src/storage/mod.rs
+++ b/crates/openhuman-core/src/storage/mod.rs
@@ -117,8 +117,10 @@ impl<T: tinystoragedrivers_api::DocumentStoreExt + ?Sized> DocumentStoreExt for
/// asynchronous storage ports. Keeping it on its own thread also permits a
/// synchronous facade to be called while the caller is on a current-thread
/// Tokio runtime.
+type StorageTask = Box<dyn FnOnce(&tokio::runtime::Runtime) + Send>;
+
struct Blocking {
- tasks: mpsc::Sender<Box<dyn FnOnce(&tokio::runtime::Runtime) + Send>>,
+ tasks: mpsc::Sender<StorageTask>,
}
thread_local! {
@@ -127,7 +129,7 @@ thread_local! {
impl Blocking {
fn new() -> anyhow::Result<Self> {
- let (tasks, receiver) = mpsc::channel::<Box<dyn FnOnce(&tokio::runtime::Runtime) + Send>>();
+ let (tasks, receiver) = mpsc::channel::<StorageTask>();
let (started, ready) = mpsc::sync_channel(1);
std::thread::Builder::new()
.name("openhuman-storage".to_owned())
diff --git a/crates/openhuman-core/src/storage/rebind_tests.rs b/crates/openhuman-core/src/storage/rebind_tests.rs
index 871619c7c2..a86d7978e5 100644
--- a/crates/openhuman-core/src/storage/rebind_tests.rs
+++ b/crates/openhuman-core/src/storage/rebind_tests.rs
@@ -1,6 +1,7 @@
use super::*;
#[cfg(feature = "legacy-import")]
use crate::storage::import::Outcome;
+#[cfg(feature = "storage-sqlite")]
use crate::storage::{CollectionSpec, Precondition, Scope};
use std::sync::Mutex;
use tempfile::TempDir;
diff --git a/crates/openhuman-core/src/storage/scope_move_boot.rs b/crates/openhuman-core/src/storage/scope_move_boot.rs
index 811b0294a5..bf3bc46d61 100644
--- a/crates/openhuman-core/src/storage/scope_move_boot.rs
+++ b/crates/openhuman-core/src/storage/scope_move_boot.rs
@@ -241,16 +241,19 @@ fn import_inventory(
}
}
+#[cfg(feature = "legacy-import")]
+type BackendForScope = (
+ Arc<dyn StorageBackend>,
+ Option<Arc<crate::profiles::host::Profile>>,
+);
+
#[cfg(feature = "legacy-import")]
fn backend_for_target_scope(
backend: &Arc<dyn StorageBackend>,
target_scope: &Scope,
known: &Known,
config: &crate::config::Config,
-) -> anyhow::Result<(
- Arc<dyn StorageBackend>,
- Option<Arc<crate::profiles::host::Profile>>,
-)> {
+) -> anyhow::Result<BackendForScope> {
if target_scope.is_local() || target_scope.is_cluster() {
return Ok((Arc::clone(backend), None));
}
diff --git a/crates/openhuman-core/src/threads/store/legacy_import_tests.rs b/crates/openhuman-core/src/threads/store/legacy_import_tests.rs
index 0e6f1174b9..197e288b63 100644
--- a/crates/openhuman-core/src/threads/store/legacy_import_tests.rs
+++ b/crates/openhuman-core/src/threads/store/legacy_import_tests.rs
@@ -1,8 +1,11 @@
use super::*;
-use sha2::Digest;
use std::path::Path;
+#[cfg(feature = "storage-sqlite")]
use std::sync::Arc;
+#[cfg(feature = "storage-sqlite")]
use tinystoragedrivers::{CollectionSpec, Precondition, WriteOptions};
+#[cfg(feature = "storage-sqlite")]
+use sha2::Digest;
fn hex(id: &str) -> String {
id.bytes().map(|b| format!("{b:02x}")).collect()