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(session-host): extract runtime turn error handling into helper
Steven Enamakel8b81d5fbb16e
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rsindex fd3202f4ad..3848dc73cf 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_turn.rs@@ -148,21 +148,30 @@ impl OpenHumanSessionHost {let outcome = match Box::pin(turn).await {Ok(outcome) => outcome,Err(error) => {- let refusal = session_sidecar- .lock()- .unwrap_or_else(std::sync::PoisonError::into_inner)- .dispatch_refusal- .take();- if let Some(refusal) = refusal {- return Err(anyhow::Error::new(refusal));- }- return Err(anyhow::anyhow!(error.to_string()));+ return Err(runtime_turn_error(error, &session_sidecar));}};Ok(outcome.output.unwrap_or_default())}}+fn runtime_turn_error(+ error: tinyagents_runtime::RuntimeError,+ sidecar: &std::sync::Arc<+ std::sync::Mutex<crate::agent::tinyagents::host::run_context::SessionTurnSidecar>,+ >,+) -> anyhow::Error {+ let refusal = sidecar+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner)+ .dispatch_refusal+ .take();+ match refusal {+ Some(refusal) => anyhow::Error::new(refusal),+ None => anyhow::anyhow!(error.to_string()),+ }+}+/// Applies the pending one-turn overrides to this turn's resume mode.pub(in crate::agent::session_host) fn begin_turn_resume(state: &mut super::OpenHumanSessionState,@@ -174,3 +183,7 @@ pub(in crate::agent::session_host) fn begin_turn_resume(}state.active_turn_overrides = overrides;}++#[cfg(test)]+#[path = "runtime_session_turn_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session_turn_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_session_turn_tests.rsnew file mode 100644index 0000000000..af9ae08ea4--- /dev/null+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_turn_tests.rs@@ -0,0 +1,43 @@+use super::*;++#[test]+fn runtime_turn_error_restores_the_typed_refusal_before_string_fallback() {+ let context = OpenHumanRunContext::new();+ let refusal = crate::agent::tinyagents::budget::DispatchRefusal::new(+ crate::agent::tinyagents::budget::DispatchRefusalReason::CallLimit,+ );+ context.session_sidecar.lock().unwrap().dispatch_refusal = Some(refusal);++ let error = runtime_turn_error(+ tinyagents_runtime::RuntimeError::Driver("driver failed".to_owned()),+ &context.session_sidecar,+ );++ assert_eq!(+ error+ .downcast_ref::<crate::agent::tinyagents::budget::DispatchRefusal>()+ .expect("the typed refusal crosses the runtime boundary")+ .reason(),+ refusal.reason()+ );+ assert!(context+ .session_sidecar+ .lock()+ .unwrap()+ .dispatch_refusal+ .is_none());+}++#[test]+fn runtime_turn_error_uses_generic_message_when_no_refusal_was_recorded() {+ let context = OpenHumanRunContext::new();+ let error = runtime_turn_error(+ tinyagents_runtime::RuntimeError::Driver("unrelated driver failure".to_owned()),+ &context.session_sidecar,+ );++ assert!(error+ .downcast_ref::<crate::agent::tinyagents::budget::DispatchRefusal>()+ .is_none());+ assert!(error.to_string().contains("unrelated driver failure"));+}diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rsindex 116685fbe5..45aa70c8a7 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs@@ -461,6 +461,27 @@ fn detached_child_inherits_the_parent_dispatch_admission() {));}+#[test]+fn independently_created_root_turns_have_isolated_dispatch_refusal_sidecars() {+ let first = OpenHumanRunContext::new();+ let second = OpenHumanRunContext::new();+ let refusal = crate::agent::tinyagents::budget::DispatchRefusal::new(+ crate::agent::tinyagents::budget::DispatchRefusalReason::CallLimit,+ );++ assert!(!Arc::ptr_eq(+ &first.session_sidecar,+ &second.session_sidecar+ ));+ first.session_sidecar.lock().unwrap().dispatch_refusal = Some(refusal);+ assert!(second+ .session_sidecar+ .lock()+ .unwrap()+ .dispatch_refusal+ .is_none());+}+struct TestAdmission;#[async_trait::async_trait]diff --git a/vendor/tinyagents b/vendor/tinyagentsindex b7df522fd0..4e9bf677a1 160000--- a/vendor/tinyagents+++ b/vendor/tinyagents@@ -1 +1 @@-Subproject commit b7df522fd0615051e19ba0077c5543b997778783+Subproject commit 4e9bf677a18e459ea4c259585ddd7f4b9f621f70