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(spawn_subagent): extract reusable session close into helper
Steven Enamakel125b08e4158b
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_driver_lookup.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_driver_lookup.rsindex 9b3ead99e0..12d4e5785c 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_driver_lookup.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_driver_lookup.rs@@ -79,3 +79,53 @@ async fn upsert_driver_session(.map_err(|error| error.to_string())?;Ok(crate::agent::orchestration::subagent_sessions::host_projection(session, parent_epoch))}++async fn close_reusable_driver_session(+ driver: &std::sync::Arc<dyn tinyagents_orchestration::subagent::SubagentSessionStore>,+ host_store: &SubagentSessionStore,+ ctx: &DispatchCtx,+ workspace_dir: &std::path::Path,+ session: &DurableSubagentSession,+ parent_session: &str,+ parent_thread_id: Option<&str>,+) -> Result<(), String> {+ let jobs = crate::core::runtime::slot_for::<+ tinyagents_harness_tools::subagents::SubAgentJobRegistry,+ >(ctx);+ let cancelled = subagent_sessions::cancel_driver_job_for_observed_session(+ host_store,+ &workspace_dir.join(".openhuman/subagent_checkpoints"),+ &jobs,+ session,+ parent_session,+ parent_thread_id,+ );+ if !cancelled {+ let _ = running_subagents::cancel_by_session_in_workspace(+ ctx,+ &session.subagent_session_id,+ parent_session,+ workspace_dir,+ );+ }+ let (Some(task_id), Some(lifecycle_key)) = (+ session.current_task_id.as_deref(),+ session.lifecycle_key.as_ref(),+ ) else {+ return Err("reusable session has no current lifecycle identity".into());+ };+ driver+ .close_if_current(+ &session.subagent_session_id,+ task_id,+ lifecycle_key,+ parent_session,+ parent_thread_id,+ )+ .await+ .map_err(|error| format!("failed to close reusable session: {error}"))?+ .then_some(())+ .ok_or_else(|| {+ "reusable session changed during fresh start; retry with the current session".into()+ })+}diff --git a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_host_impl.rs b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_host_impl.rsindex c117c8999e..4606d255b4 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_host_impl.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/spawn_subagent_host_impl.rs@@ -164,54 +164,20 @@ impl SpawnSubagentTool {.await{Ok(Some(session)) => {- let jobs = crate::core::runtime::slot_for::<- tinyagents_harness_tools::subagents::SubAgentJobRegistry,- >(&dispatch);- let cancelled = subagent_sessions::cancel_driver_job_for_observed_session(+ if let Err(error) = close_reusable_driver_session(+ &driver_store,&store,- &parent.workspace_dir.join(".openhuman/subagent_checkpoints"),- &jobs,+ &dispatch,+ &parent.workspace_dir,&session,&parent_session,parent_thread_id.as_deref(),- );- if !cancelled {- let _ = running_subagents::cancel_by_session_in_workspace(- &dispatch,- &session.subagent_session_id,- &parent_session,- &parent.workspace_dir,- );- }- let (Some(task_id), Some(lifecycle_key)) = (- session.current_task_id.as_deref(),- session.lifecycle_key.as_ref(),- ) else {- return Ok(ToolResult::error(- "spawn_subagent: reusable session has no current lifecycle identity",- ));- };- match driver_store- .close_if_current(- &session.subagent_session_id,- task_id,- lifecycle_key,- &parent_session,- parent_thread_id.as_deref(),- )- .await+ )+ .await{- Ok(true) => {}- Ok(false) => {- return Ok(ToolResult::error(- "spawn_subagent: reusable session changed during fresh start; retry with the current session",- ));- }- Err(err) => {- return Ok(ToolResult::error(format!(- "spawn_subagent: failed to close reusable session: {err}"- )));- }+ return Ok(ToolResult::error(format!(+ "spawn_subagent: {error}"+ )));}}Ok(None) => {}