Skip to content

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

feat(storage): add storage grant schemas and host integration

Steven Enamakel659cb3a71a44
diff --git a/crates/openhuman-core/src/modules/storage_grant_schemas.rs b/crates/openhuman-core/src/modules/storage_grant_schemas.rs
index 28ea1f3edf..cec549a82f 100644
--- a/crates/openhuman-core/src/modules/storage_grant_schemas.rs
+++ b/crates/openhuman-core/src/modules/storage_grant_schemas.rs
@@ -35,9 +35,19 @@ struct Row {
queues: QueueManifestSource,
}
-/// Where a row's queue manifest comes from, read when the grant is built (at
+/// Where a row's queue grant comes from, read when the grant is built (at
/// bind), so a manifest the host loads from configuration is current.
-pub(super) type QueueManifestSource = Option<fn() -> Option<Arc<QueueManifest>>>;
+pub(super) type QueueManifestSource = Option<fn() -> Option<QueueGrant>>;
+
+/// The queues a module is granted: the manifest the host declares on its
+/// scope, and where they live.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub(crate) struct QueueGrant {
+ /// The queues the module may use; the storage server refuses any other.
+ pub manifest: Arc<QueueManifest>,
+ /// `Storage` keeps them in the scope's documents; a broker URL moves them.
+ pub backend: tinystoragedrivers::QueueConfig,
+}
const ROWS: [Row; 6] = [
Row {
@@ -109,6 +119,11 @@ pub(super) async fn migrate_imported(ctx: &crate::core::runtime::DispatchCtx, mo
/// The grant generated for `module_id`, or `None` for a module with no row.
pub(super) fn grant_for(module_id: &str) -> Option<StorageGrant> {
+ let queues = ROWS
+ .iter()
+ .find(|row| row.module == module_id)
+ .and_then(|row| row.queues)
+ .and_then(|source| source());
let row = ROWS.iter().find(|row| row.module == module_id)?;
let items = module_items(row.owner);
let mut secret_prefixes: Vec<String> = row.secrets.iter().map(|s| (*s).to_owned()).collect();
@@ -119,7 +134,8 @@ pub(super) fn grant_for(module_id: &str) -> Option<StorageGrant> {
blob_prefixes: items.blobs,
secret_prefixes,
writable: true,
- queues: row.queues.and_then(|source| source()),
+ queues: queues.as_ref().map(|grant| Arc::clone(&grant.manifest)),
+ queue_backend: queues.map(|grant| grant.backend),
})
}
diff --git a/crates/openhuman-core/src/modules/storage_grants.rs b/crates/openhuman-core/src/modules/storage_grants.rs
index df85c26bf6..70bef2c6dc 100644
--- a/crates/openhuman-core/src/modules/storage_grants.rs
+++ b/crates/openhuman-core/src/modules/storage_grants.rs
@@ -117,6 +117,10 @@ pub struct StorageGrant {
/// The queues the module may use, as a manifest the host declares on the
/// module's scope when it binds; `None` grants no `Queues` object.
pub queues: Option<Arc<QueueManifest>>,
+ /// Where the granted queues live: `None` (or `QueueConfig::Storage`) keeps
+ /// them in the module scope's own documents; a broker URL moves them
+ /// there when the host binds. Meaningless without [`Self::queues`].
+ pub queue_backend: Option<tinystoragedrivers::QueueConfig>,
}
/// Collection names no grant may hold: the encrypted secret documents and the
diff --git a/crates/openhuman-core/src/modules/storage_host.rs b/crates/openhuman-core/src/modules/storage_host.rs
index cb6939173b..9ce51c97ec 100644
--- a/crates/openhuman-core/src/modules/storage_host.rs
+++ b/crates/openhuman-core/src/modules/storage_host.rs
@@ -412,6 +412,25 @@ impl StorageHost {
.await
.map_err(|_| BindError::Backend(StorageKind::Backend))?;
}
+ // A broker queue backend replaces the scope's queue port before the
+ // server takes it; the default keeps the queues in the scope's documents.
+ let storage = match (&grant.queues, &grant.queue_backend) {
+ (Some(_), Some(backend)) if *backend != tinystoragedrivers::QueueConfig::Storage => {
+ tinystoragedrivers::open_queues(backend, storage, None)
+ .await
+ .map_err(|error| {
+ tracing::warn!(
+ target: "openhuman::storage_host",
+ module,
+ backend = %backend,
+ %error,
+ "[storage_host] could not open the granted queue backend"
+ );
+ BindError::Backend(StorageKind::Backend)
+ })?
+ }
+ _ => storage,
+ };
let mut server = StorageServer::new(storage.clone());
if let Some(manifest) = &grant.queues {
// The queue port of a document backend keeps its messages in the