Skip to content

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

feat(modules): add storage host module

Steven Enamakeleff64678d844
diff --git a/crates/openhuman-core/src/modules/host.rs b/crates/openhuman-core/src/modules/host.rs
index 6e3e7c5e52..a8f364b9b0 100644
--- a/crates/openhuman-core/src/modules/host.rs
+++ b/crates/openhuman-core/src/modules/host.rs
@@ -195,7 +195,7 @@ async fn build_runtime() -> tinybus::Result<ModuleRuntime> {
tracing::debug!("[modules] juice component off; MlHost not served");
}
super::site_memory_host::install(&connection).await?;
- super::storage_host::install(&connection).await?;
+ super::storage_host::install(&connection, &host).await?;
#[cfg(feature = "tinymemes")]
{
let memes_on = crate::core::runtime::context::CoreContext::current()
diff --git a/crates/openhuman-core/src/modules/mod.rs b/crates/openhuman-core/src/modules/mod.rs
index fb34ece6e3..b25e23cc0e 100644
--- a/crates/openhuman-core/src/modules/mod.rs
+++ b/crates/openhuman-core/src/modules/mod.rs
@@ -95,6 +95,8 @@ pub mod storage_grants;
#[cfg(feature = "modules")]
pub(crate) mod storage_host;
#[cfg(feature = "modules")]
+mod storage_host_linked;
+#[cfg(feature = "modules")]
pub mod tinybox;
#[cfg(feature = "modules")]
mod tokenjuice_host;
diff --git a/crates/openhuman-core/src/modules/storage_host.rs b/crates/openhuman-core/src/modules/storage_host.rs
index 5c8fbd5808..61807788df 100644
--- a/crates/openhuman-core/src/modules/storage_host.rs
+++ b/crates/openhuman-core/src/modules/storage_host.rs
@@ -403,9 +403,12 @@ impl BindError {
}
/// One storage object on the bus.
-struct ObjectService {
- object: Object,
- host: Arc<StorageHost>,
+pub(super) struct ObjectService {
+ pub(super) object: Object,
+ pub(super) host: Arc<StorageHost>,
+ /// Where the work runs when the object is served from a linked module's own
+ /// runtime: the host's, which the backend handles were opened on.
+ pub(super) runtime: Option<tokio::runtime::Handle>,
}
fn selectors(object: Object) -> &'static [&'static str] {
@@ -462,15 +465,31 @@ impl tinybus::Interface for ObjectService {
} else {
Admission::Private
};
- self.host
- .handle(
- self.object,
- member.as_str(),
- request_of(args)?,
- context.authenticated_sender(),
- admission,
- )
+ let request = request_of(args)?;
+ let sender = context.authenticated_sender().cloned();
+ let Some(runtime) = &self.runtime else {
+ return self
+ .host
+ .handle(
+ self.object,
+ member.as_str(),
+ request,
+ sender.as_ref(),
+ admission,
+ )
+ .await
+ .map_err(Into::into);
+ };
+ let host = Arc::clone(&self.host);
+ let object = self.object;
+ let selector = member.as_str().to_string();
+ runtime
+ .spawn(async move {
+ host.handle(object, &selector, request, sender.as_ref(), admission)
+ .await
+ })
.await
+ .map_err(|_| tinybus::Error::failed("storage call was cancelled"))?
.map_err(Into::into)
}
}
@@ -538,11 +557,20 @@ impl Environment for Live {
}
}
-pub(super) async fn install(connection: &tinybus::Connection) -> tinybus::Result<()> {
+/// The production host: the live directory, environment and audit log.
+pub(super) fn live_host(connection: &tinybus::Connection) -> Arc<StorageHost> {
let live = Arc::new(Live {
connection: connection.clone(),
});
- let host = Arc::new(StorageHost::new(live.clone(), live, Arc::new(LogAudit)));
+ Arc::new(StorageHost::new(live.clone(), live, Arc::new(LogAudit)))
+}
+
+/// Serves the four objects and claims the interface name on `connection`.
+pub(super) async fn serve_objects(
+ connection: &tinybus::Connection,
+ host: &Arc<StorageHost>,
+ runtime: Option<tokio::runtime::Handle>,
+) -> tinybus::Result<()> {
for object in [
Object::Documents,
Object::Streams,
@@ -555,7 +583,8 @@ pub(super) async fn install(connection: &tinybus::Connection) -> tinybus::Result
path,
ObjectService {
object,
- host: Arc::clone(&host),
+ host: Arc::clone(host),
+ runtime: runtime.clone(),
},
)
.await?;
@@ -563,6 +592,36 @@ pub(super) async fn install(connection: &tinybus::Connection) -> tinybus::Result
connection.request_name(STORAGE_INTERFACE).await
}
+/// Serves storage to modules.
+///
+/// Secrets travel only on tinybus' confidential route, and the broker delivers
+/// that route to an attested recipient alone: a loaded module whose artifact
+/// was verified, or code linked into this executable. The host's own client
+/// connection is neither, so serving from it would refuse every secret
+/// `NotAttested`. The objects are therefore served by a *linked* module
+/// ([`super::storage_host_linked`]). If that cannot be attached the objects
+/// are served from the host connection as before, with Secrets unreachable,
+/// and the failure is logged.
+pub(super) async fn install(
+ connection: &tinybus::Connection,
+ modules: &tinybus::module::ModuleHost,
+) -> tinybus::Result<()> {
+ let host = live_host(connection);
+ match super::storage_host_linked::attach(modules, Arc::clone(&host)) {
+ Ok(()) => {
+ tracing::debug!("[storage_host] serving storage from the attested linked module");
+ Ok(())
+ }
+ Err(error) => {
+ tracing::warn!(
+ %error,
+ "[storage_host] linked storage module unavailable; module secrets are refused"
+ );
+ serve_objects(connection, &host, None).await
+ }
+ }
+}
+
#[cfg(test)]
#[path = "storage_host_tests.rs"]
mod tests;