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
test(orchestration): cover cross-profile subagent cancellation isolation
Steven Enamakele152a31c2643
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_driver_tests.rs b/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_driver_tests.rsindex 2ee69f666b..7903c8315e 100644--- a/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_driver_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/tools/tools_e2e_driver_tests.rs@@ -1,5 +1,214 @@use super::*;+#[tokio::test]+async fn profile_scope_cannot_cancel_another_profiles_driver_child() {+ const CHILD: &str = "OPENHUMAN_SAAS_SUBAGENT_CANCEL_SCOPE_CHILD";+ if std::env::var_os(CHILD).is_none() {+ let output = std::process::Command::new(+ std::env::current_exe().expect("unit test executable path"),+ )+ .args([+ "--exact",+ "agent::orchestration::tools::tools_e2e_driver_tests::profile_scope_cannot_cancel_another_profiles_driver_child",+ "--nocapture",+ ])+ .env(CHILD, "1")+ .output()+ .expect("run isolated SaaS-mode driver cancellation case");+ assert!(+ output.status.success(),+ "isolated SaaS cancellation case failed: stdout={} stderr={}",+ String::from_utf8_lossy(&output.stdout),+ String::from_utf8_lossy(&output.stderr)+ );+ return;+ }++ use crate::agent::orchestration::subagent_sessions::{+ DurableSubagentStatus, SubagentSessionStore,+ };+ use crate::agent::tinyagents::host::OpenHumanRunContext;+ use crate::core::runtime::{ContextOverlay, CoreContext, DispatchCtx, DomainSet};+ use crate::tools::toolpacks::ToolGroups;+ use tinyagents_harness::context::RunContext;+ use tinyagents_orchestration::subagent::SubAgentJobStatus;++ crate::core::runtime::mode::lock_mode(crate::core::runtime::Mode::Saas)+ .expect("the child process starts with an unlocked SaaS mode");+ let scratch = tempfile::tempdir().expect("profile cancellation workspace");+ let workspace = scratch.path().join("workspace");+ std::fs::create_dir_all(&workspace).expect("create shared workspace");+ let provider = Arc::new(ScriptedModel::new(vec![]));+ let mut parent = parent_context(workspace.as_path(), provider, vec![]);+ parent.workspace_dir = workspace.clone();+ parent.session_id = "shared-profile-parent-session".into();++ let mut config = crate::config::Config::default();+ config.workspace_dir = workspace.clone();+ config.components.juice = false;+ let root = CoreContext::for_test_with_config(DomainSet::full(), config.clone());+ let definitions = Arc::new(AgentDefinitionRegistry::builtins_only());+ let derive_profile = |profile: &str| {+ root.derive_with(+ ContextOverlay::new(config.clone(), DomainSet::full(), ToolGroups::none())+ .profile(profile)+ .definitions(Arc::clone(&definitions)),+ )+ };+ let alice = derive_profile("cancel-alice");+ let bob = derive_profile("cancel-bob");+ assert_eq!(alice.profile(), Some("cancel-alice"));+ assert_eq!(bob.profile(), Some("cancel-bob"));+ assert_eq!(alice.workspace_dir().unwrap(), workspace);+ assert_eq!(bob.workspace_dir().unwrap(), workspace);++ let thread_id = "shared-profile-parent-thread";+ let mut host = OpenHumanRunContext::new()+ .with_core(Some(Arc::clone(&alice)))+ .with_parent(parent);+ host.thread_id = Some(thread_id.into());+ let live = RunContext::<OpenHumanRunContext>::new(+ tinyagents_harness::context::RunConfig::new("profile-cancel-parent")+ .with_thread(thread_id),+ host,+ );+ let detached_data = live.data.detached_child();+ let detached = live+ .child(+ tinyagents_harness::context::RunConfig::new("profile-cancel-child"),+ detached_data.clone(),+ )+ .expect("detached child context")+ .with_cancellation(detached_data.cancellation.clone());+ let accepted = crate::agent::orchestration::tools::SpawnSubagentTool::new()+ .execute_with_live_parent_context(+ json!({+ "agent_id": "task_manager_agent",+ "prompt": "wait for an owner-scoped cancellation",+ "model": "test-model",+ "task_key": "profile-cancel-canary"+ }),+ None,+ live.data.child(),+ detached,+ )+ .await+ .expect("spawn tool execution");+ assert!(!accepted.is_error, "{}", accepted.output());+ let task_id = accepted+ .output()+ .split("[async_subagent_ref]\n")+ .nth(1)+ .and_then(|value| value.split("\n[/async_subagent_ref]").next())+ .and_then(|value| serde_json::from_str::<serde_json::Value>(value).ok())+ .and_then(|value| value["task_id"].as_str().map(str::to_owned))+ .expect("accepted child includes public task ID");+ let alice_ctx = live.data.dispatch_ctx();+ let alice_jobs = crate::core::runtime::slot_for::<+ tinyagents_harness_tools::subagents::SubAgentJobRegistry,+ >(&alice_ctx);+ let alice_job = alice_jobs+ .list()+ .into_iter()+ .find(|job| {+ job.extensions+ .get("task_id")+ .and_then(serde_json::Value::as_str)+ == Some(task_id.as_str())+ })+ .expect("real child is registered in Alice's scoped driver registry");+ assert_eq!(alice_job.status, SubAgentJobStatus::Running);++ let store = SubagentSessionStore::new(workspace.clone());+ let row_before = store+ .load()+ .expect("durable child row readable")+ .into_iter()+ .find(|row| row.current_task_id.as_deref() == Some(task_id.as_str()))+ .expect("durable row belongs to the live child");+ assert_eq!(row_before.status, DurableSubagentStatus::Running);+ assert_eq!(row_before.parent_session, "shared-profile-parent-session");+ assert_eq!(row_before.parent_thread_id.as_deref(), Some(thread_id));++ let bob_ctx = DispatchCtx::new(Arc::clone(&bob));+ let bob_job_registry = crate::core::runtime::slot_for::<+ tinyagents_harness_tools::subagents::SubAgentJobRegistry,+ >(&bob_ctx);+ assert!(+ bob_job_registry.list().is_empty(),+ "Bob resolves the same workspace/session/thread but uses Bob's scoped registry"+ );+ let foreign_cancel = crate::agent::orchestration::running_subagents::cancel_by_task_with_workspace_reason(+ &bob_ctx,+ &task_id,+ Some(&workspace),+ Some("foreign profile cancellation"),+ )+ .expect("foreign profile cancellation lookup");+ assert!(foreign_cancel.is_none(), "Bob cannot cancel Alice's child");+ assert_eq!(+ alice_jobs+ .get(alice_job.id.as_str())+ .expect("Alice's job remains registered")+ .status,+ SubAgentJobStatus::Running,+ "foreign cancellation leaves the owner job running"+ );+ let after_bob = store+ .load()+ .expect("durable child row remains readable")+ .into_iter()+ .find(|row| row.subagent_session_id == row_before.subagent_session_id)+ .expect("foreign attempt keeps Alice's durable row");+ assert_eq!(after_bob.status, DurableSubagentStatus::Running);+ assert_eq!(after_bob.current_task_id, row_before.current_task_id);+ assert_eq!(+ crate::agent::orchestration::background_completions::pending_for_ctx(+ &bob_ctx,+ &workspace,+ thread_id,+ )+ .len(),+ 0,+ "Bob's rejected attempt exposes no Alice completion"+ );+ assert!(+ crate::agent::orchestration::running_subagents::cancel_by_task_with_workspace_reason(+ &DispatchCtx::unbound(),+ &task_id,+ None,+ None,+ )+ .expect("unbound SaaS control refusal")+ .is_none(),+ "SaaS cancellation without a profile fails closed"+ );++ let owner_cancel = crate::agent::orchestration::running_subagents::cancel_by_task_with_workspace_reason(+ &alice_ctx,+ &task_id,+ Some(&workspace),+ Some("owner requested stop"),+ )+ .expect("owner cancellation lookup");+ assert!(owner_cancel.is_some(), "Alice can cancel her own child");+ let terminal = tokio::time::timeout(+ std::time::Duration::from_secs(5),+ alice_jobs.wait_owned(+ alice_job.id.as_str(),+ crate::agent::tinyagents::tool_registration::subagent_owner_key(+ &workspace,+ "shared-profile-parent-session",+ Some(thread_id),+ ),+ ),+ )+ .await+ .expect("rightful cancellation settles the driver job")+ .expect("owner job remains registered");+ assert_eq!(terminal.status, SubAgentJobStatus::Cancelled);+}+#[tokio::test]async fn failed_steer_of_running_reused_session_does_not_create_second_child() {use crate::agent::orchestration::subagent_sessions::{