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
refactor(threads): improve attachment handling and test structure
Steven Enamakel04e8c640b532
diff --git a/crates/openhuman-core/src/threads/attachments.rs b/crates/openhuman-core/src/threads/attachments.rsindex 0ceec8c312..9f4311d718 100644--- a/crates/openhuman-core/src/threads/attachments.rs+++ b/crates/openhuman-core/src/threads/attachments.rs@@ -551,7 +551,8 @@ pub(crate) async fn discard_staged_parts(if let Some(id) = opaque_media(&entry.part).and_then(|media| media.opaque_id.as_deref()) {let manifest_path = staged_manifest_path(&config.workspace_dir, id)?;let _ = tokio::fs::remove_file(manifest_path).await;- let claim_path = staged_manifest_path(&config.workspace_dir, id)?.with_extension("claim.json");+ let claim_path =+ staged_manifest_path(&config.workspace_dir, id)?.with_extension("claim.json");let _ = tokio::fs::remove_file(claim_path).await;}}@@ -581,12 +582,11 @@ pub(crate) async fn consume_staged_parts(.ok_or_else(|| "staged attachment reference is missing".to_string())?;let path = staged_manifest_path(&config.workspace_dir, id)?;let claim_path = path.with_extension("claim.json");- let claim: StagedAttachmentClaim = serde_json::from_slice(- &tokio::fs::read(&claim_path)- .await- .map_err(|_| "staged attachment is not bound to a persisted message".to_string())?,- )- .map_err(|error| format!("staged attachment claim is invalid: {error}"))?;+ let claim: StagedAttachmentClaim =+ serde_json::from_slice(&tokio::fs::read(&claim_path).await.map_err(|_| {+ "staged attachment is not bound to a persisted message".to_string()+ })?)+ .map_err(|error| format!("staged attachment claim is invalid: {error}"))?;if claim.tenant != tenant|| claim.thread_id != thread_id|| claim.message_id != message_iddiff --git a/crates/openhuman-core/src/threads/ops/crud.rs b/crates/openhuman-core/src/threads/ops/crud.rsindex 7eb5095496..554a49b969 100644--- a/crates/openhuman-core/src/threads/ops/crud.rs+++ b/crates/openhuman-core/src/threads/ops/crud.rs@@ -507,8 +507,8 @@ async fn message_append_with_config(&staged_refs,&message.id,)- .await- .map_err(ThreadsError::Message)?;+ .await+ .map_err(ThreadsError::Message)?;}Ok(envelope(message_to_record(message),diff --git a/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs b/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rsindex 9267dc9618..105d551ff5 100644--- a/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs+++ b/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs@@ -384,11 +384,11 @@ async fn typed_attachment_is_staged_like_a_marker_and_leaves_the_text_clean() {req.attachments = vec![ContentPart::Image {media: MediaReference {url: Some(format!(- "data:image/png;base64,{}",- base64::engine::general_purpose::STANDARD.encode(include_bytes!(- "../../../../../tests/fixtures/images/handoff-hero.png"- ))- )),+ "data:image/png;base64,{}",+ base64::engine::general_purpose::STANDARD.encode(include_bytes!(+ "../../../../../tests/fixtures/images/handoff-hero.png"+ ))+ )),..Default::default()},caption: None,@@ -469,11 +469,11 @@ async fn public_metadata_updates_preserve_private_attachment_bindings() {req.attachments = vec![ContentPart::Image {media: MediaReference {url: Some(format!(- "data:image/png;base64,{}",- base64::engine::general_purpose::STANDARD.encode(include_bytes!(- "../../../../../tests/fixtures/images/handoff-hero.png"- ))- )),+ "data:image/png;base64,{}",+ base64::engine::general_purpose::STANDARD.encode(include_bytes!(+ "../../../../../tests/fixtures/images/handoff-hero.png"+ ))+ )),..Default::default()},caption: None,@@ -521,13 +521,16 @@ async fn public_metadata_updates_preserve_private_attachment_bindings() {);left.expect("concurrent metadata update one");right.expect("concurrent metadata update two");- let current =- conversations::blocking::get_messages(ctx.clone(), config.workspace_dir.clone(), "uploads".to_string())- .await- .unwrap()- .into_iter()- .find(|message| message.id == saved.id)- .unwrap();+ let current = conversations::blocking::get_messages(+ ctx.clone(),+ config.workspace_dir.clone(),+ "uploads".to_string(),+ )+ .await+ .unwrap()+ .into_iter()+ .find(|message| message.id == saved.id)+ .unwrap();assert_eq!(current.extra_metadata["pinned"], true);assert_eq!(current.extra_metadata["seen"], true);assert_eq!(current.extra_metadata["reactionSummary"]["heart"], 1);@@ -552,8 +555,8 @@ async fn public_metadata_updates_preserve_private_attachment_bindings() {#[tokio::test]async fn queued_user_append_reuses_exact_request_row_and_rejects_conflicts() {- use base64::Engine as _;use crate::core::runtime::{CoreContext, DispatchCtx, DomainSet};+ use base64::Engine as _;use tinychannels_bus::{ContentPart, MediaReference};let (_temp, config) = setup().await;@@ -623,8 +626,8 @@ async fn queued_user_append_reuses_exact_request_row_and_rejects_conflicts() {#[tokio::test]async fn concurrent_queued_attachment_transfer_has_one_exact_owner() {- use base64::Engine as _;use crate::core::runtime::{CoreContext, DispatchCtx, DomainSet};+ use base64::Engine as _;use tinychannels_bus::{ContentPart, MediaReference};let (_temp, config) = setup().await;@@ -646,13 +649,10 @@ async fn concurrent_queued_attachment_transfer_has_one_exact_owner() {alt_text: None,};- let staged_conflict = crate::threads::attachments::stage_queued_parts(- &ctx,- "uploads",- &[image()],- )- .await- .unwrap();+ let staged_conflict =+ crate::threads::attachments::stage_queued_parts(&ctx, "uploads", &[image()])+ .await+ .unwrap();let barrier = std::sync::Arc::new(tokio::sync::Barrier::new(2));let left_ctx = ctx.clone();let left_refs = staged_conflict.clone();@@ -670,21 +670,13 @@ async fn concurrent_queued_attachment_transfer_has_one_exact_owner() {let results = [left.await.unwrap(), right.await.unwrap()];assert_eq!(results.iter().filter(|result| result.is_ok()).count(), 1);assert_eq!(results.iter().filter(|result| result.is_err()).count(), 1);- let rows = conversations::get_messages(- &ctx,- config.workspace_dir.clone(),- "uploads",- )- .unwrap();+ let rows = conversations::get_messages(&ctx, config.workspace_dir.clone(), "uploads").unwrap();assert_eq!(rows.iter().filter(|row| row.id == "user:same").count(), 1);- let staged_single_owner = crate::threads::attachments::stage_queued_parts(- &ctx,- "uploads",- &[image()],- )- .await- .unwrap();+ let staged_single_owner =+ crate::threads::attachments::stage_queued_parts(&ctx, "uploads", &[image()])+ .await+ .unwrap();let barrier = std::sync::Arc::new(tokio::sync::Barrier::new(2));let left_ctx = ctx.clone();let left_refs = staged_single_owner.clone();