Skip to content

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

refactor(core): update attachment stash logic and dependencies

Steven Enamakel3e8e3e5e24e6
diff --git a/crates/openhuman-core/Cargo.toml b/crates/openhuman-core/Cargo.toml
index 72e4a213d8..3466bded6e 100644
--- a/crates/openhuman-core/Cargo.toml
+++ b/crates/openhuman-core/Cargo.toml
@@ -118,6 +118,7 @@ tinyagents-storage-kit = { path = "../../vendor/tinyagents/crates/tinyagents-sto
# by default: the `storage-*` features below add them.
tinystoragedrivers = { git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2", default-features = false }
tinystoragedrivers-api = { git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" }
+tinystoragedrivers-connect = { git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2", features = ["sqlite"] }
tinystoragedrivers-types = { git = "https://github.com/senamakel/tinystoragedrivers", tag = "v2.0.2" }
# The host config and secret adapters use the driver's established `enc2`
# codec and per-scope key provider while storing through the v2 SecretStore
diff --git a/crates/openhuman-core/src/agent/multimodal.rs b/crates/openhuman-core/src/agent/multimodal.rs
index cc21549dc0..4e85c3ec23 100644
--- a/crates/openhuman-core/src/agent/multimodal.rs
+++ b/crates/openhuman-core/src/agent/multimodal.rs
@@ -297,33 +297,18 @@ pub(crate) fn attachments_dir() -> PathBuf {
.unwrap_or_else(fallback_attachments_dir)
}
-/// The calling tenant's blob-backed stash: the workspace's storage backend once
-/// [`init_attachments_dir`] ran, else a process-local in-memory one (a CLI or
-/// test with no workspace: placeholders resolve for the life of the process).
+/// The calling tenant's blob-backed stash. It exists only after
+/// [`init_attachments_dir`] supplies the workspace storage binding; absent
+/// that binding, ingress keeps the placeholder but cannot promise rehydration.
/// The mechanism (dedup'd writes, cap eviction, TTL sweep, id index) is
/// `tinyagents_harness::multimodal::BlobAttachmentStash`; the cap and TTL are
/// this host's policy (none: references stay resolvable).
fn stash() -> Option<BlobAttachmentStash> {
- match ATTACHMENTS_WORKSPACE.get() {
- Some(workspace) => crate::storage::sessions::attachment_stash_for(workspace),
- None => Some(memory_stash().clone()),
- }
+ stash_for_workspace(ATTACHMENTS_WORKSPACE.get().map(PathBuf::as_path))
}
-fn memory_stash() -> &'static BlobAttachmentStash {
- static MEMORY: OnceLock<BlobAttachmentStash> = OnceLock::new();
- MEMORY.get_or_init(|| {
- use tinystoragedrivers::StorageBackend as _;
- let scoped = tinystoragedrivers::MemoryStorage::new()
- .for_scope(&tinystoragedrivers::Scope::local())
- .expect("the memory backend binds the local scope");
- BlobAttachmentStash::new(
- std::sync::Arc::clone(scoped.blobs()),
- std::sync::Arc::clone(scoped.documents()),
- u64::MAX,
- Duration::MAX,
- )
- })
+fn stash_for_workspace(workspace: Option<&Path>) -> Option<BlobAttachmentStash> {
+ workspace.and_then(crate::storage::sessions::attachment_stash_for)
}
/// Per-user fallback attachments dir used only when [`init_attachments_dir`]
diff --git a/crates/openhuman-core/src/agent/multimodal_attachment_handling_tests.rs b/crates/openhuman-core/src/agent/multimodal_attachment_handling_tests.rs
index be0c29eab4..96487206e0 100644
--- a/crates/openhuman-core/src/agent/multimodal_attachment_handling_tests.rs
+++ b/crates/openhuman-core/src/agent/multimodal_attachment_handling_tests.rs
@@ -1,7 +1,14 @@
use super::*;
+use std::sync::OnceLock;
const TINY_PNG_DATA_URI: &str = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==";
+fn prepare_attachment_workspace() {
+ static WORKSPACE: OnceLock<tempfile::TempDir> = OnceLock::new();
+ let workspace = WORKSPACE.get_or_init(|| tempfile::tempdir().expect("workspace tempdir"));
+ init_attachments_dir(workspace.path().join("attachments"));
+}
+
#[test]
fn for_untrusted_channel_input_disables_file_markers_and_remote_fetch() {
let config = crate::config::MultimodalFileConfig::for_untrusted_channel_input();
@@ -11,6 +18,7 @@ fn for_untrusted_channel_input_disables_file_markers_and_remote_fetch() {
#[tokio::test]
async fn stash_image_attachments_replaces_marker_with_placeholder() {
+ prepare_attachment_workspace();
let msg = format!("whats this [IMAGE:{TINY_PNG_DATA_URI}]");
let out = stash_image_attachments(&msg, &MultimodalConfig::default()).await;
assert!(out.contains("[Image:"), "placeholder present: {out}");
@@ -21,7 +29,9 @@ async fn stash_image_attachments_replaces_marker_with_placeholder() {
}
#[tokio::test]
+#[cfg(feature = "storage-sqlite")]
async fn image_placeholder_rehydrates_to_inline_data_uri() {
+ prepare_attachment_workspace();
let msg = format!("describe [IMAGE:{TINY_PNG_DATA_URI}]");
let placeholdered = stash_image_attachments(&msg, &MultimodalConfig::default()).await;
let messages = vec![TranscriptMessage::user(placeholdered)];
@@ -54,6 +64,7 @@ async fn rehydrate_missing_stash_id_keeps_placeholder_text() {
#[tokio::test]
async fn stash_image_attachments_caps_at_max_images() {
+ prepare_attachment_workspace();
let msg = format!("[IMAGE:{TINY_PNG_DATA_URI}]\n[IMAGE:{TINY_PNG_DATA_URI}]");
let config = MultimodalConfig {
max_images: 1,
@@ -84,7 +95,9 @@ fn extract_image_placeholders_pulls_attachment_tokens_in_order() {
}
#[tokio::test]
+#[cfg(feature = "storage-sqlite")]
async fn sweep_keeps_fresh_attachments() {
+ prepare_attachment_workspace();
let msg = format!("[IMAGE:{TINY_PNG_DATA_URI}]");
let placeholdered = stash_image_attachments(&msg, &MultimodalConfig::default()).await;
let id = placeholdered
@@ -104,6 +117,11 @@ async fn sweep_keeps_fresh_attachments() {
);
}
+#[test]
+fn no_workspace_does_not_create_a_process_local_attachment_stash() {
+ assert!(stash_for_workspace(None).is_none());
+}
+
#[test]
fn legacy_sidecar_files_stay_indexed_by_id() {
let dir = tempfile::tempdir().unwrap();
diff --git a/crates/openhuman-core/src/storage/mod.rs b/crates/openhuman-core/src/storage/mod.rs
index 0117fc0d70..6ef409d902 100644
--- a/crates/openhuman-core/src/storage/mod.rs
+++ b/crates/openhuman-core/src/storage/mod.rs
@@ -73,9 +73,10 @@ pub use tinystoragedrivers::{
};
pub use tinystoragedrivers_api::{DocumentStore, Storage};
-/// SQLite is used only by the read-only compatibility importers while they
-/// consume historical per-domain files. It is not the process storage API.
-pub use tinystoragedrivers::sqlite::rusqlite;
+/// SQLite is used only by machine-local watcher metadata and read-only
+/// compatibility importers consuming historical files. The process storage
+/// API remains the `StorageBackend` facade above.
+pub use tinystoragedrivers_connect::sqlite::rusqlite;
/// Typed conveniences for document consumers, including a bounded cursor
/// walk for callers that need every matching record.