Skip to content

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

fix(storage): migrate legacy TinyJuice CCR blobs

Steven Enamakel325e19890e18
diff --git a/Cargo.lock b/Cargo.lock
index dea35546e3..0254744296 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -9573,7 +9573,6 @@ dependencies = [
"serde",
"serde_json",
"thiserror 2.0.20",
- "tinystoragedrivers-core",
"tinystoragedrivers-types",
]
diff --git a/crates/openhuman-core/Cargo.toml b/crates/openhuman-core/Cargo.toml
index 7f6f2379b1..d13672275b 100644
--- a/crates/openhuman-core/Cargo.toml
+++ b/crates/openhuman-core/Cargo.toml
@@ -421,7 +421,7 @@ tinyvoice-bus = { path = "../../vendor/tinyvoice/crates/tinyvoice-bus", optional
# no gate to hang off.
#
# After cloning: `git submodule update --init vendor/tinyjuice`.
-tinyjuice-bus = { path = "../../vendor/tinyjuice/crates/tinyjuice-bus", features = ["storage"] }
+tinyjuice-bus = { path = "../../vendor/tinyjuice/crates/tinyjuice-bus" }
tinyjuice-host = { path = "../../vendor/tinyjuice/crates/tinyjuice-host" }
# Transport-free vocabulary for the compiled TinyHosts provider module.
diff --git a/crates/openhuman-core/src/storage/schema.rs b/crates/openhuman-core/src/storage/schema.rs
index 50d4b0ea71..bbe0db2c06 100644
--- a/crates/openhuman-core/src/storage/schema.rs
+++ b/crates/openhuman-core/src/storage/schema.rs
@@ -11,13 +11,13 @@
//! gap, so a collision between two owners fails here, at boot and in
//! `scripts/ci/check-storage-schema.mjs`, never at a first write.
//!
-//! Module owners come from their `*-bus` contract crates (optional `storage` feature),
-//! never from the implementation libraries. Owners whose crate is gated off in a build are absent from its registry, as
-//! their data is.
+//! Module owners are composed by this host from their bus-level storage
+//! vocabulary. Owners whose crate is gated off in a build are absent from its
+//! registry, as their data is.
use std::sync::OnceLock;
-use tinystoragedrivers::schema::{Item, Registry, Schema, ScopeClass};
+use tinystoragedrivers::schema::{Item, Registry, Schema, ScopeClass, Step};
/// Every owner's schema that this build links.
pub fn owner_schemas() -> Vec<Schema> {
@@ -49,7 +49,7 @@ pub fn owner_schemas() -> Vec<Schema> {
schemas.push(tinychannels_bus::storage::storage_schema());
schemas.push(tinyconnectors_bus::storage::storage_schema());
schemas.push(tinybox_bus::storage::storage_schema());
- schemas.push(tinyjuice_bus::storage::storage_schema());
+ schemas.push(tinyjuice_storage_schema());
}
#[cfg(feature = "web3")]
schemas.push(tinywallet_bus::storage::storage_schema());
@@ -63,6 +63,37 @@ pub fn owner_schemas() -> Vec<Schema> {
schemas
}
+/// TinyJuice's storage owner contract composed into the host registry.
+#[cfg(feature = "modules")]
+fn tinyjuice_storage_schema() -> Schema {
+ use crate::storage::schema_support::owner;
+
+ let prefix = format!("{}/", tinyjuice_bus::storage::CCR_PREFIX);
+ Schema::new(owner("juice"))
+ .blobs(&prefix, ScopeClass::Module)
+ .collection(
+ tinyjuice_bus::storage::SAVINGS_COLLECTION,
+ 1,
+ ScopeClass::Module,
+ )
+ .step(
+ Step::blobs(
+ "ccr_prefix_v2",
+ tinyjuice_bus::storage::CCR_BLOB_PREFIX,
+ 1,
+ 2,
+ |key, content_type, bytes| {
+ Ok(tinyjuice_bus::storage::migrate_ccr_blob(
+ key,
+ content_type,
+ bytes,
+ ))
+ },
+ )
+ .source_prefix(tinyjuice_bus::storage::LEGACY_CCR_PREFIX),
+ )
+}
+
/// The registry composed from [`owner_schemas`].
///
/// # Errors
diff --git a/crates/openhuman-core/src/storage/schema_tests.rs b/crates/openhuman-core/src/storage/schema_tests.rs
index eec2daf870..1e3adc358a 100644
--- a/crates/openhuman-core/src/storage/schema_tests.rs
+++ b/crates/openhuman-core/src/storage/schema_tests.rs
@@ -40,3 +40,65 @@ fn module_items_are_the_owners_module_scoped_declarations() {
fn tinyjuice_ccr_blobs_stay_inside_the_juice_owner_namespace() {
assert_eq!(module_items("juice").blobs, ["juice/ccr/"]);
}
+
+#[cfg(feature = "modules")]
+#[tokio::test]
+async fn tinyjuice_legacy_ccr_blobs_migrate_with_the_owner_contract() {
+ use tinystoragedrivers::schema::{MigrateOptions, Registry};
+ use tinystoragedrivers::{MemoryStorage, Scope, StorageBackend};
+
+ let backend = MemoryStorage::new();
+ let scoped = backend.for_scope(&Scope::local()).unwrap();
+ let blobs = scoped.blobs();
+ blobs
+ .put(
+ "tinyjuice_ccr/0123456789abcdef",
+ b"original text".to_vec(),
+ Some("text/plain; charset=utf-8"),
+ )
+ .await
+ .unwrap();
+ blobs
+ .put("tinyjuice_ccr/fedcba9876543210", b"two".to_vec(), None)
+ .await
+ .unwrap();
+ blobs
+ .put("other/keep", b"keep".to_vec(), None)
+ .await
+ .unwrap();
+
+ let registry = Registry::compose([tinyjuice_storage_schema()]).unwrap();
+ let report = registry
+ .migrate(&scoped, &MigrateOptions::new())
+ .await
+ .unwrap();
+ assert_eq!(report.ran[0].written, 2);
+ assert!(blobs
+ .list(tinyjuice_bus::storage::LEGACY_CCR_PREFIX)
+ .await
+ .unwrap()
+ .is_empty());
+ let moved = blobs
+ .get("juice/ccr/0123456789abcdef")
+ .await
+ .unwrap()
+ .unwrap();
+ assert_eq!(moved.bytes, b"original text");
+ assert_eq!(
+ moved.meta.content_type.as_deref(),
+ Some("text/plain; charset=utf-8")
+ );
+ let moved = blobs
+ .get("juice/ccr/fedcba9876543210")
+ .await
+ .unwrap()
+ .unwrap();
+ assert_eq!(moved.meta.content_type, None);
+ assert!(blobs.get("other/keep").await.unwrap().is_some());
+
+ let again = registry
+ .migrate(&scoped, &MigrateOptions::new())
+ .await
+ .unwrap();
+ assert!(again.ran.is_empty());
+}
diff --git a/vendor/tinyjuice b/vendor/tinyjuice
index 88f7cb297e..d43ff81c82 160000
--- a/vendor/tinyjuice
+++ b/vendor/tinyjuice
@@ -1 +1 @@
-Subproject commit 88f7cb297e74b38a67e254aeb1c4630e949afcf3
+Subproject commit d43ff81c827ceff23eac3a6536eb7eb8a1c3319d