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(running_subagents): inline session resolution into cancel and task ledger
Steven Enamakel4150e4810f51
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents.rsindex 8d37a50d3a..f07303591f 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents.rs@@ -3,7 +3,6 @@mod cancel;mod registry;-mod resolve;mod roster;mod task_ledger;diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rsindex ba9e7239bb..105b627c64 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs@@ -4,9 +4,12 @@use std::path::{Path, PathBuf};-use tinyagents_orchestration::subagent::FinishedOutcome;+use tinyagents_orchestration::subagent::{+ FinishedOutcome, WaitError, task_id_for_session_in_records,+};-use super::resolve::task_id_for_session_in_workspace;+use super::registry::admit_workspace;+use super::task_ledger::scoped_task_store;/// Metadata captured when a sub-agent is cancelled, so the caller can surface/// the cancellation back in the parent chat (record a "cancelled" completion@@ -96,6 +99,21 @@ pub(crate) fn cancel_by_session_in_workspace(.flatten()}+fn task_id_for_session_in_workspace(+ ctx: &crate::core::runtime::DispatchCtx,+ subagent_session_id: &str,+ parent_session: &str,+ workspace_dir: &Path,+) -> Result<String, WaitError> {+ admit_workspace(ctx, workspace_dir)?;+ let store = scoped_task_store(ctx, workspace_dir)?;+ task_id_for_session_in_records(+ tinyagents_orchestration::subagent::list_subagent_records(store.as_ref()),+ subagent_session_id,+ parent_session,+ )+}+/// Abort and drop every running sub-agent whose parent chat thread is/// `thread_id`. Called when that thread is deleted so detached children don't/// keep running (and later try to deliver) against a thread that no longerdiff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/resolve.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/resolve.rsdeleted file mode 100644index 5786f2d99b..0000000000--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/resolve.rs+++ /dev/null@@ -1,92 +0,0 @@-//! Resolving a durable `subagent_session_id` (or a transient `task_id`) back-//! to the live registry entry or, failing that, the durable task-store record-//! — used by tool/control paths that only know the stable session id a-//! sub-agent is addressed by.--use std::path::Path;--use tinyagents_orchestration::subagent::{- resume_ref_from_record, subagent_record_for_task, task_id_for_session_in_records,- SubagentResumeRef, WaitError,-};--use super::registry::admit_workspace;-use super::task_ledger::task_store_for_workspace;--/// Resolve a durable `subagent_session_id` to the currently-running transient-/// `task_id`, enforcing parent-session ownership.-pub(crate) fn task_id_for_session(- ctx: &crate::core::runtime::DispatchCtx,- subagent_session_id: &str,- parent_session: &str,-) -> Result<String, WaitError> {- let context = ctx.resolved().ok_or(WaitError::NotOwned)?;- let workspace = context.workspace_dir().map_err(|_| WaitError::NotOwned)?;- task_id_for_session_in_workspace(ctx, subagent_session_id, parent_session, &workspace)-}--pub(crate) fn task_id_for_session_in_workspace(- ctx: &crate::core::runtime::DispatchCtx,- subagent_session_id: &str,- parent_session: &str,- workspace_dir: &Path,-) -> Result<String, WaitError> {- admit_workspace(ctx, workspace_dir)?;- let store = scoped_task_store(ctx, workspace_dir)?;- let task_id = task_id_for_session_in_records(- tinyagents_orchestration::subagent::list_subagent_records(store.as_ref()),- subagent_session_id,- parent_session,- )?;- log::debug!(- "[running_subagents] resolved session from task store subagent_session_id={} task_id={} workspace_dir={}",- subagent_session_id,- task_id,- workspace_dir.display()- );- Ok(task_id)-}--pub(crate) fn resume_ref_for_task(- ctx: &crate::core::runtime::DispatchCtx,- task_id: &str,- parent_session: &str,-) -> Result<SubagentResumeRef, WaitError> {- let context = ctx.resolved().ok_or(WaitError::NotOwned)?;- let workspace = context.workspace_dir().map_err(|_| WaitError::NotOwned)?;- resume_ref_for_task_in_workspace(ctx, task_id, parent_session, &workspace)-}--pub(crate) fn resume_ref_for_task_in_workspace(- ctx: &crate::core::runtime::DispatchCtx,- task_id: &str,- parent_session: &str,- workspace_dir: &Path,-) -> Result<SubagentResumeRef, WaitError> {- admit_workspace(ctx, workspace_dir)?;- let store = scoped_task_store(ctx, workspace_dir)?;- let record = subagent_record_for_task(store.as_ref(), task_id, parent_session)?;- let reference = resume_ref_from_record(task_id, &record);- log::debug!(- "[running_subagents] resolved resume ref from task store task_id={} workspace_dir={}",- task_id,- workspace_dir.display()- );- Ok(reference)-}--pub(super) fn scoped_task_store(- ctx: &crate::core::runtime::DispatchCtx,- workspace_dir: &Path,-) -> Result<std::sync::Arc<dyn tinyagents_tasks::TaskStore>, WaitError> {- if let Some(context) = ctx.resolved() {- return Ok(crate::core::runtime::CoreContext::sync_scope(- context,- || task_store_for_workspace(workspace_dir),- ));- }- if crate::core::runtime::is_saas() {- return Err(WaitError::NotOwned);- }- Ok(task_store_for_workspace(workspace_dir))-}diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger.rsindex f14aa8f9a9..6cd14b0499 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/task_ledger.rs@@ -11,7 +11,8 @@ use std::path::{Path, PathBuf};use std::sync::{Arc, OnceLock};use tinyagents_orchestration::subagent::{- orphaned_subagent_reason, record_agent_id, record_parent_session, task_status_label,+ WaitError, orphaned_subagent_reason, record_agent_id, record_parent_session,+ task_status_label,};use tinyagents_tasks::{InMemoryTaskStore, OrchestrationTaskFilter, TaskStore, TaskStoreRegistry,@@ -89,6 +90,23 @@ pub(crate) fn task_store_for_workspace(workspace_dir: &Path) -> Arc<dyn TaskStor}}+/// Open the caller's task store in its captured scope. SaaS calls without a+/// resolved owner fail closed rather than falling back to ambient storage.+pub(super) fn scoped_task_store(+ ctx: &crate::core::runtime::DispatchCtx,+ workspace_dir: &Path,+) -> Result<Arc<dyn TaskStore>, WaitError> {+ if let Some(context) = ctx.resolved() {+ return Ok(crate::core::runtime::CoreContext::sync_scope(context, || {+ task_store_for_workspace(workspace_dir)+ }));+ }+ if crate::core::runtime::is_saas() {+ return Err(WaitError::NotOwned);+ }+ Ok(task_store_for_workspace(workspace_dir))+}+/// Restart/resume reconciliation for detached sub-agents (issue #4249 / 07.2/// steps 2 & 4).///