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
fix(attachments): include attachment header in fallback readouts
Steven Enamakel63517074a330
diff --git a/crates/openhuman-core/src/attachments/provider_fallback.rs b/crates/openhuman-core/src/attachments/provider_fallback.rsindex dcb16f1e4b..7a2ef7836d 100644--- a/crates/openhuman-core/src/attachments/provider_fallback.rs+++ b/crates/openhuman-core/src/attachments/provider_fallback.rs@@ -2,7 +2,6 @@ use super::*;impl AttachmentModel {pub(super) async fn document_fallback(&self,- path: &str,mime: &str,bytes: &[u8],) -> tinyinference_llm::Result<(String, bool)> {@@ -15,7 +14,7 @@ impl AttachmentModel {#[cfg(not(feature = "documents"))]let text = String::new();#[cfg(not(feature = "documents"))]- let _ = (path, mime, bytes);+ let _ = (mime, bytes);#[cfg(feature = "documents")]{use tinydocs_bus::DocumentFormat;@@ -38,7 +37,7 @@ impl AttachmentModel {);cacheable = false;text.push_str(&format!(- "Document extraction is disabled ([components] documents = false); original remains available at workspace path: {path}."+ "Document extraction is disabled ([components] documents = false); original remains available."));} else if let Some(format) = format {let (_, _, limit) = self.config.multimodal_files.effective_limits();@@ -154,7 +153,7 @@ impl AttachmentModel {}Ok(Err(error)) => {cacheable = false;- text.push_str(&format!("Document extraction unavailable: {error}. Original remains available at workspace path: {path}."));+ text.push_str(&format!("Document extraction unavailable: {error}. Original remains available."));}Err(_) => {cacheable = false;diff --git a/crates/openhuman-core/src/attachments/provider_owner.rs b/crates/openhuman-core/src/attachments/provider_owner.rsindex 449c1b3916..1575ec3bec 100644--- a/crates/openhuman-core/src/attachments/provider_owner.rs+++ b/crates/openhuman-core/src/attachments/provider_owner.rs@@ -149,18 +149,18 @@ impl MediaFallbackRenderer<AttachmentAccessScope> for AttachmentModel {attachment: &ResolvedAttachment,) -> Result<Option<String>, String> {if modality == InputModality::Image {- let key = self.fallback_key(&attachment.name, &attachment.mime, &attachment.bytes);- if let Some(text) = self.cached_fallback(&attachment.name, &key, _scope).await {+ if let Some(text) = MediaFallbackCache::get(self, _scope, modality, attachment).await {return Ok(Some(text));}let text = format!(- "Image readout (untrusted):\n{}",+ "{}\nImage readout:\n{}",+ attachment_header(attachment),self.image_readout(&attachment.mime, &attachment.bytes).await.map_err(|error| error.to_string())?);let text = self.limit_context(text);- self.save_fallback(&attachment.name, &key, &text, _scope).await;+ MediaFallbackCache::put(self, _scope, modality, attachment, &text).await;return Ok(Some(text));}#[cfg(feature = "documents")]@@ -169,17 +169,16 @@ impl MediaFallbackRenderer<AttachmentAccessScope> for AttachmentModel {| "application/vnd.openxmlformats-officedocument.presentationml.presentation"| "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"){- let key = self.fallback_key(&attachment.name, &attachment.mime, &attachment.bytes);- if let Some(text) = self.cached_fallback(&attachment.name, &key, _scope).await {+ if let Some(text) = MediaFallbackCache::get(self, _scope, modality, attachment).await {return Ok(Some(text));}- let (text, cacheable) = self.document_fallback(- &attachment.name,+ let (body, cacheable) = self.document_fallback(&attachment.mime,&attachment.bytes,).await.map_err(|error| error.to_string())?;+ let text = format!("{}\n{body}", attachment_header(attachment));if cacheable {- self.save_fallback(&attachment.name, &key, &text, _scope).await;+ MediaFallbackCache::put(self, _scope, modality, attachment, &text).await;}return Ok(Some(text));}@@ -187,6 +186,13 @@ impl MediaFallbackRenderer<AttachmentAccessScope> for AttachmentModel {}}+fn attachment_header(attachment: &ResolvedAttachment) -> String {+ format!(+ "[Attachment: {}; {} bytes; workspace path: {}]",+ attachment.mime, attachment.size_bytes, attachment.name+ )+}+#[async_trait]impl MediaFallbackCache<AttachmentAccessScope> for AttachmentModel {async fn get(@@ -201,9 +207,7 @@ impl MediaFallbackCache<AttachmentAccessScope> for AttachmentModel {}let text = self.cached_fallback(&attachment.name, &key, scope).await?;if let Ok(mut cache) = self.fallback_cache.lock() {- if cache.len() < 16 {- cache.insert(key, text.clone());- }+ cache.insert(key, text.clone());}Some(text)}@@ -217,9 +221,7 @@ impl MediaFallbackCache<AttachmentAccessScope> for AttachmentModel {) {let key = self.fallback_key(&attachment.name, &attachment.mime, &attachment.bytes);if let Ok(mut cache) = self.fallback_cache.lock() {- if cache.len() < 16 {- cache.insert(key.clone(), text.to_owned());- }+ cache.insert(key.clone(), text.to_owned());}self.save_fallback(&attachment.name, &key, text, scope).await;}diff --git a/crates/openhuman-core/src/attachments/provider_routing_tests.rs b/crates/openhuman-core/src/attachments/provider_routing_tests.rsindex 97208dbfdd..dfbb7ec4e1 100644--- a/crates/openhuman-core/src/attachments/provider_routing_tests.rs+++ b/crates/openhuman-core/src/attachments/provider_routing_tests.rs@@ -380,6 +380,9 @@ async fn paid_vision_readout_is_reused_across_recreated_wrappers_and_invalidatedassert!(call.messages[0].text().contains("Image readout:\nmock vision readout"));+ assert!(call.messages[0]+ .text()+ .contains("workspace path: uploads/thread/image/original.jpg"));let Message::User(user) = &call.messages[0] else {panic!("expected main user message")};@@ -393,6 +396,37 @@ async fn paid_vision_readout_is_reused_across_recreated_wrappers_and_invalidated);}+#[tokio::test]+async fn image_readout_for_unmanaged_sources_uses_the_wrapper_memory_cache() {+ let temp = tempfile::tempdir().unwrap();+ let source = "outside-uploads.jpg";+ tokio::fs::write(temp.path().join(source), b"\xff\xd8\xff\xe0same image")+ .await+ .unwrap();+ let config = offline_config(temp.path());+ let mut vision = CaptureModel::new(vec![InputModality::Image]);+ vision.profile.provider = Some("injected".into());+ vision.profile.modalities.image_in = true;+ vision.reply = "mock vision readout";+ let vision = Arc::new(vision);+ let _override =+ crate::inference::provider::factory::test_provider_override::install_model(vision.clone());+ let model = controlled_wrapper(Arc::new(CaptureModel::new(vec![])), config, &[]);+ let request = user_request(vec![ContentBlock::Image(ImageRef {+ url: source.into(),+ mime_type: Some("image/jpeg".into()),+ })]);++ model.invoke(&(), request.clone()).await.unwrap();+ model.invoke(&(), request).await.unwrap();++ assert_eq!(vision.requests.lock().unwrap().len(), 1);+ assert!(!temp+ .path()+ .join(".openhuman-derived/readout.txt")+ .exists());+}+#[tokio::test]async fn streaming_prepares_only_the_ephemeral_request_and_preserves_order_and_options() {let temp = tempfile::tempdir().unwrap();