Skip to content

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

style: apply rustfmt import ordering and assertion formatting

Steven Enamakel0229ca52064f
diff --git a/crates/openhuman-core/src/agent/attachments/host.rs b/crates/openhuman-core/src/agent/attachments/host.rs
index a6e00d1859..2d90e79c59 100644
--- a/crates/openhuman-core/src/agent/attachments/host.rs
+++ b/crates/openhuman-core/src/agent/attachments/host.rs
@@ -14,7 +14,7 @@ use std::path::Path;
use tinyagents_harness::multimodal::mime::detect_file_mime;
-use super::{save, AttachmentAccessScope};
+use super::{AttachmentAccessScope, save};
use crate::config::Config;
/// One file a host attaches to a turn.
diff --git a/crates/openhuman-core/src/agent/attachments/host_tests.rs b/crates/openhuman-core/src/agent/attachments/host_tests.rs
index c34232ca8d..d90991643c 100644
--- a/crates/openhuman-core/src/agent/attachments/host_tests.rs
+++ b/crates/openhuman-core/src/agent/attachments/host_tests.rs
@@ -75,18 +75,21 @@ async fn references_convert_to_image_and_document_blocks() {
let Message::User(user) = message else {
panic!("not a user message");
};
- assert!(user
- .content
- .iter()
- .any(|block| matches!(block, ContentBlock::Image(_))));
- assert!(user
- .content
- .iter()
- .any(|block| matches!(block, ContentBlock::Document(_))));
- assert!(user
- .content
- .iter()
- .any(|block| matches!(block, ContentBlock::Text(text) if text.contains("what is this?"))));
+ assert!(
+ user.content
+ .iter()
+ .any(|block| matches!(block, ContentBlock::Image(_)))
+ );
+ assert!(
+ user.content
+ .iter()
+ .any(|block| matches!(block, ContentBlock::Document(_)))
+ );
+ assert!(
+ user.content.iter().any(
+ |block| matches!(block, ContentBlock::Text(text) if text.contains("what is this?"))
+ )
+ );
}
#[tokio::test]
diff --git a/crates/openhuman-core/src/agent/attachments/mod.rs b/crates/openhuman-core/src/agent/attachments/mod.rs
index b93769b3ea..6eb1f57b85 100644
--- a/crates/openhuman-core/src/agent/attachments/mod.rs
+++ b/crates/openhuman-core/src/agent/attachments/mod.rs
@@ -6,7 +6,7 @@ use std::path::{Component, Path, PathBuf};
use serde::{Deserialize, Serialize};
use tinyagents_harness::multimodal::{
- config::FileLimits, markers, resolve::resolve_attachment, UnknownMimePolicy,
+ UnknownMimePolicy, config::FileLimits, markers, resolve::resolve_attachment,
};
use crate::config::Config;
diff --git a/crates/openhuman-core/src/agent/attachments/mod_access_tests.rs b/crates/openhuman-core/src/agent/attachments/mod_access_tests.rs
index 8bd5225cfc..8ef4bf3122 100644
--- a/crates/openhuman-core/src/agent/attachments/mod_access_tests.rs
+++ b/crates/openhuman-core/src/agent/attachments/mod_access_tests.rs
@@ -55,15 +55,17 @@ async fn direct_upload_requires_runtime_authority_and_external_input_cannot_crea
..Config::default()
};
let workspace = tinytools::WorkspaceDescriptor::new(temp.path().join("agent-acting"));
- assert!(stage_turn(
- UPLOAD,
- Some(&config),
- Some(&workspace),
- Some("thread"),
- Some(&external_origin())
- )
- .await
- .is_err());
+ assert!(
+ stage_turn(
+ UPLOAD,
+ Some(&config),
+ Some(&workspace),
+ Some("thread"),
+ Some(&external_origin())
+ )
+ .await
+ .is_err()
+ );
assert!(!workspace.root.exists());
assert!(!config.action_dir.exists());
assert_eq!(
@@ -95,15 +97,17 @@ async fn delegation_rejects_malformed_explicit_paths_and_external_reads_before_c
serde_json::json!(["picture.png] injected"]),
serde_json::json!(["picture\u{0}.png"]),
] {
- assert!(delegation_prompt(
- &crate::core::runtime::DispatchCtx::ambient(),
- "task",
- &serde_json::json!({"image_paths": image_paths}),
- None,
- None
- )
- .await
- .is_err());
+ assert!(
+ delegation_prompt(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ "task",
+ &serde_json::json!({"image_paths": image_paths}),
+ None,
+ None
+ )
+ .await
+ .is_err()
+ );
}
let error = delegation_prompt(
&crate::core::runtime::DispatchCtx::ambient(),
@@ -180,14 +184,16 @@ async fn thread_folder_upload_is_staged_where_the_turn_reads_it() {
}
// A folder that disappeared is an error, as in `run_task`, not a silent
// fallback to the global dir.
- assert!(thread_action_dir(
- &crate::core::runtime::DispatchCtx::ambient(),
- &config,
- &config.workspace_dir,
- Some("gone")
- )
- .await
- .is_err());
+ assert!(
+ thread_action_dir(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ &config.workspace_dir,
+ Some("gone")
+ )
+ .await
+ .is_err()
+ );
// Stage the way `start_chat` does, then read the way the turn does: its
// request scope comes from a run context carrying the thread folder as its
diff --git a/crates/openhuman-core/src/agent/attachments/mod_tests.rs b/crates/openhuman-core/src/agent/attachments/mod_tests.rs
index 4d4cfa8967..5e8e06c0dd 100644
--- a/crates/openhuman-core/src/agent/attachments/mod_tests.rs
+++ b/crates/openhuman-core/src/agent/attachments/mod_tests.rs
@@ -14,9 +14,11 @@ async fn legacy_sidecar_rehydrates_into_an_authorized_acting_original() {
let bytes = b"\x89PNG\r\n\x1a\noriginal";
tokio::fs::write(&source, bytes).await.unwrap();
let scope = AttachmentAccessScope::default();
- assert!(resolve_path(&cfg, source.to_str().unwrap(), &scope)
- .await
- .is_err());
+ assert!(
+ resolve_path(&cfg, source.to_str().unwrap(), &scope)
+ .await
+ .is_err()
+ );
let index = std::collections::HashMap::from([("legacy".into(), source.clone())]);
let prompt = markers::rehydrate_placeholders_in_text("[Image: old #att:legacy]", &index);
let paths = markers::parse_image_markers(&prompt).1;
@@ -168,16 +170,18 @@ async fn forbidden_acting_root_is_rejected_before_directory_creation() {
let temp = tempfile::tempdir().unwrap();
let mut config = config(temp.path());
config.action_dir = temp.path().join(".ssh").join("new-workspace");
- assert!(save(
- &config,
- "thread",
- "file",
- "text/plain",
- b"data",
- &AttachmentAccessScope::default()
- )
- .await
- .is_err());
+ assert!(
+ save(
+ &config,
+ "thread",
+ "file",
+ "text/plain",
+ b"data",
+ &AttachmentAccessScope::default()
+ )
+ .await
+ .is_err()
+ );
assert!(!temp.path().join(".ssh").exists());
}
@@ -226,13 +230,15 @@ async fn ready_media_artifact_in_files_folder_can_be_attached() {
tokio::fs::write(&unrelated, b"not a filed media artifact")
.await
.unwrap();
- assert!(resolve_path(
- &config,
- &unrelated.to_string_lossy(),
- &AttachmentAccessScope::default(),
- )
- .await
- .is_err());
+ assert!(
+ resolve_path(
+ &config,
+ &unrelated.to_string_lossy(),
+ &AttachmentAccessScope::default(),
+ )
+ .await
+ .is_err()
+ );
}
#[tokio::test]
@@ -339,22 +345,26 @@ async fn hard_zero_and_count_gate_precede_reads() {
let temp = tempfile::tempdir().unwrap();
let mut config = config(temp.path());
config.multimodal_files.max_files = 0;
- assert!(stage(
- "[FILE:/missing]",
- "thread",
- &config,
- &AttachmentAccessScope::default()
- )
- .await
- .is_err());
- assert!(stage(
- "[IMAGE:/missing]",
- "thread",
- &config,
- &AttachmentAccessScope::default()
- )
- .await
- .is_err());
+ assert!(
+ stage(
+ "[FILE:/missing]",
+ "thread",
+ &config,
+ &AttachmentAccessScope::default()
+ )
+ .await
+ .is_err()
+ );
+ assert!(
+ stage(
+ "[IMAGE:/missing]",
+ "thread",
+ &config,
+ &AttachmentAccessScope::default()
+ )
+ .await
+ .is_err()
+ );
assert!(!config.action_dir.exists());
assert!(!safe_relative_path("../escape"));
assert!(!safe_relative_path("/absolute"));
@@ -363,23 +373,27 @@ async fn hard_zero_and_count_gate_precede_reads() {
#[tokio::test]
async fn vision_without_explicit_references_fails_before_configuration_or_inference() {
- assert!(!has_resolvable_image(
- &crate::core::runtime::DispatchCtx::ambient(),
- "Describe a filename mentioned only in prose: picture.png",
- None,
- None
- )
- .await
- .unwrap());
- assert!(delegation_prompt(
- &crate::core::runtime::DispatchCtx::ambient(),
- "task",
- &serde_json::json!({ "image_paths": [42] }),
- None,
- None
- )
- .await
- .is_err());
+ assert!(
+ !has_resolvable_image(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ "Describe a filename mentioned only in prose: picture.png",
+ None,
+ None
+ )
+ .await
+ .unwrap()
+ );
+ assert!(
+ delegation_prompt(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ "task",
+ &serde_json::json!({ "image_paths": [42] }),
+ None,
+ None
+ )
+ .await
+ .is_err()
+ );
}
#[cfg(unix)]
@@ -391,16 +405,18 @@ async fn upload_symlink_is_rejected_without_writing_outside() {
let outside = temp.path().join("outside");
tokio::fs::create_dir(&outside).await.unwrap();
std::os::unix::fs::symlink(&outside, config.action_dir.join("uploads")).unwrap();
- assert!(save(
- &config,
- "thread",
- "file",
- "application/octet-stream",
- b"original",
- &AttachmentAccessScope::default()
- )
- .await
- .is_err());
+ assert!(
+ save(
+ &config,
+ "thread",
+ "file",
+ "application/octet-stream",
+ b"original",
+ &AttachmentAccessScope::default()
+ )
+ .await
+ .is_err()
+ );
assert_eq!(std::fs::read_dir(outside).unwrap().count(), 0);
}
diff --git a/crates/openhuman-core/src/agent/attachments/parts.rs b/crates/openhuman-core/src/agent/attachments/parts.rs
index 37f7e2f4cb..426ffea96a 100644
--- a/crates/openhuman-core/src/agent/attachments/parts.rs
+++ b/crates/openhuman-core/src/agent/attachments/parts.rs
@@ -123,7 +123,7 @@ pub fn fold_into_message(text: &str, parts: &[ContentPart]) -> Result<String, At
return Err(AttachmentPartError::UnsupportedKind {
index,
kind: kind_name(other),
- })
+ });
}
}
}
diff --git a/crates/openhuman-core/src/agent/attachments/provider.rs b/crates/openhuman-core/src/agent/attachments/provider.rs
index 5d6ac8900a..ad271ef555 100644
--- a/crates/openhuman-core/src/agent/attachments/provider.rs
+++ b/crates/openhuman-core/src/agent/attachments/provider.rs
@@ -2,7 +2,7 @@
use super::AttachmentAccessScope;
use crate::config::Config;
use async_trait::async_trait;
-use base64::{engine::general_purpose::STANDARD, Engine};
+use base64::{Engine, engine::general_purpose::STANDARD};
use std::sync::Arc;
use tinyinference_llm::{
message::{ContentBlock, ImageRef, MediaRef, Message},
diff --git a/crates/openhuman-core/src/agent/attachments/provider_history_tests.rs b/crates/openhuman-core/src/agent/attachments/provider_history_tests.rs
index 90b38cc22c..43ae285aea 100644
--- a/crates/openhuman-core/src/agent/attachments/provider_history_tests.rs
+++ b/crates/openhuman-core/src/agent/attachments/provider_history_tests.rs
@@ -57,23 +57,31 @@ async fn missing_historical_media_does_not_block_latest_valid_media() {
let captured = probe.requests.lock().unwrap().clone();
assert_eq!(captured.len(), 1);
let history = &captured[0].messages[0];
- assert!(history
- .text()
- .contains("Earlier attachment omitted by history budget"));
+ assert!(
+ history
+ .text()
+ .contains("Earlier attachment omitted by history budget")
+ );
assert!(history.text().contains("Earlier attachment unavailable"));
assert!(history.text().contains("deleted-prior-upload-0.png"));
assert!(!serde_json::to_string(history).unwrap().contains("base64"));
- assert!(!serde_json::to_string(history)
- .unwrap()
- .contains("private-value"));
- assert!(!serde_json::to_string(history)
- .unwrap()
- .contains("also-private"));
+ assert!(
+ !serde_json::to_string(history)
+ .unwrap()
+ .contains("private-value")
+ );
+ assert!(
+ !serde_json::to_string(history)
+ .unwrap()
+ .contains("also-private")
+ );
let durable_text = serde_json::to_string(&durable).unwrap();
assert!(signed_urls.iter().all(|url| durable_text.contains(url)));
- assert!(serde_json::to_string(&captured[0].messages[1])
- .unwrap()
- .contains("data:image/png;base64,"));
+ assert!(
+ serde_json::to_string(&captured[0].messages[1])
+ .unwrap()
+ .contains("data:image/png;base64,")
+ );
}
#[cfg(unix)]
diff --git a/crates/openhuman-core/src/agent/attachments/provider_open.rs b/crates/openhuman-core/src/agent/attachments/provider_open.rs
index e40654dd1b..bf8a982dae 100644
--- a/crates/openhuman-core/src/agent/attachments/provider_open.rs
+++ b/crates/openhuman-core/src/agent/attachments/provider_open.rs
@@ -100,7 +100,7 @@ pub(crate) fn secure_open(
) -> std::io::Result<std::fs::File> {
use std::os::windows::io::AsRawHandle;
use windows_sys::Win32::Storage::FileSystem::{
- GetFinalPathNameByHandleW, FILE_NAME_NORMALIZED, VOLUME_NAME_DOS,
+ FILE_NAME_NORMALIZED, GetFinalPathNameByHandleW, VOLUME_NAME_DOS,
};
use std::os::windows::ffi::OsStringExt;
diff --git a/crates/openhuman-core/src/agent/attachments/provider_routing_tests.rs b/crates/openhuman-core/src/agent/attachments/provider_routing_tests.rs
index 3cbc38d4fa..d9cbf53330 100644
--- a/crates/openhuman-core/src/agent/attachments/provider_routing_tests.rs
+++ b/crates/openhuman-core/src/agent/attachments/provider_routing_tests.rs
@@ -285,16 +285,19 @@ async fn paid_vision_readout_is_reused_across_recreated_wrappers_and_invalidated
let calls = main.requests.lock().unwrap().clone();
assert_eq!(calls.len(), 3);
for (_, call) in &calls {
- assert!(call.messages[0]
- .text()
- .contains("Image readout:\nmock vision readout"));
+ assert!(
+ call.messages[0]
+ .text()
+ .contains("Image readout:\nmock vision readout")
+ );
let Message::User(user) = &call.messages[0] else {
panic!("expected main user message")
};
- assert!(user
- .content
- .iter()
- .all(|block| matches!(block, ContentBlock::Text(_))));
+ assert!(
+ user.content
+ .iter()
+ .all(|block| matches!(block, ContentBlock::Text(_)))
+ );
}
assert!(
matches!(&request.messages[0], Message::User(user) if matches!(&user.content[0], ContentBlock::Image(image) if image.url == "uploads/thread/image/original.jpg"))
@@ -336,13 +339,15 @@ async fn streaming_prepares_only_the_ephemeral_request_and_preserves_order_and_o
request.temperature = Some(0.37);
request.max_tokens = Some(128);
let durable = serde_json::to_value(&request).unwrap();
- assert!(model
- .stream(&(), request.clone())
- .await
- .unwrap()
- .collect::<Vec<_>>()
- .await
- .is_empty());
+ assert!(
+ model
+ .stream(&(), request.clone())
+ .await
+ .unwrap()
+ .collect::<Vec<_>>()
+ .await
+ .is_empty()
+ );
assert_eq!(serde_json::to_value(&request).unwrap(), durable);
let captured = transport.requests.lock().unwrap().clone();
assert_eq!(captured.len(), 1);
@@ -474,8 +479,10 @@ async fn unsupported_media_urls_and_oversized_inline_sources_fail_before_inferen
media_type: "application/octet-stream".into(),
})]);
let error = model.prepare(oversized).await.unwrap_err();
- assert!(error
- .to_string()
- .contains("inline media exceeds size limit"));
+ assert!(
+ error
+ .to_string()
+ .contains("inline media exceeds size limit")
+ );
assert!(transport.requests.lock().unwrap().is_empty());
}
diff --git a/crates/openhuman-core/src/agent/attachments/provider_source.rs b/crates/openhuman-core/src/agent/attachments/provider_source.rs
index 8445ba7508..588a4209ef 100644
--- a/crates/openhuman-core/src/agent/attachments/provider_source.rs
+++ b/crates/openhuman-core/src/agent/attachments/provider_source.rs
@@ -1,10 +1,10 @@
//! Resolve every admitted media source on a disposable provider request.
-use super::super::{is_missing_local_reference, SOURCE_MISSING_MARKER};
+use super::super::{SOURCE_MISSING_MARKER, is_missing_local_reference};
use super::AttachmentAccessScope;
use super::*;
use sha2::{Digest, Sha256};
use tinyagents_harness::multimodal::{
- config::FileLimits, resolve::resolve_attachment, UnknownMimePolicy,
+ UnknownMimePolicy, config::FileLimits, resolve::resolve_attachment,
};
impl AttachmentModel {
diff --git a/crates/openhuman-core/src/agent/attachments/provider_tests.rs b/crates/openhuman-core/src/agent/attachments/provider_tests.rs
index a095e790df..1f0a56a05d 100644
--- a/crates/openhuman-core/src/agent/attachments/provider_tests.rs
+++ b/crates/openhuman-core/src/agent/attachments/provider_tests.rs
@@ -51,14 +51,18 @@ async fn local_native_resolution_changes_only_ephemeral_request() {
)]);
let durable = request.clone();
assert!(wrapper.invoke(&(), request).await.is_err());
- assert!(serde_json::to_string(&durable)
- .unwrap()
- .contains("sample.png"));
+ assert!(
+ serde_json::to_string(&durable)
+ .unwrap()
+ .contains("sample.png")
+ );
let captured = probe.requests.lock().unwrap().clone();
assert_eq!(captured.len(), 1);
- assert!(serde_json::to_string(&captured[0])
- .unwrap()
- .contains("data:image/png;base64,"));
+ assert!(
+ serde_json::to_string(&captured[0])
+ .unwrap()
+ .contains("data:image/png;base64,")
+ );
assert_eq!(
tokio::fs::read(temp.path().join("sample.png"))
.await
@@ -130,9 +134,11 @@ async fn persisted_image_without_mime_uses_magic_over_extension() {
assert!(wrapper.invoke(&(), request).await.is_err());
let captured = probe.requests.lock().unwrap().clone();
assert_eq!(captured.len(), 1);
- assert!(serde_json::to_string(&captured[0])
- .unwrap()
- .contains("data:image/jpeg;base64,"));
+ assert!(
+ serde_json::to_string(&captured[0])
+ .unwrap()
+ .contains("data:image/jpeg;base64,")
+ );
}
#[tokio::test]
@@ -227,9 +233,11 @@ async fn unknown_video_retains_path_as_metadata_without_specialist() {
let text = captured[0].messages[0].text();
assert!(text.contains("clip.mp4"));
assert!(text.contains("14 bytes"));
- assert!(!serde_json::to_string(&captured[0])
- .unwrap()
- .contains("base64"));
+ assert!(
+ !serde_json::to_string(&captured[0])
+ .unwrap()
+ .contains("base64")
+ );
}
#[tokio::test]
@@ -270,18 +278,22 @@ async fn derivative_cache_survives_model_recreation_and_invalidates_changed_cont
Some("derived readout")
);
let changed = first.fallback_key("uploads/thread/id/original.txt", "text/plain", b"modified");
- assert!(resumed
- .cached_fallback("uploads/thread/id/original.txt", &changed, &scope)
- .await
- .is_none());
+ assert!(
+ resumed
+ .cached_fallback("uploads/thread/id/original.txt", &changed, &scope)
+ .await
+ .is_none()
+ );
assert_eq!(tokio::fs::read(original).await.unwrap(), b"original");
- assert!(tokio::fs::read_dir(temp.path().join("uploads/thread/id"))
- .await
- .unwrap()
- .next_entry()
- .await
- .unwrap()
- .is_some());
+ assert!(
+ tokio::fs::read_dir(temp.path().join("uploads/thread/id"))
+ .await
+ .unwrap()
+ .next_entry()
+ .await
+ .unwrap()
+ .is_some()
+ );
}
#[tokio::test]
@@ -313,7 +325,7 @@ async fn cache_is_not_written_beside_unmanaged_local_files() {
#[test]
fn endpoint_discovery_denial_overrides_offline_vision_facts() {
use crate::config::schema::cloud_providers::{AuthStyle, CloudProviderCreds};
- use tinyinference_llm::model::discover::{model_limits_cache, LimitSource, ModelLimits};
+ use tinyinference_llm::model::discover::{LimitSource, ModelLimits, model_limits_cache};
let temp = tempfile::tempdir().unwrap();
let mut config = Config::default();
config.config_path = temp.path().join("config.toml");
@@ -409,9 +421,11 @@ async fn disabled_remote_replay_is_rejected_before_inference() {
},
)]);
let error = wrapper.invoke(&(), request).await.unwrap_err();
- assert!(error
- .to_string()
- .contains("remote attachment fetch is disabled"));
+ assert!(
+ error
+ .to_string()
+ .contains("remote attachment fetch is disabled")
+ );
}
assert!(probe.requests.lock().unwrap().is_empty());
}
@@ -564,12 +578,16 @@ async fn unknown_model_legacy_inline_replay_uses_specialist_once_across_model_re
assert!(wrapper.invoke(&(), request.clone()).await.is_err());
let captured = main.requests.lock().unwrap().clone();
assert_eq!(captured.len(), 1);
- assert!(captured[0].messages[0]
- .text()
- .contains("specialist image readout"));
- assert!(!serde_json::to_string(&captured[0])
- .unwrap()
- .contains("base64"));
+ assert!(
+ captured[0].messages[0]
+ .text()
+ .contains("specialist image readout")
+ );
+ assert!(
+ !serde_json::to_string(&captured[0])
+ .unwrap()
+ .contains("base64")
+ );
}
assert_eq!(
specialist.calls.load(std::sync::atomic::Ordering::SeqCst),
@@ -604,9 +622,11 @@ async fn legacy_audio_base64_unsupported_transport_becomes_workspace_reference()
let text = captured[0].messages[0].text();
assert!(text.contains("audio/wav"));
assert!(text.contains("workspace path: uploads/legacy-media/"));
- assert!(!serde_json::to_string(&captured[0])
- .unwrap()
- .contains("base64"));
+ assert!(
+ !serde_json::to_string(&captured[0])
+ .unwrap()
+ .contains("base64")
+ );
}
#[tokio::test]
@@ -640,9 +660,11 @@ async fn injected_turn_source_uses_bound_workspace_and_explicit_model_facts() {
assert!(models.primary.invoke(&(), request).await.is_err());
let captured = probe.requests.lock().unwrap().clone();
assert_eq!(captured.len(), 1);
- assert!(serde_json::to_string(&captured[0])
- .unwrap()
- .contains("data:image/png;base64,"));
+ assert!(
+ serde_json::to_string(&captured[0])
+ .unwrap()
+ .contains("data:image/png;base64,")
+ );
}
#[tokio::test]
@@ -701,9 +723,11 @@ async fn configured_injected_builder_stages_and_resolves_in_explicit_acting_work
assert!(models.primary.invoke(&(), request).await.is_err());
let captured = probe.requests.lock().unwrap().clone();
assert_eq!(captured.len(), 1);
- assert!(serde_json::to_string(&captured[0])
- .unwrap()
- .contains("data:image/png;base64,"));
+ assert!(
+ serde_json::to_string(&captured[0])
+ .unwrap()
+ .contains("data:image/png;base64,")
+ );
}
#[test]
diff --git a/crates/openhuman-core/src/agent/message_convert_tests.rs b/crates/openhuman-core/src/agent/message_convert_tests.rs
index 3466bdfb32..3d0c9d5140 100644
--- a/crates/openhuman-core/src/agent/message_convert_tests.rs
+++ b/crates/openhuman-core/src/agent/message_convert_tests.rs
@@ -37,6 +37,79 @@ fn stored_typed_media_rejects_unresolved_paths() {
assert!(user_message_from_parts("image", &[part]).is_err());
}
+#[test]
+fn typed_native_parts_preserve_text_voice_transcript_and_file_order() {
+ let parts = vec![
+ tinychannels_bus::ContentPart::Text {
+ text: "before".into(),
+ markdown_dialect: None,
+ },
+ tinychannels_bus::ContentPart::VoiceNote {
+ voice_note: tinychannels_bus::VoiceNote {
+ transcript: Some(tinychannels_bus::VoiceTranscript {
+ text: "spoken words".into(),
+ language: Some("en".into()),
+ state: tinychannels_bus::VoiceTranscriptState::Complete,
+ source: tinychannels_bus::VoiceTranscriptSource::Provider,
+ }),
+ ..Default::default()
+ },
+ },
+ tinychannels_bus::ContentPart::File {
+ media: tinychannels_bus::MediaReference {
+ path: Some("uploads/thread/document.txt".into()),
+ content_type: Some("text/plain".into()),
+ ..Default::default()
+ },
+ file_name: Some("document.txt".into()),
+ caption: Some("after voice".into()),
+ },
+ ];
+ let Message::User(user) = user_message_from_parts("", &parts).unwrap() else {
+ panic!("user message expected")
+ };
+ assert!(matches!(&user.content[0], ContentBlock::Text(text) if text == "before"));
+ assert!(matches!(&user.content[1], ContentBlock::Text(text) if text == "spoken words"));
+ assert!(matches!(&user.content[2], ContentBlock::Text(text) if text == "after voice"));
+ assert!(matches!(
+ &user.content[3],
+ ContentBlock::Document(MediaRef::Path { path, .. }) if path == "uploads/thread/document.txt"
+ ));
+}
+
+#[test]
+fn typed_native_parts_reject_unavailable_voice_and_unsupported_audio_video() {
+ let incomplete = tinychannels_bus::ContentPart::VoiceNote {
+ voice_note: tinychannels_bus::VoiceNote {
+ transcript: Some(tinychannels_bus::VoiceTranscript {
+ text: "partial".into(),
+ language: None,
+ state: tinychannels_bus::VoiceTranscriptState::Pending,
+ source: tinychannels_bus::VoiceTranscriptSource::HostStt,
+ }),
+ ..Default::default()
+ },
+ };
+ assert!(user_message_from_parts("", &[incomplete]).is_err());
+
+ let audio = tinychannels_bus::ContentPart::Audio {
+ media: tinychannels_bus::MediaReference::default(),
+ codec: None,
+ duration_ms: None,
+ title: None,
+ transcript: None,
+ };
+ assert!(user_message_from_parts("", &[audio]).is_err());
+
+ let video = tinychannels_bus::ContentPart::Video {
+ media: tinychannels_bus::MediaReference::default(),
+ caption: None,
+ duration_ms: None,
+ thumbnail: None,
+ };
+ assert!(user_message_from_parts("", &[video]).is_err());
+}
+
#[test]
fn durable_upload_parts_survive_message_row_replay_without_inline_payloads() {
let mut text = String::from("Inspect these files");
@@ -61,18 +134,21 @@ fn durable_upload_parts_survive_message_row_replay_without_inline_payloads() {
let Message::User(user) = replay else {
panic!("user row expected")
};
- assert!(user
- .content
- .iter()
- .any(|part| matches!(part, ContentBlock::Audio(MediaRef::Path { .. }))));
- assert!(user
- .content
- .iter()
- .any(|part| matches!(part, ContentBlock::Video(MediaRef::Path { .. }))));
- assert!(user
- .content
- .iter()
- .any(|part| matches!(part, ContentBlock::Document(MediaRef::Path { .. }))));
+ assert!(
+ user.content
+ .iter()
+ .any(|part| matches!(part, ContentBlock::Audio(MediaRef::Path { .. })))
+ );
+ assert!(
+ user.content
+ .iter()
+ .any(|part| matches!(part, ContentBlock::Video(MediaRef::Path { .. })))
+ );
+ assert!(
+ user.content
+ .iter()
+ .any(|part| matches!(part, ContentBlock::Document(MediaRef::Path { .. })))
+ );
assert!(!serde_json::to_string(&row).unwrap().contains("base64"));
}
use tinyinference_llm::model::ModelRequest;
@@ -339,10 +415,12 @@ fn reasoning_content_uses_typed_thinking_block_and_round_trips_metadata() {
ContentBlock::Thinking { text, signature: None } if text == "private thoughts"
)
}));
- assert!(!assistant
- .content
- .iter()
- .any(|block| matches!(block, ContentBlock::ProviderExtension(_))));
+ assert!(
+ !assistant
+ .content
+ .iter()
+ .any(|block| matches!(block, ContentBlock::ProviderExtension(_)))
+ );
let back = message_to_chat_message(&msg).expect("assistant converts");
assert_eq!(back.content, "visible answer");
diff --git a/crates/openhuman-core/src/agent/queued_turn.rs b/crates/openhuman-core/src/agent/queued_turn.rs
index a4f43babb0..232fb25166 100644
--- a/crates/openhuman-core/src/agent/queued_turn.rs
+++ b/crates/openhuman-core/src/agent/queued_turn.rs
@@ -73,7 +73,10 @@ impl std::fmt::Debug for QueuedPayload {
"has_pending_attachments",
&self.pending_attachments.is_some(),
)
- .field("has_native_message_input", &self.native_message_input.is_some())
+ .field(
+ "has_native_message_input",
+ &self.native_message_input.is_some(),
+ )
.finish_non_exhaustive()
}
}
diff --git a/crates/openhuman-core/src/agent/queued_turn_tests.rs b/crates/openhuman-core/src/agent/queued_turn_tests.rs
index 32f74ee9d5..b999ee3d8f 100644
--- a/crates/openhuman-core/src/agent/queued_turn_tests.rs
+++ b/crates/openhuman-core/src/agent/queued_turn_tests.rs
@@ -178,6 +178,9 @@ fn requeue_adopts_context_but_never_predecessor_message_or_attachment_state() {
persisted_message_id: "user:prior-image".into(),
parts: vec![],
}),
+ native_message_input: Some(tinyinference_llm::message::Message::user(
+ "prior request typed content",
+ )),
..Default::default()
};
let mut next = QueuedPayload {
@@ -194,4 +197,5 @@ fn requeue_adopts_context_but_never_predecessor_message_or_attachment_state() {
assert!(!next.deferred_user_message);
assert!(next.pending_attachments.is_none());
assert!(next.stored_attachments.is_none());
+ assert!(next.native_message_input.is_none());
}
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs
index 1302a91dd6..9fde422116 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs
@@ -7,13 +7,13 @@ use std::{
use async_trait::async_trait;
use tinyagents_harness::{
+ CancellationToken,
run_queue::RunQueue,
turn_runner::{
EventSink, FailureClassification, FailureClassifier, IngressDecision, IngressPolicy,
IngressStage, QueueDisposition, ReplyStore, ScopeKey, Summarizer, TerminalEvent, TurnHost,
TurnRequest, TurnResult, TurnRunner, TurnRunnerConfig, TurnSession, TurnSignal,
},
- CancellationToken,
};
use tokio::sync::mpsc;
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner_tests.rs
index 5f38967bb3..f0025a9ea8 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner_tests.rs
@@ -135,11 +135,13 @@ async fn queued_terminal_delivery_does_not_leave_a_completion_entry() {
shared.with("queued-request", |_| {});
shared.record_delivery("queued-request", true);
- assert!(shared
- .slots
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner())
- .is_empty());
+ assert!(
+ shared
+ .slots
+ .lock()
+ .unwrap_or_else(|poisoned| poisoned.into_inner())
+ .is_empty()
+ );
}
#[tokio::test]
@@ -149,11 +151,13 @@ async fn active_terminal_delivery_is_returned_to_its_waiting_caller() {
shared.record_delivery("active-request", true);
assert_eq!(shared.take_delivery("active-request"), Some(true));
- assert!(shared
- .slots
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner())
- .is_empty());
+ assert!(
+ shared
+ .slots
+ .lock()
+ .unwrap_or_else(|poisoned| poisoned.into_inner())
+ .is_empty()
+ );
}
#[tokio::test]
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs
index 67770808b1..114c265c62 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/bus_turn.rs
@@ -1,7 +1,7 @@
//! The orchestrator path: an unbound channel's turn goes over the native bus
//! to the `agent.run_turn` handler, with the orchestrator's tool scoping.
-use crate::agent::bus::{AgentTurnRequest, AgentTurnResponse, AGENT_RUN_TURN_METHOD};
+use crate::agent::bus::{AGENT_RUN_TURN_METHOD, AgentTurnRequest, AgentTurnResponse};
use crate::agent::turn_origin::AgentTurnOrigin;
use crate::channels::context::{ChannelRouteSelection, ChannelRuntimeContext};
use crate::core::bus::BUS;
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media.rs
index f13fba6118..a7a252e868 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media.rs
@@ -1,14 +1,14 @@
//! Resolve typed native-channel media through TinyChannels' scoped media port.
-use tinyinference_llm::message::Message;
+use tinybus::module::ModuleClient;
use tinychannels_bus::{
- module_media::{MediaReadBegin, MediaReadChunk, MediaReadFinish}, ChannelInboundEnvelope,
- ContentPart, HostVoiceScope, MediaKind, MediaReference,
+ ChannelInboundEnvelope, ContentPart, HostVoiceScope, MediaReference,
+ module_media::{MediaReadBegin, MediaReadChunk, MediaReadFinish},
};
-use tinybus::module::ModuleClient;
+use tinyinference_llm::message::Message;
use crate::{
- channels::context::{module_client, ChannelRuntimeContext},
+ channels::context::{ChannelRuntimeContext, module_client},
core::runtime::DispatchCtx,
};
@@ -76,7 +76,11 @@ pub(super) async fn resolve_typed_message(
let (media, image, name) = match part {
ContentPart::Image { media, .. } => {
image_count += 1;
- (media, true, media.file_name.clone().unwrap_or_else(|| "image".into()))
+ (
+ media,
+ true,
+ media.file_name.clone().unwrap_or_else(|| "image".into()),
+ )
}
ContentPart::File {
media, file_name, ..
@@ -118,14 +122,21 @@ pub(super) async fn resolve_typed_message(
image_mb.saturating_mul(1024 * 1024).min(MAX_MEDIA_BYTES)
} else {
if max_files == 0 || file_count > max_files {
- return Err("native file attachments are disabled or exceed their count limit".into());
+ return Err(
+ "native file attachments are disabled or exceed their count limit".into(),
+ );
}
file_mb.saturating_mul(1024 * 1024).min(MAX_MEDIA_BYTES)
};
if image_count > max_images {
return Err("native image attachments exceed their count limit".into());
}
- validate_reference(media, image, byte_limit, &config.multimodal_files.allowed_mime_types)?;
+ validate_reference(
+ media,
+ image,
+ byte_limit,
+ &config.multimodal_files.allowed_mime_types,
+ )?;
let bytes = read_scoped_media(
&client,
&dispatch,
@@ -140,11 +151,7 @@ pub(super) async fn resolve_typed_message(
.as_deref()
.ok_or_else(|| "native media has no content type".to_owned())?;
let staged = crate::agent::attachments::store_scoped_channel_media(
- config,
- thread_id,
- &name,
- mime,
- &bytes,
+ config, thread_id, &name, mime, &bytes,
)
.await
.map_err(|_| "native media could not be staged safely".to_owned())?;
@@ -185,7 +192,10 @@ fn validate_reference(
{
return Err("native media reference is not an opaque module reference".into());
}
- if media.size_bytes.is_some_and(|size| size == 0 || size > byte_limit as u64) {
+ if media
+ .size_bytes
+ .is_some_and(|size| size == 0 || size > byte_limit as u64)
+ {
return Err("native media exceeds its declared byte limit".into());
}
let mime = media
@@ -194,7 +204,10 @@ fn validate_reference(
.filter(|mime| !mime.trim().is_empty())
.ok_or_else(|| "native media has no content type".to_owned())?;
if image {
- if !matches!(mime, "image/png" | "image/jpeg" | "image/webp" | "image/gif") {
+ if !matches!(
+ mime,
+ "image/png" | "image/jpeg" | "image/webp" | "image/gif"
+ ) {
return Err("native image MIME type is unsupported".into());
}
} else if !allowed_file_mimes.iter().any(|allowed| allowed == mime) {
@@ -230,11 +243,15 @@ async fn read_scoped_media(
|| begin.byte_count > MAX_MEDIA_BYTES
|| begin.media.opaque_id != media.opaque_id
|| begin.content_type != media.content_type.as_deref().unwrap_or_default()
- || media.size_bytes.is_some_and(|size| size != begin.byte_count as u64)
+ || media
+ .size_bytes
+ .is_some_and(|size| size != begin.byte_count as u64)
{
return Err("native media read metadata does not match its scoped reference".into());
}
- let expected_chunks = begin.byte_count.div_ceil(tinychannels_bus::module_media::MEDIA_READ_CHUNK_BYTES);
+ let expected_chunks = begin
+ .byte_count
+ .div_ceil(tinychannels_bus::module_media::MEDIA_READ_CHUNK_BYTES);
if begin.chunk_count as usize != expected_chunks {
return Err("native media read chunk count is invalid".into());
}
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media_tests.rs
new file mode 100644
index 0000000000..14ca7e5be6
--- /dev/null
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media_tests.rs
@@ -0,0 +1,68 @@
+use super::*;
+use tinychannels_bus::{ChannelInboundEnvelope, MediaKind};
+
+fn reference() -> MediaReference {
+ MediaReference {
+ opaque_id: Some("opaque-media".into()),
+ content_type: Some("image/png".into()),
+ size_bytes: Some(32),
+ kind: MediaKind::Image,
+ ..Default::default()
+ }
+}
+
+#[test]
+fn native_media_requires_an_opaque_reference_and_rejects_provider_paths() {
+ let mut media = reference();
+ media.opaque_id = None;
+ assert!(validate_reference(&media, true, 1024, &[]).is_err());
+
+ let mut media = reference();
+ media.path = Some("/etc/passwd".into());
+ assert!(validate_reference(&media, true, 1024, &[]).is_err());
+
+ let mut media = reference();
+ media.url = Some("https://attacker.invalid/media".into());
+ assert!(validate_reference(&media, true, 1024, &[]).is_err());
+
+ let mut media = reference();
+ media.local_cache_path = Some("/tmp/private".into());
+ assert!(validate_reference(&media, true, 1024, &[]).is_err());
+}
+
+#[test]
+fn native_media_rejects_declared_oversize_and_unsupported_mime() {
+ let mut media = reference();
+ media.size_bytes = Some(1025);
+ assert!(validate_reference(&media, true, 1024, &[]).is_err());
+
+ let mut media = reference();
+ media.content_type = Some("image/svg+xml".into());
+ assert!(validate_reference(&media, true, 1024, &[]).is_err());
+
+ let mut file = reference();
+ file.content_type = Some("application/x-executable".into());
+ assert!(validate_reference(&file, false, 1024, &["text/plain".into()]).is_err());
+}
+
+#[test]
+fn typed_native_media_is_selected_only_from_envelope_parts() {
+ let envelope = ChannelInboundEnvelope {
+ parts: vec![ContentPart::Image {
+ media: reference(),
+ caption: None,
+ alt_text: None,
+ }],
+ ..Default::default()
+ };
+ assert!(requires_typed_preparation(&envelope));
+
+ let text_only = ChannelInboundEnvelope {
+ parts: vec![ContentPart::Text {
+ text: "ordinary text".into(),
+ markdown_dialect: None,
+ }],
+ ..Default::default()
+ };
+ assert!(!requires_typed_preparation(&text_only));
+}
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
index 59350fde63..aaabd58b17 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
@@ -1,7 +1,7 @@
//! The per-message pipeline: typing indicator, ACK reaction, durable-session
//! dispatch through the shared runner, and final reply delivery.
-use crate::channels::context::{is_context_window_overflow_error, ChannelRuntimeContext};
+use crate::channels::context::{ChannelRuntimeContext, is_context_window_overflow_error};
#[cfg(test)]
use crate::channels::routes::get_or_create_turn_model_source;
use crate::channels::routes::{get_route_selection, handle_runtime_command_with_reset};
@@ -15,12 +15,12 @@ use tokio_util::sync::CancellationToken;
use tokio_util::task::AbortOnDropHandle;
use super::super::helpers::{
- build_channel_context_block, log_worker_join_result, spawn_typing_task,
- REPLY_LOG_TRUNCATE_CHARS,
+ REPLY_LOG_TRUNCATE_CHARS, build_channel_context_block, log_worker_join_result,
+ spawn_typing_task,
};
use super::super::host_agent::{self, HostRoute};
-use super::approval::{channel_has_approval_surface, try_route_approval_reply};
use super::RuntimeChannelMessage;
+use super::approval::{channel_has_approval_surface, try_route_approval_reply};
fn channel_inbound_preparation_request(
source: tinychannels_bus::module_inbound::ChannelInboundSource,
@@ -96,8 +96,7 @@ pub(crate) async fn process_channel_runtime_message(
let mut envelope = prepared.envelope;
envelope.access.delivered_via_upstream_relay = authenticated_relay;
let native_message_input = if typed_envelope_input {
- match super::native_media::resolve_typed_message(&ctx, &envelope, &prepared.thread_id)
- .await
+ match super::native_media::resolve_typed_message(&ctx, &envelope, &prepared.thread_id).await
{
Ok(input) => input,
Err(error) => {
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn_tests.rs
index a681006a36..b6989b822e 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn_tests.rs
@@ -73,18 +73,20 @@ async fn native_inbound_preparation_preserves_image_envelope_for_typed_turns() {
),
)
.await;
- assert!(legacy.is_err(), "legacy callers must still reject rich-only input");
+ assert!(
+ legacy.is_err(),
+ "legacy callers must still reject rich-only input"
+ );
}
#[tokio::test]
async fn native_typed_preparation_preserves_ordered_voice_and_file_parts() {
use tinychannels_bus::{
channel::{
- ChannelRef, ContentPart, ConversationKind, ConversationRef, MediaKind,
- MediaReference, SenderRef, VoiceNote, VoiceTranscript, VoiceTranscriptSource,
- VoiceTranscriptState,
+ ChannelRef, ContentPart, ConversationKind, ConversationRef, MediaKind, MediaReference,
+ SenderRef, VoiceNote, VoiceTranscript, VoiceTranscriptSource, VoiceTranscriptState,
},
- module_inbound::{ChannelInboundSource, ChannelInboundPreparationMode},
+ module_inbound::{ChannelInboundPreparationMode, ChannelInboundSource},
};
let envelope = tinychannels_bus::ChannelInboundEnvelope {
@@ -155,9 +157,18 @@ async fn native_typed_preparation_preserves_ordered_voice_and_file_parts() {
assert_eq!(prepared.envelope, envelope);
assert_eq!(prepared.message.content, "before\nspoken words\nafter");
- assert_eq!(prepared.envelope.channel.account_id.as_deref(), Some("work"));
- assert_eq!(prepared.envelope.conversation.thread_id.as_deref(), Some("thread-3"));
- assert_eq!(prepared.envelope.conversation.topic_id.as_deref(), Some("topic-4"));
+ assert_eq!(
+ prepared.envelope.channel.account_id.as_deref(),
+ Some("work")
+ );
+ assert_eq!(
+ prepared.envelope.conversation.thread_id.as_deref(),
+ Some("thread-3")
+ );
+ assert_eq!(
+ prepared.envelope.conversation.topic_id.as_deref(),
+ Some("topic-4")
+ );
assert!(matches!(
prepared.envelope.parts.get(2),
Some(ContentPart::File { media, .. }) if media.opaque_id.as_deref() == Some("scoped-file-ref")
diff --git a/tests/native_channel_session_restart_e2e.rs b/tests/native_channel_session_restart_e2e.rs
index 4e6ecd55ce..433c03459e 100644
--- a/tests/native_channel_session_restart_e2e.rs
+++ b/tests/native_channel_session_restart_e2e.rs
@@ -145,10 +145,7 @@ async fn send_message(State(state): State<Arc<MockState>>, Json(body): Json<Valu
Json(json!({ "ok": true, "result": { "message_id": id, "chat": { "id": 42 } } }))
}
-async fn get_file(
- State(state): State<Arc<MockState>>,
- Json(body): Json<Value>,
-) -> Json<Value> {
+async fn get_file(State(state): State<Arc<MockState>>, Json(body): Json<Value>) -> Json<Value> {
let file_id = body
.get("file_id")
.and_then(Value::as_str)
@@ -816,7 +813,13 @@ async fn native_telegram_typed_media_reaches_the_model_without_provider_paths()
wait_for_media_fetch(&mocks.state, 200, "typed-image-file", "photos/native.png").await;
wait_for_completion(&mocks.state, 1).await;
push_media_update(&mocks.state, media_update(201, 21, false, true, None));
- wait_for_media_fetch(&mocks.state, 201, "typed-document-file", "documents/native.txt").await;
+ wait_for_media_fetch(
+ &mocks.state,
+ 201,
+ "typed-document-file",
+ "documents/native.txt",
+ )
+ .await;
wait_for_completion(&mocks.state, 2).await;
push_media_update(
&mocks.state,
@@ -828,7 +831,13 @@ async fn native_telegram_typed_media_reaches_the_model_without_provider_paths()
&mocks.state,
media_update(203, 23, false, true, Some("file caption before media")),
);
- wait_for_media_fetch(&mocks.state, 203, "typed-document-file", "documents/native.txt").await;
+ wait_for_media_fetch(
+ &mocks.state,
+ 203,
+ "typed-document-file",
+ "documents/native.txt",
+ )
+ .await;
wait_for_completion(&mocks.state, 4).await;
let requests = mocks