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
feat(runtime): introduce native staged lease tracking
Steven Enamakelc5eb2971e761
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rsindex af467bdf7b..9d070735fa 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs@@ -560,6 +560,7 @@ pub(crate) async fn run(text: String,message_input: Option<tinyinference_llm::message::Message>,staged_parts: Vec<tinychannels_bus::ContentPart>,+ staged_lease: Option<crate::threads::attachments::NativeStagedLease>,staged_message_id: Option<String>,preparation_error: Option<String>,trusted: Arc<crate::agent::turn_host::TrustedAgentTurn>,@@ -576,14 +577,6 @@ pub(crate) async fn run(}};runtime.shared.begin_delivery_wait(&request_id);- let staged_lease = (!staged_parts.is_empty()).then(|| {- crate::threads::attachments::NativeStagedLease::new(- dispatch.clone(),- thread_id.clone(),- trusted.host_agent.config.clone(),- staged_parts.clone(),- )- });let request = TurnRequest {scope: ScopeKey {agent_id: trusted.host_agent.definition.id.clone(),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.rsindex 85b363ffe9..574dc28285 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@@ -184,6 +184,12 @@ pub(super) async fn resolve_typed_message(.map_err(|error| log_rejection("module_media_read", error))?;media_payloads.push((index, part.clone(), name, mime, bytes));}+ let staged_lease = crate::threads::attachments::NativeStagedLease::new(+ host_dispatch.clone(),+ thread_id.to_owned(),+ config.clone(),+ Vec::new(),+ );for (index, input, name, mime, bytes) in media_payloads {let staged = match crate::threads::attachments::stage_native_channel_part(host_dispatch,@@ -193,18 +199,13 @@ pub(super) async fn resolve_typed_message(&name,&mime,&bytes,+ &staged_lease,).await{Ok(staged) => staged,Err(error) => {- let _ = crate::threads::attachments::discard_native_channel_parts(- host_dispatch,- thread_id,- config,- &staged_parts,- )- .await;+ let _ = staged_lease.discard().await;return Err(log_rejection("host_staging", error));}};@@ -230,19 +231,14 @@ pub(super) async fn resolve_typed_message(match crate::agent::message_convert::user_message_from_parts(channel_context, &parts) {Ok(message) => message,Err(error) => {- let _ = crate::threads::attachments::discard_native_channel_parts(- host_dispatch,- thread_id,- config,- &staged_parts,- )- .await;+ let _ = staged_lease.discard().await;return Err(log_rejection("message_conversion", error));}};Ok(Some(ResolvedNativeMessage {message,staged_parts,+ staged_lease,}))}@@ -258,6 +254,7 @@ fn media_opaque_id(part: &ContentPart) -> Option<&str> {pub(super) struct ResolvedNativeMessage {pub(super) message: Message,pub(super) staged_parts: Vec<ContentPart>,+ pub(super) staged_lease: crate::threads::attachments::NativeStagedLease,}fn media_scope(envelope: &ChannelInboundEnvelope) -> Result<HostVoiceScope, String> {diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rsindex 7088ae1535..eca9289621 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs@@ -427,11 +427,16 @@ pub(crate) async fn process_channel_runtime_message(} else {None};- let (native_message_input, native_staged_parts, native_preparation_error) =+ let (native_message_input, native_staged_parts, native_staged_lease, native_preparation_error) =match native_preparation {- Some(Ok(Some(prepared))) => (Some(prepared.message), prepared.staged_parts, None),- Some(Ok(None)) | None => (None, Vec::new(), None),- Some(Err(error)) => (None, Vec::new(), Some(error)),+ Some(Ok(Some(prepared))) => (+ Some(prepared.message),+ prepared.staged_parts,+ Some(prepared.staged_lease),+ None,+ ),+ Some(Ok(None)) | None => (None, Vec::new(), None, None),+ Some(Err(error)) => (None, Vec::new(), None, Some(error)),};let channel_session = selected_host.as_ref().and_then(|host| {let account_id = envelope@@ -487,6 +492,7 @@ pub(crate) async fn process_channel_runtime_message(enriched_message.clone(),native_message_input,native_staged_parts,+ native_staged_lease,Some(envelope.message_id.clone()),native_preparation_error,trusted,diff --git a/crates/openhuman-core/src/threads/attachments/staged/native.rs b/crates/openhuman-core/src/threads/attachments/staged/native.rsindex 1a75cf15c1..85f215ad94 100644--- a/crates/openhuman-core/src/threads/attachments/staged/native.rs+++ b/crates/openhuman-core/src/threads/attachments/staged/native.rs@@ -47,7 +47,11 @@ impl NativeStagedLease {}pub(crate) fn track(&self, part: ContentPart) -> Result<(), String> {- let mut parts = self.0.parts.lock().unwrap_or_else(|error| error.into_inner());+ let mut parts = self+ .0+ .parts+ .lock()+ .unwrap_or_else(|error| error.into_inner());if self.0.state.load(Ordering::Acquire) != NATIVE_STAGED_ACTIVE {return Err("native attachment lease is no longer active".into());}@@ -82,14 +86,14 @@ impl NativeStagedLease {state: self.0.clone(),completed: false,};- let parts = self.0.parts.lock().unwrap_or_else(|error| error.into_inner()).clone();- discard_native_channel_parts(- &self.0.dispatch,- &self.0.thread_id,- &self.0.config,- &parts,- )- .await?;+ let parts = self+ .0+ .parts+ .lock()+ .unwrap_or_else(|error| error.into_inner())+ .clone();+ discard_native_channel_parts(&self.0.dispatch, &self.0.thread_id, &self.0.config, &parts)+ .await?;self.0.state.store(NATIVE_STAGED_DISCARDED, Ordering::Release);diff --git a/crates/openhuman-core/src/threads/attachments_tests.rs b/crates/openhuman-core/src/threads/attachments_tests.rsindex bee6aefea0..ab22b6b74f 100644--- a/crates/openhuman-core/src/threads/attachments_tests.rs+++ b/crates/openhuman-core/src/threads/attachments_tests.rs@@ -642,6 +642,12 @@ async fn canceling_native_media_resolution_cleans_the_first_staged_part() {let task_ctx = ctx.clone();let task_config = config.clone();let task = tokio::spawn(async move {+ let lease = NativeStagedLease::new(+ task_ctx.clone(),+ thread_id.into(),+ task_config.clone(),+ Vec::new(),+ );let source = image(MediaReference {content_type: Some("image/png".into()),kind: tinychannels_bus::MediaKind::Image,@@ -655,6 +661,7 @@ async fn canceling_native_media_resolution_cleans_the_first_staged_part() {"first-native.png","image/png",b"cancellation lifecycle fixture",+ &lease,).await.unwrap();