Skip to content

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

refactor(storage): add scope conditioning to watching storage

Steven Enamakel247c5be501c7
diff --git a/crates/openhuman-core/src/modules/storage_host_watching.rs b/crates/openhuman-core/src/modules/storage_host_watching.rs
index 17401c75c3..7ecf41e125 100644
--- a/crates/openhuman-core/src/modules/storage_host_watching.rs
+++ b/crates/openhuman-core/src/modules/storage_host_watching.rs
@@ -10,9 +10,7 @@ use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use serde_json::Value;
-use tinystoragedrivers_api::{
- async_trait, DocumentStore, DocumentWatch, Storage, StorageBackend,
-};
+use tinystoragedrivers_api::{DocumentStore, DocumentWatch, Storage, StorageBackend, async_trait};
use tinystoragedrivers_testkit::MemoryBackend;
use tinystoragedrivers_types::{
Capabilities, Capability, CollectionSpec, Filter, Page, Precondition, Query, Result, Scope,
@@ -42,13 +40,28 @@ impl StorageBackend for WatchingStorage {
fn for_scope(&self, scope: &Scope) -> Result<Storage> {
let scoped = self.inner.for_scope(scope)?;
+ Ok(self.wrap_scope(scope, scoped))
+ }
+
+ fn for_scope_conditioned(
+ &self,
+ scope: &Scope,
+ condition: &tinystoragedrivers_types::WriteCondition,
+ ) -> Result<Storage> {
+ let scoped = self.inner.for_scope_conditioned(scope, condition)?;
+ Ok(self.wrap_scope(scope, scoped))
+ }
+}
+
+impl WatchingStorage {
+ fn wrap_scope(&self, scope: &Scope, scoped: Storage) -> Storage {
let sender = {
let mut hub = self.hub.lock().unwrap();
hub.entry(scope.as_str().to_string())
.or_insert_with(|| broadcast::channel(64).0)
.clone()
};
- Ok(Storage::new(
+ Storage::new(
Arc::new(Documents {
inner: Arc::clone(scoped.documents()),
changed: sender,
@@ -58,7 +71,7 @@ impl StorageBackend for WatchingStorage {
Arc::clone(scoped.blobs()),
Arc::clone(scoped.queues()),
Arc::clone(scoped.secrets()),
- ))
+ )
}
}
@@ -102,6 +115,10 @@ impl DocumentStore for Documents {
self.inner.ensure_collection(spec).await
}
+ async fn validate_collection_spec(&self, spec: &CollectionSpec) -> Result<()> {
+ self.inner.validate_collection_spec(spec).await
+ }
+
async fn get(&self, c: &str, id: &str) -> Result<Option<Versioned<Value>>> {
self.inner.get(c, id).await
}
diff --git a/crates/openhuman-core/src/storage/fenced_ports.rs b/crates/openhuman-core/src/storage/fenced_ports.rs
index f19c1e3869..598aabd497 100644
--- a/crates/openhuman-core/src/storage/fenced_ports.rs
+++ b/crates/openhuman-core/src/storage/fenced_ports.rs
@@ -13,10 +13,10 @@ use tinystoragedrivers_api::{
DocumentWatch, Enqueued, KvStore, NewMessage, QueueStore, Receipt, Retry, Storage, StreamStore,
};
use tinystoragedrivers_types::{
- Capabilities, CollectionSpec, Cursor, Filter, Page, Precondition, Query, QueueFeatures,
- QueueSpec, QueueStats, ReadCheck, Result, SealOutcome, SearchHit, Sort, StreamEntry,
- StreamInfo, TreeEntry, TreeFile, Version, Versioned, WatchOptions, WriteOp, WriteOptions,
- WriteResult,
+ Capabilities, Capability, CollectionSpec, Cursor, Filter, Page, Precondition, Query,
+ QueueFeatures, QueueSpec, QueueStats, ReadCheck, Result, SealOutcome, SearchHit, Sort,
+ StreamEntry, StreamInfo, TreeEntry, TreeFile, Version, Versioned, WatchOptions, WriteOp,
+ WriteOptions, WriteResult,
};
use super::{
@@ -336,7 +336,11 @@ impl BlobStore for GuardedBlobs {
self.inner.presign_get(k, t).await
}
async fn presign_put(&self, k: &str, t: Duration) -> Result<String> {
- self.inner.presign_put(k, t).await
+ let _ = (k, t);
+ Err(StorageError::unsupported(
+ Capability::PresignedUrls,
+ "condition-bound storage cannot issue a write URL that outlives its lease check",
+ ))
}
async fn list_dir(&self, d: &str) -> Result<Vec<TreeEntry>> {
self.inner.list_dir(d).await