Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(orchestration): cancel sub-agent driver jobs on close

Steven Enamakel53beeb605113
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/close_subagent.rs b/crates/openhuman-core/src/agent/orchestration/tools/close_subagent.rs
index 9015e42e29..25750d635f 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/close_subagent.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/close_subagent.rs
@@ -152,8 +152,22 @@ impl CloseSubagentTool {
"close_subagent: sub-agent session not found for this parent thread",
));
}
- let cancelled = running_subagents::cancel_by_session_in_workspace(
- &crate::agent::tinyagents::host::run_context::dispatch_ctx_for_tool(tool_context),
+ let dispatch =
+ crate::agent::tinyagents::host::run_context::dispatch_ctx_for_tool(tool_context);
+ let thread_id = tool_context.and_then(ToolRunContext::thread_id);
+ let jobs = crate::core::runtime::slot_for::<
+ tinyagents_orchestration::subagent::SubAgentJobRegistry,
+ >(&dispatch);
+ let store = SubagentSessionStore::new(parent.workspace_dir.clone());
+ let cancelled = subagent_sessions::cancel_driver_job_for_session(
+ &store,
+ &parent.workspace_dir.join(".openhuman/subagent_checkpoints"),
+ &jobs,
+ &subagent_session_id,
+ &parent.session_id,
+ thread_id,
+ ) || running_subagents::cancel_by_session_in_workspace(
+ &dispatch,
&subagent_session_id,
&parent.session_id,
&parent.workspace_dir,
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs
index 14dc160f14..f0e6c19b45 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/dispatch_tests.rs
@@ -157,7 +157,12 @@ async fn config_delegate_dispatch_honours_the_parent_cancellation_token() {
});
let dispatch = DelegateToolDispatch::new(tool);
let cancellation = tinyagents_harness::CancellationToken::new();
+ let core = crate::core::runtime::CoreContext::for_test_with_config(
+ crate::core::runtime::DomainSet::full(),
+ crate::config::Config::default(),
+ );
let parent = crate::agent::tinyagents::host::OpenHumanRunContext::new()
+ .with_core(Some(Arc::clone(&core)))
.with_cancellation(cancellation.clone())
.into_tinyagents(RunConfig::new("config-delegate-parent").with_thread("thread-parent"));
let jobs = crate::core::runtime::slot_for::<
@@ -186,18 +191,27 @@ async fn config_delegate_dispatch_honours_the_parent_cancellation_token() {
.expect("cancellation is reported as a tool result");
assert!(result.is_error);
assert!(result.output().contains("cancelled"), "{}", result.output());
- assert!(
- jobs.list()
- .iter()
- .any(|job| { job.agent == "configured" && job.status.is_terminal() }),
- "configured child cancellation settles the shared Jobs lifecycle"
+ let cancelled = jobs
+ .list()
+ .into_iter()
+ .find(|job| job.agent == "configured")
+ .expect("configured child remains in the isolated shared registry");
+ assert_eq!(
+ cancelled.status,
+ tinyagents_orchestration::subagent::SubAgentJobStatus::Cancelled,
+ "configured child cancellation settles as Cancelled"
);
}
#[tokio::test]
async fn config_delegate_dispatch_preserves_tool_failure_in_shared_jobs() {
let dispatch = DelegateToolDispatch::new(Arc::new(FailingDelegationTool));
+ let core = crate::core::runtime::CoreContext::for_test_with_config(
+ crate::core::runtime::DomainSet::full(),
+ crate::config::Config::default(),
+ );
let parent = crate::agent::tinyagents::host::OpenHumanRunContext::new()
+ .with_core(Some(Arc::clone(&core)))
.into_tinyagents(RunConfig::new("config-delegate-error-parent"));
let jobs = crate::core::runtime::slot_for::<
tinyagents_orchestration::subagent::SubAgentJobRegistry,