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
fix(subagent): cancel subagents without a bound core context
Steven Enamakela32c6fef62ca
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rsindex a121877dfb..7b6212b3d3 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs@@ -43,33 +43,18 @@ pub(crate) fn cancel_by_task(ctx: &crate::core::runtime::DispatchCtx,task_id: &str,) -> Option<CancelledSubagent> {- if std::env::var_os("OPENHUMAN_DEBUG_DRIVER_CANCEL").is_some() {- let resolved = ctx.resolved();- let describe = |label: &str, core: &std::sync::Arc<crate::core::runtime::CoreContext>| {- let jobs = crate::core::runtime::slot_for::<- tinyagents_orchestration::subagent::SubAgentJobRegistry,- >(&crate::core::runtime::DispatchCtx::new(- std::sync::Arc::clone(core),- ));- let entries: Vec<_> = jobs- .list()- .into_iter()- .map(|job| (job.id, job.agent, job.status))- .collect();- eprintln!(- "CANCEL_CTX {label} core={:p} workspace={:?} agent={:?} jobs={entries:?}",- core,- core.workspace_dir().ok(),- core.session_agent(),- );- };- if let Some(core) = resolved.as_ref() {- describe("dispatch", core);- }- for (id, core) in crate::core::runtime::AgentContextRegistry::live() {- describe(&format!("agent:{id}"), &core);- }- }+ cancel_by_task_with_workspace(ctx, task_id, None)+}++/// Cancels a child by public task id using the authenticated active workspace+/// when a non-SaaS transport has no bound `CoreContext`. In that case+/// `slot_for` still resolves the same host-owned unscoped Jobs registry used by+/// the unbound turn, while the workspace identifies its durable product row.+pub(crate) fn cancel_by_task_with_workspace(+ ctx: &crate::core::runtime::DispatchCtx,+ task_id: &str,+ fallback_workspace: Option<&Path>,+) -> Option<CancelledSubagent> {let id = TaskId::new(task_id);if let Ok(snapshot) = registry().snapshot_trusted(&id) {if !control_admits(ctx, &snapshot.metadata) {@@ -102,29 +87,17 @@ pub(crate) fn cancel_by_task(});}- let context = ctx.resolved()?;- let workspace_dir = context.workspace_dir().ok()?;+ let workspace_dir = match ctx.resolved() {+ Some(context) => context.workspace_dir().ok()?,+ None if !crate::core::runtime::is_saas() => fallback_workspace?.to_path_buf(),+ None => return None,+ };let store = crate::agent::orchestration::subagent_sessions::SubagentSessionStore::new(workspace_dir.clone(),);let jobs = crate::core::runtime::slot_for::<tinyagents_orchestration::subagent::SubAgentJobRegistry,>(ctx);- if std::env::var_os("OPENHUMAN_DEBUG_DRIVER_CANCEL").is_some() {- eprintln!(- "CANCEL_LOOKUP task={task_id:?} workspace={workspace_dir:?} rows={:?}",- store.load().map(|rows| rows- .into_iter()- .map(|row| (- row.current_task_id,- row.parent_session,- row.parent_thread_id,- row.status,- row.lifecycle_key,- ))- .collect::<Vec<_>>())- );- }let selected = crate::agent::orchestration::subagent_sessions::cancel_driver_job_by_task(&store,&workspace_dir.join(".openhuman/subagent_checkpoints"),diff --git a/crates/openhuman-core/src/agent_runs/subagent_control.rs b/crates/openhuman-core/src/agent_runs/subagent_control.rsindex 00223c584e..1c34ac5538 100644--- a/crates/openhuman-core/src/agent_runs/subagent_control.rs+++ b/crates/openhuman-core/src/agent_runs/subagent_control.rs@@ -106,19 +106,6 @@ fn handle_subagent_cancel(ctx: DispatchCtx, params: Map<String, Value>) -> ContrBox::pin(async move {let cid = new_correlation_id();let task_id = require_str(¶ms, "taskId")?;- if std::env::var_os("OPENHUMAN_DEBUG_DRIVER_CANCEL").is_some() {- eprintln!(- "CANCEL_HANDLER task={task_id:?} dispatch_core={:?} current_core={:?} default_core={:?} saas={}",- ctx.core().map(std::sync::Arc::as_ptr),- crate::core::runtime::CoreContext::current()- .as_ref()- .map(std::sync::Arc::as_ptr),- crate::core::runtime::CoreContext::default_context()- .as_ref()- .map(std::sync::Arc::as_ptr),- crate::core::runtime::is_saas(),- );- }let reason = opt_str(¶ms, "reason");log::debug!(target: "subagent_control_rpc",@@ -128,7 +115,21 @@ fn handle_subagent_cancel(ctx: DispatchCtx, params: Map<String, Value>) -> Contr// `outcome` is set only when nothing was cancelled: how the run ended// if the registry still knew it, else "unknown" (never registered, or// already swept). The card settles on it instead of assuming success.- let (cancelled, outcome) = match running_subagents::cancel_by_task(&ctx, &task_id) {+ let mut cancelled_subagent = running_subagents::cancel_by_task(&ctx, &task_id);+ if cancelled_subagent.is_none()+ && ctx.resolved().is_none()+ && !crate::core::runtime::is_saas()+ {+ let config = crate::config::ops::load_config_in(&ctx)+ .await+ .map_err(|error| format!("subagent_cancel: failed to resolve active workspace: {error}"))?;+ cancelled_subagent = running_subagents::cancel_by_task_with_workspace(+ &ctx,+ &task_id,+ Some(&config.workspace_dir),+ );+ }+ let (cancelled, outcome) = match cancelled_subagent {// Finished before the click landed (it stays registered until the// terminal sweep). Its outcome is already recorded and delivered;// announcing a cancellation would overwrite a completed session