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
chore: files changed crates/openhuman-core/src/agent/turn_host.rs,crates/openhuman-core/src/channels
Steven Enamakel8e587a1f84e2
diff --git a/crates/openhuman-core/src/agent/turn_host.rs b/crates/openhuman-core/src/agent/turn_host.rsindex f80e90f602..93763662fc 100644--- a/crates/openhuman-core/src/agent/turn_host.rs+++ b/crates/openhuman-core/src/agent/turn_host.rs@@ -34,9 +34,10 @@ pub(crate) struct TrustedAgentTurn {pub(crate) approval: ApprovalTurnContext,pub(crate) relay_thread: Option<String>,pub(crate) imported_history: Vec<tinyagents_session::transcript::TranscriptMessage>,- /// Captured compiled-module reply port for native channel turns. This- /// stays in trusted queue state and is never reconstructed from metadata.- pub(crate) native_reply: Option<Arc<crate::channels::bus::NativeProgressiveReply>>,+ /// Captured configured compiled-module target for native turns. The+ /// progressive handle itself is opened at runner checkout per admitted+ /// request, so queued follow-ups never reuse a finished handle.+ pub(crate) native_target: Option<Arc<crate::channels::runtime::dispatch::processor::progressive::NativeProgressiveTarget>>,}impl std::fmt::Debug for TrustedAgentTurn {@@ -47,7 +48,7 @@ impl std::fmt::Debug for TrustedAgentTurn {.field("session_scoped", &!self.session_key.is_empty()).field("relay_thread", &self.relay_thread).field("imported_history_rows", &self.imported_history.len())- .field("native_reply", &self.native_reply.is_some())+ .field("native_target", &self.native_target.is_some()).finish_non_exhaustive()}}diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rsindex e3ee653606..2b74380905 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/native_runner.rs@@ -27,12 +27,13 @@ struct NativeSlot {lease: Option<SessionLease>,reply: Option<String>,progress_failed: bool,+ waiting_for_delivery: bool,+ delivery_succeeded: Option<bool>,}#[derive(Default)]struct NativeShared {slots: Mutex<HashMap<String, NativeSlot>>,- delivery_status: Mutex<HashMap<String, bool>>,}impl NativeShared {@@ -44,22 +45,44 @@ impl NativeShared {f(slots.entry(request_id.to_owned()).or_default())}+ fn begin_delivery_wait(&self, request_id: &str) {+ self.with(request_id, |slot| slot.waiting_for_delivery = true);+ }+fn record_delivery(&self, request_id: &str, delivered: bool) {- self.delivery_status+ let mut slots = self+ .slots.lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())- .insert(request_id.to_owned(), delivered);- self.slots+ .unwrap_or_else(|poisoned| poisoned.into_inner());+ if let Some(slot) = slots.get_mut(request_id) {+ slot.delivery_succeeded = Some(delivered);+ // The lease spans model execution and terminal provider delivery.+ slot.lease = None;+ if !slot.waiting_for_delivery {+ slots.remove(request_id);+ }+ }+ }++ fn abandon_delivery_wait(&self, request_id: &str) {+ let mut slots = self+ .slots.lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())- .remove(request_id);+ .unwrap_or_else(|poisoned| poisoned.into_inner());+ if let Some(slot) = slots.get_mut(request_id) {+ slot.waiting_for_delivery = false;+ if slot.delivery_succeeded.is_some() {+ slots.remove(request_id);+ }+ }}fn take_delivery(&self, request_id: &str) -> Option<bool> {- self.delivery_status+ self.slots.lock().unwrap_or_else(|poisoned| poisoned.into_inner()).remove(request_id)+ .and_then(|slot| slot.delivery_succeeded)}}@@ -117,7 +140,12 @@ impl TurnHost<QueuedPayload> for NativeHost {.as_ref().ok_or_else(|| "channel turn has no trusted host context".to_owned())?;let (agent_progress, mut progress_rx) = mpsc::channel(64);- let progress_forwarder = tokio::spawn(async move {+ let progress_forwarder = request+ .payload+ .ctx+ .as_ref()+ .map(crate::core::runtime::DispatchCtx::clone)+ .map(|dispatch| dispatch.spawn(async move {while let Some(event) = progress_rx.recv().await {if progress.send(TurnSignal::Progress(Box::new(event)))@@ -127,7 +155,7 @@ impl TurnHost<QueuedPayload> for NativeHost {break;}}- });+ }));let response = crate::channels::runtime::dispatch::host_agent::run_host_agent_turn(trusted.host_agent.clone(),crate::channels::runtime::dispatch::host_agent::HostChannelTurn {@@ -147,7 +175,9 @@ impl TurnHost<QueuedPayload> for NativeHost {).await.map_err(|error| error.to_string());- let _ = progress_forwarder.await;+ if let Some(progress_forwarder) = progress_forwarder {+ let _ = progress_forwarder.await;+ }response.map(|response| TurnResult {reply: response.text,data: serde_json::json!({@@ -361,6 +391,7 @@ pub(crate) async fn run(};}};+ runtime.shared.begin_delivery_wait(&request_id);let request = TurnRequest {scope: ScopeKey {agent_id: trusted.host_agent.definition.id.clone(),@@ -377,17 +408,17 @@ pub(crate) async fn run(host_authored: false,disposition: QueueDisposition::Interrupt,deadline: Some(crate::agent::session_host::turn_backstop::configured_backstop()),- idle_timeout: Some(std::time::Duration::from_secs(900)),+ idle_timeout: Some(crate::agent::turn_policy::configured_idle_window()),};let runner_result = runtime.runner.run(request).await;- let queued = matches!(runner_result, Err(tinyagents_harness::turn_runner::TurnRunnerError::Queued));+ let queued = matches!(+ &runner_result,+ Err(tinyagents_harness::turn_runner::TurnRunnerError::Queued)+ );let result = runner_result.map_err(|error| error.to_string());- runtime- .shared- .slots- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner())- .remove(&request_id);+ if queued {+ runtime.shared.abandon_delivery_wait(&request_id);+ }let result = result.map(|result| {let provider = result.data["provider"].as_str().map(str::to_owned);let model = result.data["model"].as_str().map(str::to_owned);@@ -399,7 +430,11 @@ pub(crate) async fn run(});NativeTurnExecution {result,- delivery_succeeded: runtime.shared.take_delivery(&request_id),+ delivery_succeeded: if queued {+ None+ } else {+ runtime.shared.take_delivery(&request_id)+ },queued,}}diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive.rsindex 7844c15760..bf095a8aa2 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive.rs@@ -10,6 +10,43 @@ pub(super) async fn open_native_reply(envelope: &tinychannels_bus::channel::ChannelInboundEnvelope,turn_id: &str,) -> anyhow::Result<Option<std::sync::Arc<NativeProgressiveReply>>> {+ let Some(target) = native_target(ctx, envelope)? else {+ return Ok(None);+ };+ target.open(turn_id).await.map(Some)+}++/// Captured configured module target for a single inbound conversation.+/// Opening the progressive handle is deferred until TurnRunner checkout, so a+/// queued follow-up gets a fresh module handle after it wins admission.+pub(crate) struct NativeProgressiveTarget {+ object: tinybus::module::ModuleObjectClient,+ channel: tinychannels_bus::channel::ChannelRef,+ conversation: tinychannels_bus::channel::ConversationRef,+}++impl NativeProgressiveTarget {+ pub(crate) async fn open(+ &self,+ turn_id: &str,+ ) -> anyhow::Result<std::sync::Arc<NativeProgressiveReply>> {+ Ok(std::sync::Arc::new(+ NativeProgressiveReply::open(+ self.object.clone(),+ self.channel.clone(),+ self.conversation.clone(),+ turn_id.to_owned(),+ std::time::Duration::from_secs(3_660),+ )+ .await?,+ ))+ }+}++pub(crate) fn native_target(+ ctx: &crate::channels::context::ChannelRuntimeContext,+ envelope: &tinychannels_bus::channel::ChannelInboundEnvelope,+) -> anyhow::Result<Option<NativeProgressiveTarget>> {#[cfg(test)]if ctx.config.is_none() && ctx.module_objects.is_empty() {return Ok(None);@@ -25,15 +62,11 @@ pub(super) async fn open_native_reply(.get(account).cloned().ok_or_else(|| anyhow::anyhow!("native channel account is not configured"))?;- let reply = NativeProgressiveReply::open(+ Ok(Some(NativeProgressiveTarget {object,- envelope.channel.clone(),- envelope.conversation.clone(),- turn_id.to_owned(),- std::time::Duration::from_secs(3_660),- )- .await?;- Ok(Some(std::sync::Arc::new(reply)))+ channel: envelope.channel.clone(),+ conversation: envelope.conversation.clone(),+ }))}pub(crate) async fn finish_native_reply(