Skip to content

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

refactor(storage): improve scope handling across storage modules

Steven Enamakel58b980977199
diff --git a/crates/openhuman-core/src/cron/documents_port.rs b/crates/openhuman-core/src/cron/documents_port.rs
index f8d994fbb1..838eafcc21 100644
--- a/crates/openhuman-core/src/cron/documents_port.rs
+++ b/crates/openhuman-core/src/cron/documents_port.rs
@@ -30,10 +30,11 @@ use tinyflows_bus::schedule::CallbackAddress;
use tinystoragedrivers::StorageBackend;
use tinystoragedrivers_api::DocumentStore;
use tinystoragedrivers_types::{
- Capability, CollectionSpec, Filter, Precondition, Query, Scope, StorageError, WriteOp,
+ Capability, CollectionSpec, Filter, Precondition, Query, StorageError, WriteOp,
};
use crate::config::Config;
+use crate::storage::Scope;
use crate::modules::tinyflows as module;
/// Schedule-owned collections, including the v1 sources read and retired by
diff --git a/crates/openhuman-core/src/flows/catalog_storage.rs b/crates/openhuman-core/src/flows/catalog_storage.rs
index 93d0eb5af3..1b0b980da9 100644
--- a/crates/openhuman-core/src/flows/catalog_storage.rs
+++ b/crates/openhuman-core/src/flows/catalog_storage.rs
@@ -24,11 +24,12 @@ use tinyflows_bus::catalog::{
use tinystoragedrivers::StorageBackend;
use tinystoragedrivers_api::DocumentStore;
use tinystoragedrivers_types::{
- Capability, CollectionSpec, Filter, Page, Precondition, Query, Scope, StorageError, Versioned,
+ Capability, CollectionSpec, Filter, Page, Precondition, Query, StorageError, Versioned,
WriteOptions,
};
use crate::config::Config;
+use crate::storage::Scope;
use crate::core::runtime::DispatchCtx;
use crate::modules::tinyflows as module;
diff --git a/crates/openhuman-core/src/storage/mod.rs b/crates/openhuman-core/src/storage/mod.rs
index 429fead89e..dd064f035c 100644
--- a/crates/openhuman-core/src/storage/mod.rs
+++ b/crates/openhuman-core/src/storage/mod.rs
@@ -379,9 +379,11 @@ pub fn scope_from(
/// When the scope cannot be resolved ([`current_scope`]) or the backend
/// refuses it.
pub fn current_scoped() -> Result<Option<Storage>, StorageError> {
- installed()
- .map(|backend| backend.for_scope(&current_scope()?))
- .transpose()
+ let Some(backend) = installed() else {
+ return Ok(None);
+ };
+ let scope = current_scope()?;
+ backend.for_scope(&scope.to_storage_scope()).map(Some)
}
/// Runs `future` to completion from synchronous code, on one dedicated
diff --git a/crates/openhuman-core/src/storage/scope.rs b/crates/openhuman-core/src/storage/scope.rs
index 21800810f0..211ef35007 100644
--- a/crates/openhuman-core/src/storage/scope.rs
+++ b/crates/openhuman-core/src/storage/scope.rs
@@ -104,6 +104,12 @@ impl Scope {
self.0.as_str()
}
+ /// Clones the opaque driver scope for APIs that consume TSD's scope type.
+ #[must_use]
+ pub fn to_storage_scope(&self) -> tinystoragedrivers::Scope {
+ self.0.clone()
+ }
+
/// Whether this scope is the host's local operator tenant.
#[must_use]
pub fn is_local(&self) -> bool {
diff --git a/crates/openhuman-core/src/storage/secrets.rs b/crates/openhuman-core/src/storage/secrets.rs
index 64d2d3506d..4fa587a80f 100644
--- a/crates/openhuman-core/src/storage/secrets.rs
+++ b/crates/openhuman-core/src/storage/secrets.rs
@@ -54,7 +54,7 @@ pub fn current() -> Result<Option<DocumentSecrets>, StorageError> {
/// Secrets in `scoped` under `keys` (tests and explicit scopes).
pub fn over(scoped: &Storage, scope: Scope, keys: Arc<dyn KeyProvider>) -> DocumentSecrets {
- DocumentSecrets::new(scoped, scope, keys)
+ DocumentSecrets::new(scoped, scope.to_storage_scope(), keys)
}
/// Reads secret `name` from synchronous code.
diff --git a/crates/openhuman-core/src/storage/state_kv.rs b/crates/openhuman-core/src/storage/state_kv.rs
index 7065ae1ed9..27791c3ca6 100644
--- a/crates/openhuman-core/src/storage/state_kv.rs
+++ b/crates/openhuman-core/src/storage/state_kv.rs
@@ -27,12 +27,12 @@ use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use sha2::Digest;
-use tinystoragedrivers::{CollectionSpec, Cursor, ErrorKind, Precondition, Scope, StorageError};
+use tinystoragedrivers::{CollectionSpec, Cursor, ErrorKind, Precondition, StorageError};
use tinystoragedrivers_api::KvStore;
use super::documents::Repo;
use super::import_state;
-use super::Storage;
+use super::{Scope, Storage};
/// The `tsd.migrations` step kind of a state-file import.
const IMPORT_KIND: &str = "state_file";