The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(storage): host stores on the v2 schema, tsd.migrations markers and tsd Leases claims
Steven Enamakel2d3e22636e4f
diff --git a/crates/openhuman-core/src/agent/artifacts/mod.rs b/crates/openhuman-core/src/agent/artifacts/mod.rsindex 5da709ed64..a694f06549 100644--- a/crates/openhuman-core/src/agent/artifacts/mod.rs+++ b/crates/openhuman-core/src/agent/artifacts/mod.rs@@ -4,8 +4,8 @@ pub mod ops;pub mod preview;pub mod production;pub mod schemas;-pub mod store;mod storage_schema;+pub mod store;mod store_documents;pub use storage_schema::storage_schema;pub mod tiny_store;diff --git a/crates/openhuman-core/src/agent/artifacts/storage_schema.rs b/crates/openhuman-core/src/agent/artifacts/storage_schema.rsindex 829e59cbfe..d4d189bb43 100644--- a/crates/openhuman-core/src/agent/artifacts/storage_schema.rs+++ b/crates/openhuman-core/src/agent/artifacts/storage_schema.rs@@ -61,7 +61,10 @@ pub(super) fn meta_to_body(meta: &ArtifactMeta) -> anyhow::Result<Value> {let mut doc = serde_json::to_value(meta)?;if let Some(fields) = doc.as_object_mut() {fields.remove("created_at");- fields.insert("created_ms".into(), meta.created_at.timestamp_millis().into());+ fields.insert(+ "created_ms".into(),+ meta.created_at.timestamp_millis().into(),+ );}Ok(doc)}@@ -95,9 +98,7 @@ pub(super) fn args_body(args: &Value) -> Value {/// The arguments a stored body holds.pub(super) fn args_of_body(body: &Value) -> Value {match body.as_object() {- Some(fields) if fields.len() == 1 && fields.contains_key("_args") => {- body["_args"].clone()- }+ Some(fields) if fields.len() == 1 && fields.contains_key("_args") => body["_args"].clone(),_ => body.clone(),}}diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/mod.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/mod.rsindex 0c2b1851e2..48f34a86ae 100644--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/mod.rs+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/mod.rs@@ -1,6 +1,6 @@mod ops;-mod store;mod storage_schema;+mod store;pub use storage_schema::storage_schema;mod store_documents;mod types;diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/storage_schema.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/storage_schema.rsindex 489cb258fc..043c668435 100644--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/storage_schema.rs+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/storage_schema.rs@@ -80,8 +80,7 @@ fn sessions_v2(batch: Vec<SourceRecord>) -> Result<Vec<TargetRecord>> {.get("subagentSessionId").and_then(Value::as_str).unwrap_or(&record.id);- Ok(TargetRecord::new(SESSIONS, key_of(id)?, Value::Object(body))- .created_ms(created))+ Ok(TargetRecord::new(SESSIONS, key_of(id)?, Value::Object(body)).created_ms(created))}).collect()}diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents.rsindex 9f106726e7..cbcab9fb6a 100644--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents.rs+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents.rs@@ -26,8 +26,8 @@use anyhow::Result;use serde::{Deserialize, Serialize};use serde_json::Value;-use tinystoragedrivers::{CollectionSpec, Query, Sort};use tinyagents_session::transcript::TranscriptMessage;+use tinystoragedrivers::{CollectionSpec, Query, Sort};use super::storage_schema::{spec, SESSIONS};use super::types::{DurableSubagentSession, DurableSubagentStatus};diff --git a/crates/openhuman-core/src/config/schema/load/source/document.rs b/crates/openhuman-core/src/config/schema/load/source/document.rsindex 5923cf6dd9..6726885f6b 100644--- a/crates/openhuman-core/src/config/schema/load/source/document.rs+++ b/crates/openhuman-core/src/config/schema/load/source/document.rs@@ -11,8 +11,8 @@ use tinystoragedrivers::{CollectionSpec, DocumentStore, Precondition};use super::{apply_bootstrap, strip_bootstrap, ConfigRead, ConfigSource, FileConfigSource};use crate::storage::Scope;-pub(crate) use super::storage_schema::CONFIG_COLLECTION;use super::storage_schema::document_id;+pub(crate) use super::storage_schema::CONFIG_COLLECTION;/// The document field holding the encrypted TOML body (`enc2:` hex).const BODY_FIELD: &str = "toml_enc";diff --git a/crates/openhuman-core/src/config/schema/load/source/mod_tests.rs b/crates/openhuman-core/src/config/schema/load/source/mod_tests.rsindex 66c20314c2..1211307057 100644--- a/crates/openhuman-core/src/config/schema/load/source/mod_tests.rs+++ b/crates/openhuman-core/src/config/schema/load/source/mod_tests.rs@@ -120,7 +120,11 @@ async fn a_document_holds_no_plaintext_and_no_bootstrap_tables() {.unwrap();let docs = Arc::clone(scoped(&storage, "alice").documents());- let stored = docs.get("config.documents", "alice").await.unwrap().unwrap();+ let stored = docs+ .get("config.documents", "alice")+ .await+ .unwrap()+ .unwrap();let raw = serde_json::to_string(&stored.doc).unwrap();assert!(raw.contains("enc2:"), "{raw}");for leaked in ["sk-very-secret", "mongodb", "default_model", "[storage]"] {@@ -146,7 +150,12 @@ async fn a_document_does_not_decrypt_under_another_scope_or_master_key() {// Another scope's data key cannot open alice's ciphertext even when the// sealed value is copied across (per-scope key derivation).let docs = Arc::clone(scoped(&storage, "alice").documents());- let sealed = docs.get("config.documents", "alice").await.unwrap().unwrap().doc;+ let sealed = docs+ .get("config.documents", "alice")+ .await+ .unwrap()+ .unwrap()+ .doc;let bob_docs = Arc::clone(scoped(&storage, "bob").documents());bob_docs.put(@@ -517,7 +526,10 @@ async fn a_document_save_refuses_process_key_secrets_it_cannot_open() {.await.unwrap();assert!(- docs.get("config.documents", "tenant-a").await.unwrap().is_none(),+ docs.get("config.documents", "tenant-a")+ .await+ .unwrap()+ .is_none(),"nothing was written over the shared document");}diff --git a/crates/openhuman-core/src/config/schema/load/source/storage_schema.rs b/crates/openhuman-core/src/config/schema/load/source/storage_schema.rsindex 594c1bb85d..b6f5304342 100644--- a/crates/openhuman-core/src/config/schema/load/source/storage_schema.rs+++ b/crates/openhuman-core/src/config/schema/load/source/storage_schema.rs@@ -36,7 +36,9 @@ pub fn storage_schema() -> Schema {/// # Errors////// When `scope` is empty.-pub(crate) fn document_id(scope: &str) -> std::result::Result<String, tinystoragedrivers::StorageError> {+pub(crate) fn document_id(+ scope: &str,+) -> std::result::Result<String, tinystoragedrivers::StorageError> {key_of(scope)}diff --git a/crates/openhuman-core/src/desktop/notifications/mod.rs b/crates/openhuman-core/src/desktop/notifications/mod.rsindex f88f5c23a0..44f190b831 100644--- a/crates/openhuman-core/src/desktop/notifications/mod.rs+++ b/crates/openhuman-core/src/desktop/notifications/mod.rs@@ -25,8 +25,8 @@pub mod bus;pub mod rpc;pub mod schemas;-pub mod store;mod storage_schema;+pub mod store;mod store_documents;mod store_import;pub(crate) use storage_schema::storage_schema;diff --git a/crates/openhuman-core/src/desktop/notifications/storage_schema.rs b/crates/openhuman-core/src/desktop/notifications/storage_schema.rsindex b0277e8375..d6a68178f6 100644--- a/crates/openhuman-core/src/desktop/notifications/storage_schema.rs+++ b/crates/openhuman-core/src/desktop/notifications/storage_schema.rs@@ -160,7 +160,10 @@ fn core_v2(batch: Vec<SourceRecord>) -> Result<Vec<TargetRecord>> {.set("workspace", workspace).copy(old, "payload").copy(old, "timestamp_ms")- .set("read", old.get("read").and_then(Value::as_bool).unwrap_or(false))+ .set(+ "read",+ old.get("read").and_then(Value::as_bool).unwrap_or(false),+ ).build();Some(TargetRecord::new(CORE, core_id(workspace, event), body).created_ms(created_ms))})diff --git a/crates/openhuman-core/src/desktop/notifications/store_documents.rs b/crates/openhuman-core/src/desktop/notifications/store_documents.rsindex 4f5866a4f5..59b3eb2d92 100644--- a/crates/openhuman-core/src/desktop/notifications/store_documents.rs+++ b/crates/openhuman-core/src/desktop/notifications/store_documents.rs@@ -33,9 +33,7 @@ use anyhow::{Context, Result};use chrono::{DateTime, Duration, Utc};use serde_json::{json, Map, Value};use sha2::{Digest, Sha256};-use tinystoragedrivers::{- CollectionSpec, ErrorKind, Filter, Precondition, Query, Sort, Versioned,-};+use tinystoragedrivers::{CollectionSpec, ErrorKind, Filter, Precondition, Query, Sort, Versioned};use super::types::{CoreNotificationEvent, IntegrationNotification, NotificationSettings, NotificationStats,diff --git a/crates/openhuman-core/src/desktop/notifications/store_import.rs b/crates/openhuman-core/src/desktop/notifications/store_import.rsindex 7e18d2d2dd..053f409650 100644--- a/crates/openhuman-core/src/desktop/notifications/store_import.rs+++ b/crates/openhuman-core/src/desktop/notifications/store_import.rs@@ -23,8 +23,8 @@ use serde_json::json;mod store_rows;use store_rows::rows_to_notifications;-use super::store_documents::LOCAL_WORKSPACE;use super::storage_schema::{LEGACY_CORE, LEGACY_NOTIFICATIONS, LEGACY_SETTINGS};+use super::store_documents::LOCAL_WORKSPACE;use super::types::IntegrationNotification;use crate::config::Config;use crate::storage::import::{table_exists, ImportDoc};diff --git a/crates/openhuman-core/src/integrations/composio/file_store_documents.rs b/crates/openhuman-core/src/integrations/composio/file_store_documents.rsindex 3e9d8c08e1..cb23de2ecc 100644--- a/crates/openhuman-core/src/integrations/composio/file_store_documents.rs+++ b/crates/openhuman-core/src/integrations/composio/file_store_documents.rs@@ -29,8 +29,7 @@ use serde::de::DeserializeOwned;use serde::{Deserialize, Serialize};use serde_json::Value;use tinystoragedrivers::{- CollectionSpec, DocumentStore, DocumentStoreExt, Key, Kv, ScopedStorage,- StorageError,+ CollectionSpec, DocumentStore, DocumentStoreExt, Key, Kv, ScopedStorage, StorageError,};use crate::storage::documents::Repo;@@ -122,7 +121,10 @@ impl Docs {{let name = name.to_string();self.0.run(|docs| async move {- let repo = tinystoragedrivers::Repo::<KvEntry>::new(&docs, tinystoragedrivers::primitives::KV)?;+ let repo = tinystoragedrivers::Repo::<KvEntry>::new(+ &docs,+ tinystoragedrivers::primitives::KV,+ )?;let mut result = None;repo.update(&kv_id(&name)?, |current| {let mut value: T = match ¤t {@@ -195,9 +197,8 @@ impl Docs {let name = name.to_string();let value = serde_json::to_value(value)?;log::debug!("[composio:store] document save id={name}");- self.0.run(|docs| async move {- kv(&docs)?.put(&name, &value).await.map(|_| ())- })+ self.0+ .run(|docs| async move { kv(&docs)?.put(&name, &value).await.map(|_| ()) })}}@@ -219,8 +220,14 @@ fn import_step(name: &str) -> String {pub(crate) async fn migrate_legacy_state(scoped: &ScopedStorage) -> Result<usize, StorageError> {use tinystoragedrivers::Capability;let docs = scoped.documents();- if !docs.capabilities().contains(Capability::CollectionEnumeration)- || !docs.collections("").await?.iter().any(|name| name == LEGACY_STATE)+ if !docs+ .capabilities()+ .contains(Capability::CollectionEnumeration)+ || !docs+ .collections("")+ .await?+ .iter()+ .any(|name| name == LEGACY_STATE){return Ok(0);}diff --git a/crates/openhuman-core/src/integrations/composio/file_store_documents_tests.rs b/crates/openhuman-core/src/integrations/composio/file_store_documents_tests.rsindex 66d0abc9ed..b281fc0513 100644--- a/crates/openhuman-core/src/integrations/composio/file_store_documents_tests.rs+++ b/crates/openhuman-core/src/integrations/composio/file_store_documents_tests.rs@@ -113,3 +113,91 @@ fn concurrent_updates_do_not_lose_each_other() {let loaded: BTreeMap<String, u32> = docs.load(path()).unwrap();assert_eq!(loaded.len(), 8);}++#[test]+fn values_are_tsd_kv_entries_that_kv_itself_reads_and_updates_in_place() {+ let storage = MemoryStorage::new();+ let docs = docs_in(&storage, "local");+ let mut value = BTreeMap::new();+ value.insert("gmail".to_string(), 1u32);+ docs.save(path(), &value).unwrap();++ // `update` writes the same document `Kv` reads, so the two never drift.+ let bumped = docs+ .update::<BTreeMap<String, u32>, u32>(path(), |map| {+ let next = map.get("gmail").copied().unwrap_or(0) + 1;+ map.insert("gmail".into(), next);+ (next, true)+ })+ .unwrap();+ assert_eq!(bumped, 2);++ let scoped = storage.for_scope(&Scope::new("local").unwrap()).unwrap();+ let kv = tinystoragedrivers::Kv::ns(scoped.documents(), "composio", "state").unwrap();+ let read: Option<BTreeMap<String, u32>> =+ crate::storage::block_on(async move { kv.get(path()).await }).unwrap();+ assert_eq!(read.unwrap()["gmail"], 2);+}++#[test]+fn an_unchanged_update_writes_nothing_and_returns_its_result() {+ let docs = docs_in(&MemoryStorage::new(), "local");+ let seen = docs+ .update::<BTreeMap<String, u32>, usize>(path(), |map| (map.len(), false))+ .unwrap();+ assert_eq!(seen, 0);+ let loaded: BTreeMap<String, u32> = docs.load(path()).unwrap();+ assert!(loaded.is_empty());+}++#[test]+fn the_import_marker_is_a_migrations_entry_and_stops_a_second_import() {+ let docs = docs_in(&MemoryStorage::new(), "local");+ assert!(!docs.legacy_imported(path()).unwrap());+ assert!(docs+ .import_if_absent(path(), serde_json::json!({ "gmail": 5 }))+ .unwrap());+ assert!(docs.legacy_imported(path()).unwrap());+ let loaded: BTreeMap<String, u32> = docs.load(path()).unwrap();+ assert_eq!(loaded["gmail"], 5);+}++#[tokio::test]+async fn v1_state_documents_move_into_kv_without_replacing_a_newer_value() {+ use tinystoragedrivers::{DocumentStoreExt, Precondition};+ let storage = MemoryStorage::new();+ let scoped = storage.for_scope(&Scope::new("local").unwrap()).unwrap();+ let raw = scoped.documents();+ raw.ensure_collection(&tinystoragedrivers::CollectionSpec::new("composio_state"))+ .await+ .unwrap();+ for (name, value) in [("a.json", 1), ("b.json", 2)] {+ raw.put(+ "composio_state",+ name,+ serde_json::json!({ "value": { "n": value } }),+ Precondition::Absent,+ )+ .await+ .unwrap();+ }+ let kv = tinystoragedrivers::Kv::ns(raw, "composio", "state").unwrap();+ for spec in tinystoragedrivers::primitives::collection_specs() {+ raw.ensure_collection(&spec).await.unwrap();+ }+ kv.put("b.json", &serde_json::json!({ "n": 99 }))+ .await+ .unwrap();++ assert_eq!(migrate_legacy_state(&scoped).await.unwrap(), 1);+ assert_eq!(+ kv.get::<serde_json::Value>("a.json").await.unwrap(),+ Some(serde_json::json!({ "n": 1 }))+ );+ assert_eq!(+ kv.get::<serde_json::Value>("b.json").await.unwrap(),+ Some(serde_json::json!({ "n": 99 })),+ "a value already in kv is newer"+ );+ assert_eq!(migrate_legacy_state(&scoped).await.unwrap(), 0);+}diff --git a/crates/openhuman-core/src/integrations/task_sources/mod.rs b/crates/openhuman-core/src/integrations/task_sources/mod.rsindex 870888ff63..344a64bc37 100644--- a/crates/openhuman-core/src/integrations/task_sources/mod.rs+++ b/crates/openhuman-core/src/integrations/task_sources/mod.rs@@ -22,8 +22,8 @@ pub mod periodic;pub mod pipeline;pub mod route;mod schemas;-pub mod store;mod storage_schema;+pub mod store;mod store_documents;mod store_import;pub(crate) use storage_schema::storage_schema;diff --git a/crates/openhuman-core/src/modules/storage_import_support.rs b/crates/openhuman-core/src/modules/storage_import_support.rsindex c35a1437dc..8244310099 100644--- a/crates/openhuman-core/src/modules/storage_import_support.rs+++ b/crates/openhuman-core/src/modules/storage_import_support.rs@@ -42,11 +42,7 @@ pub(super) fn marker_id(prefix: &str, source: &Path) -> String {/// collection name (`tinybox_host_import`), so a marker row an older build/// wrote ([`crate::storage::import_state::migrate_legacy_markers`]) answers/// the same question.-pub(super) async fn already_imported(- scoped: &ScopedStorage,- kind: &str,- id: &str,-) -> Result<bool> {+pub(super) async fn already_imported(scoped: &ScopedStorage, kind: &str, id: &str) -> Result<bool> {crate::storage::import_state::host_import_done(scoped, kind, id).await.map_err(|error| anyhow!("read the import state: {:?}", error.kind()))diff --git a/crates/openhuman-core/src/modules/storage_import_tinybox.rs b/crates/openhuman-core/src/modules/storage_import_tinybox.rsindex 2d7457510a..97a383100d 100644--- a/crates/openhuman-core/src/modules/storage_import_tinybox.rs+++ b/crates/openhuman-core/src/modules/storage_import_tinybox.rs@@ -91,8 +91,7 @@ async fn import_into(scoped: &ScopedStorage, base: &Path) -> Result<Outcome> {_ => tracing::warn!("{LOG_PREFIX} skipped an index file that is not a JSON object"),}- support::mark_imported(scoped, MARKER_COLLECTION, &marker)- .await?;+ support::mark_imported(scoped, MARKER_COLLECTION, &marker).await?;tracing::info!("{LOG_PREFIX} imported written={written}");Ok(Outcome::Imported { written })}diff --git a/crates/openhuman-core/src/modules/storage_import_tinyconnectors.rs b/crates/openhuman-core/src/modules/storage_import_tinyconnectors.rsindex f131d49bca..a4b69eb69a 100644--- a/crates/openhuman-core/src/modules/storage_import_tinyconnectors.rs+++ b/crates/openhuman-core/src/modules/storage_import_tinyconnectors.rs@@ -118,8 +118,7 @@ async fn import_into(triggers += support::append_if_empty(scoped, &day.stream, day.records).await?;}- support::mark_imported(scoped, MARKER_COLLECTION, &marker)- .await?;+ support::mark_imported(scoped, MARKER_COLLECTION, &marker).await?;tracing::info!("{LOG_PREFIX} imported prefs={prefs} triggers={triggers} skipped={}",legacy.skippeddiff --git a/crates/openhuman-core/src/modules/storage_import_tinyjuice.rs b/crates/openhuman-core/src/modules/storage_import_tinyjuice.rsindex 494ea34351..4f974bcd10 100644--- a/crates/openhuman-core/src/modules/storage_import_tinyjuice.rs+++ b/crates/openhuman-core/src/modules/storage_import_tinyjuice.rs@@ -136,8 +136,7 @@ async fn import_into(imported += 1;}- support::mark_imported(scoped, MARKER_COLLECTION, &marker)- .await?;+ support::mark_imported(scoped, MARKER_COLLECTION, &marker).await?;tracing::info!("{LOG_PREFIX} imported={imported} expired={expired} skipped={skipped}");Ok(Outcome::Imported {imported,diff --git a/crates/openhuman-core/src/modules/storage_import_tinymcp.rs b/crates/openhuman-core/src/modules/storage_import_tinymcp.rsindex 2459dcbfe0..6b008a67f6 100644--- a/crates/openhuman-core/src/modules/storage_import_tinymcp.rs+++ b/crates/openhuman-core/src/modules/storage_import_tinymcp.rs@@ -95,7 +95,8 @@ async fn import_into(let marker = marker_id(data_dir);if crate::storage::import_state::host_import_done(scoped, MARKER_COLLECTION, &marker).await- .map_err(|error| anyhow!("read the import state: {:?}", error.kind()))? {+ .map_err(|error| anyhow!("read the import state: {:?}", error.kind()))?+ {return Ok(Outcome::AlreadyDone);}let clients = data_dir.join(CLIENTS_DB);diff --git a/crates/openhuman-core/src/modules/storage_import_tinywallet.rs b/crates/openhuman-core/src/modules/storage_import_tinywallet.rsindex 15b2be0d11..70d88947d5 100644--- a/crates/openhuman-core/src/modules/storage_import_tinywallet.rs+++ b/crates/openhuman-core/src/modules/storage_import_tinywallet.rs@@ -83,8 +83,7 @@ async fn import_into(let payments = support::append_if_empty(scoped, PAYMENTS_STREAM, records).await.map_err(|error| anyhow!("import the payments: {error:#}"))?;- support::mark_imported(scoped, MARKER_COLLECTION, &marker)- .await?;+ support::mark_imported(scoped, MARKER_COLLECTION, &marker).await?;tracing::info!("{LOG_PREFIX} imported payments={payments} skipped={skipped}");Ok(Outcome::Imported { payments, skipped })}diff --git a/crates/openhuman-core/src/platform/cost/mod.rs b/crates/openhuman-core/src/platform/cost/mod.rsindex 74be1db618..d2c3f13752 100644--- a/crates/openhuman-core/src/platform/cost/mod.rs+++ b/crates/openhuman-core/src/platform/cost/mod.rs@@ -6,9 +6,9 @@ pub mod route;mod rpc;mod schemas;pub mod scope;+mod storage_schema;pub mod tools;pub mod tracker;-mod storage_schema;pub use storage_schema::storage_schema;mod tracker_documents;pub mod types;diff --git a/crates/openhuman-core/src/profiles/registry.rs b/crates/openhuman-core/src/profiles/registry.rsindex 21007d40e2..e25431c70a 100644--- a/crates/openhuman-core/src/profiles/registry.rs+++ b/crates/openhuman-core/src/profiles/registry.rs@@ -21,9 +21,9 @@ use tinystoragedrivers::{};use super::layout::{self, ProfileLayout};-use super::types::{ProfileId, ProfileMeta};use super::storage_schema::migrate_cluster;pub use super::storage_schema::REGISTRY_COLLECTION;+use super::types::{ProfileId, ProfileMeta};use crate::storage::lease::CLUSTER_SCOPE;use crate::storage::schema_support::key_of;use crate::storage::{DocumentStore, StorageBackend};diff --git a/crates/openhuman-core/src/profiles/storage_schema_tests.rs b/crates/openhuman-core/src/profiles/storage_schema_tests.rsindex 0a92821b1c..73297ec0ad 100644--- a/crates/openhuman-core/src/profiles/storage_schema_tests.rs+++ b/crates/openhuman-core/src/profiles/storage_schema_tests.rs@@ -1,6 +1,6 @@use super::*;use serde_json::json;-use tinystoragedrivers::{Meta, MemoryStorage, Precondition, Scope, StorageBackend};+use tinystoragedrivers::{MemoryStorage, Meta, Precondition, Scope, StorageBackend};#[test]fn a_registry_row_loses_its_seconds_field_and_keeps_its_creation_time() {@@ -12,7 +12,10 @@ fn a_registry_row_loses_its_seconds_field_and_keeps_its_creation_time() {.unwrap();assert_eq!(out[0].collection, REGISTRY_COLLECTION);assert_eq!(out[0].id, "alice");- assert_eq!(out[0].body, json!({ "profile_id": "alice", "layout_version": 2 }));+ assert_eq!(+ out[0].body,+ json!({ "profile_id": "alice", "layout_version": 2 })+ );assert_eq!(out[0].created_ms, Some(1_700_000_000_000));}@@ -21,7 +24,9 @@ async fn migrate_cluster_moves_the_v1_registry_into_the_v2_collection() {let backend = MemoryStorage::new();let scoped = backend.for_scope(&Scope::cluster()).unwrap();let docs = scoped.documents();- docs.ensure_collection(&CollectionSpec::new("profiles")).await.unwrap();+ docs.ensure_collection(&CollectionSpec::new("profiles"))+ .await+ .unwrap();docs.put("profiles","alice",@@ -32,8 +37,15 @@ async fn migrate_cluster_moves_the_v1_registry_into_the_v2_collection() {.unwrap();migrate_cluster(&scoped).await.unwrap();migrate_cluster(&scoped).await.unwrap();- let moved = docs.get(REGISTRY_COLLECTION, "alice").await.unwrap().unwrap();- assert_eq!(moved.doc, json!({ "profile_id": "alice", "layout_version": 2 }));+ let moved = docs+ .get(REGISTRY_COLLECTION, "alice")+ .await+ .unwrap()+ .unwrap();+ assert_eq!(+ moved.doc,+ json!({ "profile_id": "alice", "layout_version": 2 })+ );assert_eq!(moved.meta.created_ms, 5000);}diff --git a/crates/openhuman-core/src/security/approval/mod.rs b/crates/openhuman-core/src/security/approval/mod.rsindex 267b9c91a8..15c7762001 100644--- a/crates/openhuman-core/src/security/approval/mod.rs+++ b/crates/openhuman-core/src/security/approval/mod.rs@@ -20,8 +20,8 @@ mod registration_scope;pub use registration_scope::ApprovalScope;pub mod rpc;pub mod schemas;-pub mod store;mod storage_schema;+pub mod store;mod store_documents;mod store_import;pub(crate) use storage_schema::storage_schema;diff --git a/crates/openhuman-core/src/security/approval/store_documents.rs b/crates/openhuman-core/src/security/approval/store_documents.rsindex 22d73fefd9..b58c1b47af 100644--- a/crates/openhuman-core/src/security/approval/store_documents.rs+++ b/crates/openhuman-core/src/security/approval/store_documents.rs@@ -32,10 +32,12 @@ use crate::config::Config;use crate::storage::documents::compare_and_swap;use crate::storage::local;use crate::storage::{block_on, DocumentStore, DocumentStoreExt, ScopedStorage, StorageError};-use tinystoragedrivers::{CollectionSpec, ErrorKind, Filter, Key, Precondition, Query, Sort, Versioned};+use tinystoragedrivers::{+ CollectionSpec, ErrorKind, Filter, Key, Precondition, Query, Sort, Versioned,+};-pub(super) use super::storage_schema::{trust_id, APPROVALS, FLOW_TRUST};use super::storage_schema::{legacy_collections, specs};+pub(super) use super::storage_schema::{trust_id, APPROVALS, FLOW_TRUST};use super::types::{ApprovalAuditEntry, ApprovalDecision, ApprovalSourceContext, ExecutionOutcome, PendingApproval,diff --git a/crates/openhuman-core/src/security/approval/store_import_tests.rs b/crates/openhuman-core/src/security/approval/store_import_tests.rsindex 6dc3a19d71..ddc6cf839a 100644--- a/crates/openhuman-core/src/security/approval/store_import_tests.rs+++ b/crates/openhuman-core/src/security/approval/store_import_tests.rs@@ -186,9 +186,10 @@ fn an_old_schema_is_brought_forward_and_its_session_ids_scrubbed() {.scoped().unwrap();let docs = std::sync::Arc::clone(docs.documents());- let stored = crate::storage::block_on(async move { docs.get("approvals.requests", "old").await })- .unwrap()- .unwrap();+ let stored =+ crate::storage::block_on(async move { docs.get("approvals.requests", "old").await })+ .unwrap()+ .unwrap();assert_eq!(stored.doc["session_id"], PRE_MIGRATION_SESSION_ID);assert_eq!(std::fs::read(&db).unwrap(), before, "approval.db untouched");}diff --git a/crates/openhuman-core/src/security/devices/mod.rs b/crates/openhuman-core/src/security/devices/mod.rsindex 77cbdcac52..dba38566ba 100644--- a/crates/openhuman-core/src/security/devices/mod.rs+++ b/crates/openhuman-core/src/security/devices/mod.rs@@ -8,8 +8,8 @@ pub mod crypto;mod owner;pub mod rpc;pub mod schemas;-pub mod store;mod storage_schema;+pub mod store;mod store_documents;mod store_import;pub(crate) use storage_schema::storage_schema;diff --git a/crates/openhuman-core/src/storage/agents.rs b/crates/openhuman-core/src/storage/agents.rsindex 3556741169..b4b4fb9e67 100644--- a/crates/openhuman-core/src/storage/agents.rs+++ b/crates/openhuman-core/src/storage/agents.rs@@ -51,16 +51,16 @@ pub fn storage_schema() -> Schema {.step(Step::new("registry_v2", AGENTS, 1, 2, registry_v2).source(LEGACY_AGENTS))}-fn registry_v2(- batch: Vec<SourceRecord>,-) -> tinystoragedrivers::Result<Vec<TargetRecord>> {+fn registry_v2(batch: Vec<SourceRecord>) -> tinystoragedrivers::Result<Vec<TargetRecord>> {batch.into_iter().map(|record| {- Ok(- TargetRecord::new(AGENTS, key_of(&record.id)?, json!({ "agent_id": record.id }))- .created_ms(record.meta.created_ms),+ Ok(TargetRecord::new(+ AGENTS,+ key_of(&record.id)?,+ json!({ "agent_id": record.id }),)+ .created_ms(record.meta.created_ms))}).collect()}@@ -154,7 +154,12 @@ fn recorded(backend: Arc<dyn StorageBackend>) -> Vec<String> {let stored = docs.query_all(AGENTS, &Query::all()).await?;Ok(stored.into_iter()- .filter_map(|doc| doc.doc.get("agent_id").and_then(Value::as_str).map(str::to_owned))+ .filter_map(|doc| {+ doc.doc+ .get("agent_id")+ .and_then(Value::as_str)+ .map(str::to_owned)+ }).collect::<Vec<_>>())});result.unwrap_or_else(|error| {diff --git a/crates/openhuman-core/src/storage/host_migration_tests.rs b/crates/openhuman-core/src/storage/host_migration_tests.rsnew file mode 100644index 0000000000..6f5e6af3d6--- /dev/null+++ b/crates/openhuman-core/src/storage/host_migration_tests.rs@@ -0,0 +1,324 @@+//! Boot over a backend holding the host domains' v1 collections: every record+//! arrives in its v2 collection and shape, the v1 collections are emptied, and+//! the import markers an older build wrote still count as finished imports.++use std::sync::Arc;++use serde_json::{json, Value};+use tinystoragedrivers::schema::Migrations;+use tinystoragedrivers::{+ DocumentStore, DocumentStoreExt, Kv, MemoryStorage, Precondition, Query, Scope, ScopedStorage,+ StorageBackend,+};++use super::boot::prepare_and_migrate;+use super::import_state::{migrate_legacy_markers, step_id};++async fn seed(docs: &Arc<dyn DocumentStore>, collection: &str, id: &str, body: Value) {+ docs.ensure_collection(&tinystoragedrivers::CollectionSpec::new(collection))+ .await+ .unwrap();+ docs.put(collection, id, body, Precondition::Absent)+ .await+ .unwrap();+}++async fn get(docs: &Arc<dyn DocumentStore>, collection: &str, id: &str) -> Value {+ docs.get(collection, id)+ .await+ .unwrap()+ .unwrap_or_else(|| panic!("{collection}/{id} is missing"))+ .doc+}++async fn rows(docs: &Arc<dyn DocumentStore>, collection: &str) -> usize {+ docs.query_all(collection, &Query::all())+ .await+ .map_or(0, |rows| rows.len())+}++fn local(backend: &Arc<dyn StorageBackend>) -> ScopedStorage {+ backend.for_scope(&Scope::local()).unwrap()+}++#[tokio::test]+async fn the_host_domains_v1_records_arrive_in_the_v2_collections() {+ let backend: Arc<dyn StorageBackend> = Arc::new(MemoryStorage::new());+ let scoped = local(&backend);+ let docs = Arc::clone(scoped.documents());++ seed(+ &docs,+ "approvals",+ "req-1",+ json!({+ "tool_name": "shell", "action_summary": "ls", "args_redacted": "{}",+ "session_id": "s", "created_at": "1970-01-01T00:00:01Z",+ "expires_at": "1970-01-01T00:00:05Z", "expires_ts": 5_000_000_000_i64,+ "pending": true,+ }),+ )+ .await;+ seed(+ &docs,+ "approval_flow_trust",+ "4:flow/tool",+ json!({ "flow_id": "flow", "tool_name": "tool", "created_at": "1970-01-01T00:00:02Z" }),+ )+ .await;+ seed(+ &docs,+ "paired_devices",+ "chan-1",+ json!({+ "label": "Phone", "device_pubkey": "pk", "core_session_token_hash": "h",+ "created_at": "1970-01-01T00:00:03Z", "last_seen_at": null, "revoked": false,+ }),+ )+ .await;+ seed(+ &docs,+ "integration_notifications",+ "n1",+ json!({+ "provider": "slack", "title": "t", "body": "b", "raw_payload": "{}",+ "status": "unread", "received_at": "1970-01-01T00:00:04Z", "received_ms": 4000,+ }),+ )+ .await;+ seed(&docs, "notification_dedup", "abc", json!({ "last_ms": 9 })).await;+ seed(+ &docs,+ "notification_settings",+ "slack",+ json!({ "enabled": true, "importance_threshold": 0.5, "route_to_orchestrator": true }),+ )+ .await;+ seed(+ &docs,+ "core_notifications",+ "5:local/e1",+ json!({+ "workspace": "local", "payload": "{}", "timestamp_ms": 6, "read": false,+ "created_at": "1970-01-01T00:00:05Z",+ }),+ )+ .await;+ seed(+ &docs,+ "task_sources",+ "src",+ json!({+ "provider": "linear", "enabled": true, "filter": "{}", "interval_secs": 60,+ "target": "{}", "max_tasks_per_fetch": 5,+ "created_at": "1970-01-01T00:00:06Z", "created_ms": 6000,+ "last_fetch_at": "1970-01-01T00:00:07Z",+ }),+ )+ .await;+ seed(+ &docs,+ "ingested_tasks",+ "3:src/ext",+ json!({+ "source_id": "src", "external_id": "ext", "content_hash": "h",+ "ingested_at": "1970-01-01T00:00:08Z", "ingested_ms": 8000, "ingested_ns": 8_000_000_000_i64,+ }),+ )+ .await;+ seed(+ &docs,+ "artifacts",+ "art-1",+ json!({+ "id": "art-1", "kind": "document", "title": "T", "path": "p", "size_bytes": 1,+ "status": "ready", "created_at": "1970-01-01T00:00:09Z", "created_ms": 9000,+ }),+ )+ .await;+ seed(+ &docs,+ "artifact_args",+ "art-1",+ json!({ "args": { "prompt": "x" } }),+ )+ .await;+ seed(+ &docs,+ "artifact_versions",+ "art-1",+ json!({+ "id": "art-1", "updatedAtMillis": 10, "updated_ms": 10,+ "versions": [{ "authorId": "a", "createdAtMillis": 1 }],+ }),+ )+ .await;+ seed(+ &docs,+ "cost_records",+ "c1",+ json!({+ "id": "c1", "session_id": "s", "ts_ms": 11000,+ "usage": { "model": "m", "timestamp": "1970-01-01T00:00:11Z" },+ }),+ )+ .await;+ seed(&docs, "config", "local", json!({ "toml_enc": "enc2:00" })).await;+ seed(+ &docs,+ "subagent_sessions",+ "sub-1",+ json!({+ "subagentSessionId": "sub-1", "parentSession": "p", "agentId": "a",+ "sandboxMode": "workspace", "taskKey": "k", "taskTitle": "T", "status": "idle",+ "reusable": true, "createdAt": "1970-01-01T00:00:12Z",+ "updatedAt": "1970-01-01T00:00:13Z", "lastUsedAt": "1970-01-01T00:00:13Z",+ }),+ )+ .await;+ seed(+ &docs,+ "threads_transcript_keys",+ "thread-1",+ json!({ "key": "agent" }),+ )+ .await;+ seed(&docs, "storage_agents", "asha", json!({})).await;+ seed(+ &docs,+ "composio_state",+ "composio_identities.json",+ json!({ "value": { "gmail": 3 } }),+ )+ .await;+ seed(+ &docs,+ "storage_import",+ "approval@abcd",+ json!({ "version": 1 }),+ )+ .await;+ seed(+ &docs,+ "threads_import",+ "legacy-conversations:k",+ json!({ "threads": 1 }),+ )+ .await;++ let report = prepare_and_migrate(&backend).await.unwrap();+ assert!(report.failures.is_empty(), "{:?}", report.failures);++ let request = get(&docs, "approvals.requests", "req-1").await;+ assert_eq!(request["created_ms"], 1000);+ assert_eq!(request["deadline_ms"], 5000);+ assert_eq!(request["pending"], true);+ assert_eq!(+ get(&docs, "approvals.flow_trust", "flow/tool").await,+ json!({ "flow_id": "flow", "tool_name": "tool", "created_ms": 2000 })+ );+ assert_eq!(+ get(&docs, "devices.paired", "chan-1").await["created_ms"],+ 3000+ );+ assert_eq!(+ get(&docs, "notifications.integration", "n1").await["received_ms"],+ 4000+ );+ assert_eq!(get(&docs, "notifications.dedup", "abc").await["last_ms"], 9);+ assert_eq!(+ get(&docs, "notifications.settings", "slack").await["enabled"],+ true+ );+ assert_eq!(+ get(&docs, "notifications.core", "local/e1").await["timestamp_ms"],+ 6+ );+ assert_eq!(+ get(&docs, "task_sources.sources", "src").await["last_fetch_ms"],+ 7000+ );+ assert_eq!(+ get(&docs, "task_sources.ingested", "src/ext").await["ingested_ms"],+ 8000+ );+ assert!(get(&docs, "artifacts.records", "art-1")+ .await+ .get("created_at")+ .is_none());+ assert_eq!(+ get(&docs, "artifacts.args", "art-1").await,+ json!({ "prompt": "x" })+ );+ assert_eq!(+ get(&docs, "artifacts.versions", "art-1").await["versions"][0]["created_ms"],+ 1+ );+ assert!(get(&docs, "cost.records", "c1").await["usage"]+ .get("timestamp")+ .is_none());+ assert_eq!(+ get(&docs, "config.documents", "local").await,+ json!({ "toml_enc": "enc2:00" })+ );+ assert_eq!(+ get(&docs, "subagents.sessions", "sub-1").await["created_ms"],+ 12000+ );+ assert_eq!(+ get(&docs, "threads.transcript_keys", "thread-1").await,+ json!({ "key": "agent" })+ );+ assert_eq!(+ get(&docs, "agents.registry", "asha").await,+ json!({ "agent_id": "asha" })+ );+ // `composio_state` moved into tsd.kv, unwrapped.+ let kv = Kv::ns(&docs, "composio", "state").unwrap();+ assert_eq!(+ kv.get::<Value>("composio_identities.json").await.unwrap(),+ Some(json!({ "gmail": 3 }))+ );++ // The v1 collections are empty.+ for old in [+ "approvals",+ "approval_flow_trust",+ "paired_devices",+ "integration_notifications",+ "core_notifications",+ "task_sources",+ "ingested_tasks",+ "artifacts",+ "artifact_args",+ "artifact_versions",+ "cost_records",+ "config",+ "subagent_sessions",+ "threads_transcript_keys",+ "storage_agents",+ "composio_state",+ ] {+ assert_eq!(rows(&docs, old).await, 0, "{old} still holds records");+ }++ // The older builds' markers are finished imports now.+ let migrations = Migrations::new(&scoped);+ assert!(migrations+ .done("storage", &step_id("storage_import", "approval@abcd"))+ .await+ .unwrap());+ assert!(migrations+ .done(+ "threads",+ &step_id("threads_import", "legacy-conversations:k")+ )+ .await+ .unwrap());++ // A second boot has nothing left to do.+ let again = prepare_and_migrate(&backend).await.unwrap();+ assert!(again.failures.is_empty(), "{:?}", again.failures);+ assert_eq!(again.steps_run, 0);+ assert_eq!(migrate_legacy_markers(&scoped).await.unwrap(), 0);+}diff --git a/crates/openhuman-core/src/storage/import/mod.rs b/crates/openhuman-core/src/storage/import/mod.rsindex 612a360755..b779e108c7 100644--- a/crates/openhuman-core/src/storage/import/mod.rs+++ b/crates/openhuman-core/src/storage/import/mod.rs@@ -309,7 +309,8 @@ fn upgrade(owner: &str, records: Vec<Record>) -> Result<(Vec<Record>, Vec<Collec}for (collection, batch) in by_collection {let step = schema.steps.iter().find(|step| {- matches!(step.run, StepBody::Documents(_)) && step.source.unwrap_or(step.item) == collection+ matches!(step.run, StepBody::Documents(_))+ && step.source.unwrap_or(step.item) == collection});let Some(StepBody::Documents(run)) = step.map(|step| &step.run) else {upgraded.extend(batch.into_iter().map(|r| Record {@@ -354,12 +355,7 @@ fn import_one(let domain = source.domain;// The v2 collections are declared by the write itself (`upgrade` names// them); the v1 specs only tell the snapshot which document tables to read.- let repo = Repo::on(- backend,- &super::scope::tenant_scope(None),- domain,- Vec::new,- )?;+ let repo = Repo::on(backend, &super::scope::tenant_scope(None), domain, Vec::new)?;let markers = Repo::on(backend,&super::scope::tenant_scope(None),diff --git a/crates/openhuman-core/src/storage/import/tinyflows_tests.rs b/crates/openhuman-core/src/storage/import/tinyflows_tests.rsindex 615bb659fd..69d337f540 100644--- a/crates/openhuman-core/src/storage/import/tinyflows_tests.rs+++ b/crates/openhuman-core/src/storage/import/tinyflows_tests.rs@@ -1,7 +1,7 @@use super::*;-use serde_json::json;use crate::cron::client::testing as cron_store;use crate::storage::{MemoryStorage, Scope};+use serde_json::json;use serde_json::Value;use sha2::Digest;use std::collections::BTreeMap;diff --git a/crates/openhuman-core/src/storage/import_state.rs b/crates/openhuman-core/src/storage/import_state.rsindex a7f4c59bbe..09669d8feb 100644--- a/crates/openhuman-core/src/storage/import_state.rs+++ b/crates/openhuman-core/src/storage/import_state.rs@@ -90,7 +90,11 @@ pub async fn done(scoped: &ScopedStorage, owner: &str, step: &str) -> Result<boo/// # Errors////// A storage error.-pub async fn mark_done(scoped: &ScopedStorage, owner: &str, step: &str) -> Result<(), StorageError> {+pub async fn mark_done(+ scoped: &ScopedStorage,+ owner: &str,+ step: &str,+) -> Result<(), StorageError> {declare(scoped.documents()).await?;Migrations::new(scoped).mark_done(owner, step).await}@@ -297,7 +301,10 @@ fn lease_key(owner: &str, step: &str) -> String {/// A storage error; the markers not yet moved stay in place for the next boot.pub async fn migrate_legacy_markers(scoped: &ScopedStorage) -> Result<usize, StorageError> {let docs = scoped.documents();- if !docs.capabilities().contains(Capability::CollectionEnumeration) {+ if !docs+ .capabilities()+ .contains(Capability::CollectionEnumeration)+ {return Ok(0);}let present = docs.collections("").await?;diff --git a/crates/openhuman-core/src/storage/import_state_tests.rs b/crates/openhuman-core/src/storage/import_state_tests.rsindex 3843422472..b96bf5bc52 100644--- a/crates/openhuman-core/src/storage/import_state_tests.rs+++ b/crates/openhuman-core/src/storage/import_state_tests.rs@@ -36,14 +36,10 @@ fn claim_runs_the_body_and_releases() {#[test]fn claim_is_released_when_the_body_fails() {let repo = repo();- let result: Result<Option<()>> =- with_claim(&repo, OWNER, "m", || Err(anyhow::anyhow!("boom")));+ let result: Result<Option<()>> = with_claim(&repo, OWNER, "m", || Err(anyhow::anyhow!("boom")));assert!(result.is_err());assert!(!claim_held(&repo, "m"));- assert_eq!(- with_claim(&repo, OWNER, "m", || Ok(1)).unwrap(),- Some(1)- );+ assert_eq!(with_claim(&repo, OWNER, "m", || Ok(1)).unwrap(), Some(1));}#[test]@@ -181,7 +177,14 @@ fn a_legacy_marker_row_is_honoured_and_removed() {.await?;let moved = migrate_legacy_markers(&scoped).await?;assert_eq!(moved, 1);- assert!(done(&scoped, "storage", &step_id("storage_import", "approval@abcd")).await?);+ assert!(+ done(+ &scoped,+ "storage",+ &step_id("storage_import", "approval@abcd")+ )+ .await?+ );assert!(!done(&scoped, "storage", &step_id("storage_import", "other@x")).await?);assert!(docs.query_all("storage_import", &tinystoragedrivers::Query::all())@@ -191,7 +194,14 @@ fn a_legacy_marker_row_is_honoured_and_removed() {);// A second sweep has nothing to do and keeps the entry.assert_eq!(migrate_legacy_markers(&scoped).await?, 0);- assert!(done(&scoped, "storage", &step_id("storage_import", "approval@abcd")).await?);+ assert!(+ done(+ &scoped,+ "storage",+ &step_id("storage_import", "approval@abcd")+ )+ .await?+ );Ok::<_, StorageError>(())}).unwrap();diff --git a/crates/openhuman-core/src/storage/mod.rs b/crates/openhuman-core/src/storage/mod.rsindex 07b0ababa5..49416eabd5 100644--- a/crates/openhuman-core/src/storage/mod.rs+++ b/crates/openhuman-core/src/storage/mod.rs@@ -40,8 +40,8 @@ mod lease_local;pub mod local;pub mod rebind;pub mod schema;-pub mod scope;pub mod schema_support;+pub mod scope;pub mod scope_move;pub mod secrets;@@ -347,3 +347,7 @@ pub fn source_key(source: &std::path::Path) -> String {#[cfg(test)]#[path = "mod_tests.rs"]mod tests;++#[cfg(test)]+#[path = "host_migration_tests.rs"]+mod host_migration_tests;diff --git a/crates/openhuman-core/src/storage/schema_tests.rs b/crates/openhuman-core/src/storage/schema_tests.rsindex 21fa7416f6..0389689caa 100644--- a/crates/openhuman-core/src/storage/schema_tests.rs+++ b/crates/openhuman-core/src/storage/schema_tests.rs@@ -4,7 +4,23 @@ use super::*;fn every_owner_composes_without_collision() {let registry = registry().expect("the owners compose");let owners: Vec<&str> = registry.owners().collect();- for expected in ["harness", "session", "graph", "tasks"] {+ for expected in [+ "harness",+ "session",+ "graph",+ "tasks",+ "approvals",+ "devices",+ "notifications",+ "task_sources",+ "artifacts",+ "cost",+ "config",+ "profiles",+ "threads",+ "subagents",+ "agents",+ ] {assert!(owners.contains(&expected), "{expected} missing: {owners:?}");}}diff --git a/crates/openhuman-core/src/threads/store/legacy_import.rs b/crates/openhuman-core/src/threads/store/legacy_import.rsindex ddf8f87287..b9ef725aba 100644--- a/crates/openhuman-core/src/threads/store/legacy_import.rs+++ b/crates/openhuman-core/src/threads/store/legacy_import.rs@@ -179,9 +179,10 @@ pub(super) fn import_once())?);}let store = store.clone();- let (threads_n, messages_n) = crate::storage::block_on_anyhow(async move {- copy(&store, threads, messages).await- })?;+ let (threads_n, messages_n) =+ crate::storage::block_on_anyhow(+ async move { copy(&store, threads, messages).await },+ )?;import_state::set_done(repo, OWNER, &step)?;log::info!("{LOG_PREFIX} imported threads={threads_n} messages={messages_n}");Ok(())diff --git a/crates/openhuman-core/src/threads/store/storage_schema.rs b/crates/openhuman-core/src/threads/store/storage_schema.rsindex 4cf479eda1..503a776bcb 100644--- a/crates/openhuman-core/src/threads/store/storage_schema.rs+++ b/crates/openhuman-core/src/threads/store/storage_schema.rs@@ -25,8 +25,14 @@ pub fn storage_schema() -> Schema {Schema::new(owner("threads")).collection_with(SCHEMA, spec(), ScopeClass::Tenant).step(- Step::new("transcript_keys_v2", TRANSCRIPT_KEYS, 1, SCHEMA, transcript_keys_v2)- .source(LEGACY_TRANSCRIPT_KEYS),+ Step::new(+ "transcript_keys_v2",+ TRANSCRIPT_KEYS,+ 1,+ SCHEMA,+ transcript_keys_v2,+ )+ .source(LEGACY_TRANSCRIPT_KEYS),)}diff --git a/crates/openhuman-core/src/tinymemes/docs.rs b/crates/openhuman-core/src/tinymemes/docs.rsindex 8f213ffae5..35a95dac42 100644--- a/crates/openhuman-core/src/tinymemes/docs.rs+++ b/crates/openhuman-core/src/tinymemes/docs.rs@@ -72,8 +72,8 @@ pub(super) fn load(config: &Config, kind: IndexKind) -> Result<Option<String>> {let adopted = state_body(kind, &legacy);let written = repo.run(move |docs| async move {docs.put(COLLECTION, id, adopted, Precondition::Absent)- .await- .map(|_| ())+ .await+ .map(|_| ())});match written {Ok(()) => {diff --git a/docs/storage-schema.md b/docs/storage-schema.mdindex ea0381afbf..22522d3ffe 100644--- a/docs/storage-schema.md+++ b/docs/storage-schema.md@@ -9,6 +9,42 @@ scope at boot. Names are `<owner>.<entity>`; the scope class says where a record(`tenant`: `local` or `u:<id>`, `agent`: `<tenant>/agent:<id>`, `module`:`<tenant>/module:<id>`, `cluster`: the shared registry scope).+## agents++| Kind | Name | Version | Scope | Indexed fields |+| --- | --- | --- | --- | --- |+| collection | `agents.registry` | 2 | tenant | |++Migration steps:++- `registry_v2`: `agents.registry` v1 to v2 from `storage_agents`++## approvals++| Kind | Name | Version | Scope | Indexed fields |+| --- | --- | --- | --- | --- |+| collection | `approvals.flow_trust` | 2 | tenant | `flow_id`, `tool_name` |+| collection | `approvals.requests` | 2 | tenant | `pending`, `created_ms`, `pending`, `decided_ms`, `session_id`, `pending` |++Migration steps:++- `requests_v2`: `approvals.requests` v1 to v2 from `approvals`+- `flow_trust_v2`: `approvals.flow_trust` v1 to v2 from `approval_flow_trust`++## artifacts++| Kind | Name | Version | Scope | Indexed fields |+| --- | --- | --- | --- | --- |+| collection | `artifacts.args` | 2 | tenant | |+| collection | `artifacts.records` | 2 | tenant | `thread_id`, `created_ms` |+| collection | `artifacts.versions` | 2 | tenant | |++Migration steps:++- `records_v2`: `artifacts.records` v1 to v2 from `artifacts`+- `args_v2`: `artifacts.args` v1 to v2 from `artifact_args`+- `versions_v2`: `artifacts.versions` v1 to v2 from `artifact_versions`+## box| Kind | Name | Version | Scope | Indexed fields |@@ -57,6 +93,16 @@ Migration steps:- `whatsapp-sync-key-v2`: `channels.whatsapp_sync_key` v1 to v2 from `whatsapp_sync_key`- `whatsapp-lid-mapping-v2`: `channels.whatsapp_lid_mapping` v1 to v2 from `whatsapp_lid_mapping`+## config++| Kind | Name | Version | Scope | Indexed fields |+| --- | --- | --- | --- | --- |+| collection | `config.documents` | 2 | tenant | |++Migration steps:++- `documents_v2`: `config.documents` v1 to v2 from `config`+## connectors| Kind | Name | Version | Scope | Indexed fields |@@ -83,6 +129,16 @@ Migration steps:- `appends_v2`: `conversations.appends` v1 to v2 from `conversation_appends_v1`- `messages_v2`: `conversations.messages` v1 to v2 from `conversation_messages_v1:`+## cost++| Kind | Name | Version | Scope | Indexed fields |+| --- | --- | --- | --- | --- |+| collection | `cost.records` | 2 | tenant | `ts_ms` |++Migration steps:++- `records_v2`: `cost.records` v1 to v2 from `cost_records`+## cron| Kind | Name | Version | Scope | Indexed fields |@@ -97,6 +153,16 @@ Migration steps:- `runs_v2`: `cron.runs` v1 to v2 from `cron_runs`- `admission_v2`: `cron.admission` v1 to v2 from `cron_counters`+## devices++| Kind | Name | Version | Scope | Indexed fields |+| --- | --- | --- | --- | --- |+| collection | `devices.paired` | 2 | tenant | `revoked`, `created_ms` |++Migration steps:++- `paired_v2`: `devices.paired` v1 to v2 from `paired_devices`+## flows| Kind | Name | Version | Scope | Indexed fields |@@ -267,6 +333,32 @@ Migration steps:- `state_v2`: `memes.state` v1 to v2 from `tinymemes_documents`+## notifications++| Kind | Name | Version | Scope | Indexed fields |+| --- | --- | --- | --- | --- |+| collection | `notifications.core` | 2 | tenant | `workspace`, `read`, `timestamp_ms` |+| collection | `notifications.dedup` | 2 | tenant | |+| collection | `notifications.integration` | 2 | tenant | `provider`, `received_ms`, `status` |+| collection | `notifications.settings` | 2 | tenant | |++Migration steps:++- `integration_v2`: `notifications.integration` v1 to v2 from `integration_notifications`+- `dedup_v2`: `notifications.dedup` v1 to v2 from `notification_dedup`+- `settings_v2`: `notifications.settings` v1 to v2 from `notification_settings`+- `core_v2`: `notifications.core` v1 to v2 from `core_notifications`++## profiles++| Kind | Name | Version | Scope | Indexed fields |+| --- | --- | --- | --- | --- |+| collection | `profiles.registry` | 2 | cluster | |++Migration steps:++- `registry_v2`: `profiles.registry` v1 to v2 from `profiles`+## session| Kind | Name | Version | Scope | Indexed fields |@@ -292,6 +384,28 @@ Migration steps:- `catalogs_v2`: `skills.catalogs` v1 to v2 from `tinyskills_catalogs`+## subagents++| Kind | Name | Version | Scope | Indexed fields |+| --- | --- | --- | --- | --- |+| collection | `subagents.sessions` | 2 | agent | |++Migration steps:++- `sessions_v2`: `subagents.sessions` v1 to v2 from `subagent_sessions`++## task_sources++| Kind | Name | Version | Scope | Indexed fields |+| --- | --- | --- | --- | --- |+| collection | `task_sources.ingested` | 2 | tenant | `source_id`, `ingested_ms` |+| collection | `task_sources.sources` | 2 | tenant | `created_ms` |++Migration steps:++- `sources_v2`: `task_sources.sources` v1 to v2 from `task_sources`+- `ingested_v2`: `task_sources.ingested` v1 to v2 from `ingested_tasks`+## tasks| Kind | Name | Version | Scope | Indexed fields |@@ -306,6 +420,16 @@ Migration steps:- `history_v2`: `tasks.history` v1 to v2 from `orchestration_task_history`- `completions_v2`: `tasks.completions` v1 to v2 from `orchestration_completions`+## threads++| Kind | Name | Version | Scope | Indexed fields |+| --- | --- | --- | --- | --- |+| collection | `threads.transcript_keys` | 2 | tenant | |++Migration steps:++- `transcript_keys_v2`: `threads.transcript_keys` v1 to v2 from `threads_transcript_keys`+## wallet| Kind | Name | Version | Scope | Indexed fields |