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(core): improve subagent session state management
Steven Enamakel18d57279b9b0
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops.rsindex b75c1224b0..c6519c8a59 100644--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops.rs+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops.rs@@ -188,10 +188,11 @@ pub fn mark_finished(history: Vec<TranscriptMessage>,) -> Result<(), String> {let task_id = task_id.to_owned();+ let task_id_for_update = task_id.clone();let status = DurableSubagentStatus::from_run_status(run_status);let updated =update_session_for_task(store, subagent_session_id, &task_id, move |session, now| {- session.current_task_id = Some(task_id.clone());+ session.current_task_id = Some(task_id_for_update.clone());session.status = status;session.latest_history = Some(history.clone());session.latest_error = None;@@ -214,9 +215,10 @@ pub fn mark_failed(error: String,) -> Result<(), String> {let task_id = task_id.to_owned();+ let task_id_for_update = task_id.clone();let updated =update_session_for_task(store, subagent_session_id, &task_id, move |session, now| {- session.current_task_id = Some(task_id.clone());+ session.current_task_id = Some(task_id_for_update.clone());session.status = DurableSubagentStatus::Failed;session.latest_error = Some(error.clone());session.updated_at = now.clone();@@ -302,7 +304,7 @@ pub fn reuse_decision(reuse: Option<&DurableSubagentSession>, force_fresh: bool)fn update_session<F>(store: &SubagentSessionStore,subagent_session_id: &str,- update: F,+ mut update: F,) -> Result<bool, String>whereF: FnMut(&mut DurableSubagentSession, String) + Send + 'static,diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port.rsindex e62fcb2aa7..09b9b23157 100644--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port.rs+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port.rs@@ -276,6 +276,7 @@ impl TinySessionStore for OpenHumanTinySubagentSessionStore {let status = match status {TinyStatus::Running => crate::agent::subagent_host::SubagentRunStatus::Incomplete {reason: "still running".into(),+ failure_cause: None,},TinyStatus::Idle => crate::agent::subagent_host::SubagentRunStatus::Completed,TinyStatus::AwaitingUser => {diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_completion.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_completion.rsindex ab7ed36e94..bffb5d7cfb 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_completion.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_async_subagent_completion.rs@@ -121,7 +121,7 @@ pub(super) fn make_completion(.await;}}- SubagentRunStatus::Incomplete { ref reason } => {+ SubagentRunStatus::Incomplete { ref reason, .. } => {// Async sub-agent stopped short (stuck halt / iteration// cap). Mark the session finished and deliver the PARTIAL// progress back to the parent, framed so it is notdiff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rsindex c21c8fbfec..79910c0f33 100644--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs@@ -287,6 +287,7 @@ impl SubagentExecutor<crate::agent::tinyagents::host::OpenHumanRunContext> for O} else if tool_result.is_error {SubagentRunStatus::Incomplete {reason: "configured delegate reported failure".into(),+ failure_cause: None,}} else {SubagentRunStatus::Completed@@ -462,6 +463,7 @@ pub(in crate::agent::subagent_host) fn outcome_to_host(},SubagentOutcomeKind::Incomplete(incomplete) => SubagentRunStatus::Incomplete {reason: incomplete.reason,+ failure_cause: neutral_failure_cause.clone(),},SubagentOutcomeKind::Cancelled => SubagentRunStatus::Cancelled,};diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rsindex 986f985de9..b4a79fd134 100644--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs@@ -860,7 +860,7 @@ async fn run_typed_mode();crate::agent::subagent_host::types::SubagentRunStatus::Incomplete {reason,- failure_cause,+ failure_cause: failure_cause.clone(),}} else if hit_cap {// The tinyagents run stopped at the model-call cap with work stilldiff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rsindex ec60cd56eb..cc77e72585 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs@@ -87,7 +87,7 @@ impl RepeatedToolFailureMiddleware {pub(crate) fn current_classified_cause(&self,) -> Option<tinyagents_harness::no_progress::ClassifiedStopCause> {- self.stop.current_classified_cause()+ self.policy.stop.current_classified_cause()}/// Judge each call's side effect from the registered tools' owndiff --git a/crates/openhuman-core/src/flows/caps_host/service_helpers.rs b/crates/openhuman-core/src/flows/caps_host/service_helpers.rsindex 71f6d25a0b..fcd7132885 100644--- a/crates/openhuman-core/src/flows/caps_host/service_helpers.rs+++ b/crates/openhuman-core/src/flows/caps_host/service_helpers.rs@@ -21,7 +21,7 @@ pub(super) fn bus_error(error: impl std::fmt::Display) -> tinybus::Error {}pub(super) fn to_bus_agent_definition(- definition: crate::agent_registry::host_definition::AgentDefinition,+ definition: &crate::agent_registry::host_definition::AgentDefinition,) -> Result<runs::AgentDefinition, String> {use tinyagents_definition::{ModelSpec, PromptSource, ToolScope};diff --git a/crates/openhuman-core/src/flows/catalog_storage.rs b/crates/openhuman-core/src/flows/catalog_storage.rsindex 5e581cf0bc..92a719f6d5 100644--- a/crates/openhuman-core/src/flows/catalog_storage.rs+++ b/crates/openhuman-core/src/flows/catalog_storage.rs@@ -376,7 +376,7 @@ impl CatalogStoragePort {.map(|record| {Ok(CatalogVersionedDocument {id: record.id,- version: record.version,+ version: record.version.0,doc: record.doc,meta: CatalogDocumentMeta {schema: record.meta.schema,@@ -444,7 +444,7 @@ impl CatalogStoragePort {.into_iter().map(|record| CatalogVersionedDocument {id: record.id,- version: record.version,+ version: record.version.0,doc: record.doc,meta: CatalogDocumentMeta {schema: record.meta.schema,diff --git a/crates/openhuman-core/src/flows/ops/inference_readiness.rs b/crates/openhuman-core/src/flows/ops/inference_readiness.rsindex 52dca81334..f67d7b6590 100644--- a/crates/openhuman-core/src/flows/ops/inference_readiness.rs+++ b/crates/openhuman-core/src/flows/ops/inference_readiness.rs@@ -34,7 +34,9 @@ pub(super) async fn agent_node_role(};let effective_iteration_cap = definition.as_ref()- .and_then(|definition| definition.limits.max_steps)+ .map(|definition| {+ u32::try_from(definition.max_iterations).unwrap_or(u32::MAX)+ }).unwrap_or(1);let override_model = match crate::modules::tinyflows::portability_proxy(config).await {Ok(proxy) => proxydiff --git a/crates/openhuman-core/src/flows/runs_adapter/session.rs b/crates/openhuman-core/src/flows/runs_adapter/session.rsindex 28df4eb5a8..20a8c0cc55 100644--- a/crates/openhuman-core/src/flows/runs_adapter/session.rs+++ b/crates/openhuman-core/src/flows/runs_adapter/session.rs@@ -290,6 +290,7 @@ pub(crate) fn insert(session: Arc<RunSession>) -> Result<(), String> {.read().unwrap_or_else(std::sync::PoisonError::into_inner);let key = RunKey::new(&bindings.storage(), &session.run_id);+ drop(bindings);let mut sessions = SESSIONS.lock().unwrap_or_else(std::sync::PoisonError::into_inner);diff --git a/crates/openhuman-core/src/flows/store.rs b/crates/openhuman-core/src/flows/store.rsindex 8bd3ccb0f7..2607e28bfa 100644--- a/crates/openhuman-core/src/flows/store.rs+++ b/crates/openhuman-core/src/flows/store.rs@@ -27,7 +27,7 @@ pub fn dir(config: &Config) -> PathBuf {pub(crate) fn call_catalog<T, A>(config: &Config, member: &'static str, args: A) -> Result<T>whereT: DeserializeOwned + Send + 'static,- A: Serialize + Send + 'static,+ A: Serialize + Send + Sync + 'static,{let config = config.clone();crate::storage::block_on_anyhow(async move {