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(subagent_sessions): cover stopped-thread driver spawn rejection
Steven Enamakel31d579f9f182
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rsindex 7b4d6482a9..b8cc75aaba 100644--- a/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents/cancel.rs@@ -158,14 +158,15 @@ pub(crate) fn stop_for_thread(let jobs = crate::core::runtime::slot_for::<tinyagents_orchestration::subagent::SubAgentJobRegistry,>(ctx);- let driver_stopped = crate::agent::orchestration::subagent_sessions::cancel_driver_jobs_for_thread(- &crate::agent::orchestration::subagent_sessions::SubagentSessionStore::new(- workspace_dir.clone(),- ),- &workspace_dir,- &jobs,- thread_id,- );+ let driver_stopped =+ crate::agent::orchestration::subagent_sessions::cancel_driver_jobs_for_thread(+ &crate::agent::orchestration::subagent_sessions::SubagentSessionStore::new(+ workspace_dir.clone(),+ ),+ &workspace_dir,+ &jobs,+ thread_id,+ );for task_id in driver_stopped {if !task_ids.contains(&task_id) {task_ids.push(task_id);diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/mod.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/mod.rsindex 552ae159b4..b7ab58945b 100644--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/mod.rs+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/mod.rs@@ -5,9 +5,9 @@ mod tiny_port;mod types;pub use ops::{- action_root_key, cancel_driver_jobs_for_thread, close, find_reusable, list_for_parent, mark_failed, mark_finished,- normalize_task_key, resolve_lifecycle_key, reuse_decision, task_title_from_prompt,- upsert_running,+ action_root_key, cancel_driver_jobs_for_thread, close, find_reusable, list_for_parent,+ mark_failed, mark_finished, normalize_task_key, resolve_lifecycle_key, reuse_decision,+ task_title_from_prompt, upsert_running,};pub(crate) use tiny_port::OpenHumanTinySubagentSessionStore;pub use types::{diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops.rsindex 64d54696ef..a19dd2c6e4 100644--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops.rs+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/ops.rs@@ -25,7 +25,9 @@ pub fn cancel_driver_jobs_for_thread(let sessions = match store.load() {Ok(sessions) => sessions,Err(error) => {- log::warn!("[subagent_sessions] failed to load sessions for thread cancellation: {error}");+ log::warn!(+ "[subagent_sessions] failed to load sessions for thread cancellation: {error}"+ );return Vec::new();}};diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port.rsindex c013b62d4e..7c6f041200 100644--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port.rs+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port.rs@@ -122,9 +122,9 @@ impl TinySessionStore for OpenHumanTinySubagentSessionStore {if parent_session != self.parent_session {return Ok(Vec::new());}- if parent_thread_id.is_some_and(|requested| {- self.parent_thread_id.as_deref() != Some(requested)- }) {+ if parent_thread_id+ .is_some_and(|requested| self.parent_thread_id.as_deref() != Some(requested))+ {return Ok(Vec::new());}super::list_for_parent(@@ -132,11 +132,11 @@ impl TinySessionStore for OpenHumanTinySubagentSessionStore {parent_session,self.parent_thread_id.as_deref(),)- .map_err(SubagentError::Persistence)?- .into_iter()- .filter(|row| self.is_owned(row))- .map(|row| self.convert(row))- .collect()+ .map_err(SubagentError::Persistence)?+ .into_iter()+ .filter(|row| self.is_owned(row))+ .map(|row| self.convert(row))+ .collect()}async fn get(&self, id: &str) -> Result<Option<TinySession>, SubagentError> {diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port_tests.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port_tests.rsindex 1249fe52d5..29e541161e 100644--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/tiny_port_tests.rs@@ -90,11 +90,8 @@ async fn unthreaded_port_lists_only_unthreaded_rows() {threaded.parent_thread_id = Some("thread-a".into());store.save(&[unthreaded, threaded]).unwrap();- let port = OpenHumanTinySubagentSessionStore::new(- workspace.path().to_path_buf(),- "owner",- None,- );+ let port =+ OpenHumanTinySubagentSessionStore::new(workspace.path().to_path_buf(), "owner", None);let sessions = port.list_for_parent("owner", None).await.unwrap();assert_eq!(sessions.len(), 1);assert_eq!(sessions[0].subagent_session_id, "unthreaded-session");@@ -122,42 +119,59 @@ async fn upsert_rejects_a_selector_or_lifecycle_key_outside_bound_scope() {task_id: task_id.into(),}};- let upsert = |parent_session: &str,- parent_thread_id: Option<&str>,- lifecycle_key: tinyagents_orchestration::subagent::SubagentTaskKey| {- TinyUpsert {- selector: TinySelector {- parent_session: parent_session.into(),- parent_thread_id: parent_thread_id.map(str::to_owned),- agent_id: "researcher".into(),- model: None,- sandbox_mode: "workspace".into(),- action_root: None,- task_key: "analysis".into(),- },- lifecycle_key,- display_name: None,- task_title: "Task".into(),- worker_thread_id: None,- task_id: "task-1".into(),- force_fresh: true,- }- };+ let upsert =+ |parent_session: &str,+ parent_thread_id: Option<&str>,+ lifecycle_key: tinyagents_orchestration::subagent::SubagentTaskKey| {+ TinyUpsert {+ selector: TinySelector {+ parent_session: parent_session.into(),+ parent_thread_id: parent_thread_id.map(str::to_owned),+ agent_id: "researcher".into(),+ model: None,+ sandbox_mode: "workspace".into(),+ action_root: None,+ task_key: "analysis".into(),+ },+ lifecycle_key,+ display_name: None,+ task_title: "Task".into(),+ worker_thread_id: None,+ task_id: "task-1".into(),+ force_fresh: true,+ }+ };assert!(port- .upsert_running(upsert("foreign", Some("thread-a"), key(Some("thread-a"), "task-1")))+ .upsert_running(upsert(+ "foreign",+ Some("thread-a"),+ key(Some("thread-a"), "task-1")+ )).await.is_err());assert!(port- .upsert_running(upsert("owner", Some("thread-b"), key(Some("thread-b"), "task-1")))+ .upsert_running(upsert(+ "owner",+ Some("thread-b"),+ key(Some("thread-b"), "task-1")+ )).await.is_err());assert!(port- .upsert_running(upsert("owner", Some("thread-a"), key(Some("thread-b"), "task-1")))+ .upsert_running(upsert(+ "owner",+ Some("thread-a"),+ key(Some("thread-b"), "task-1")+ )).await.is_err());assert!(port- .upsert_running(upsert("owner", Some("thread-a"), key(Some("thread-a"), "other-task")))+ .upsert_running(upsert(+ "owner",+ Some("thread-a"),+ key(Some("thread-a"), "other-task")+ )).await.is_err());assert!(store.load().unwrap().is_empty());diff --git a/crates/openhuman-core/src/agent/subagent_host/ops_tests_model_resolution_tests.rs b/crates/openhuman-core/src/agent/subagent_host/ops_tests_model_resolution_tests.rsindex f119451c91..9ca6e4eaea 100644--- a/crates/openhuman-core/src/agent/subagent_host/ops_tests_model_resolution_tests.rs+++ b/crates/openhuman-core/src/agent/subagent_host/ops_tests_model_resolution_tests.rs@@ -94,6 +94,42 @@ async fn prepared_async_spawn_runs_through_driver_jobs_dispatcher() {);}+#[tokio::test]+async fn stopped_parent_thread_rejects_a_new_driver_spawn_before_execution() {+ let scratch = tempfile::tempdir().expect("isolated stopped-thread fixture");+ let workspace = scratch.path().join("workspace");+ std::fs::create_dir_all(&workspace).expect("create isolated workspace");+ let provider = ScriptedProvider::new(vec![text_response("must not run")]);+ let mut parent_context = make_parent(provider.clone(), vec![]);+ parent_context.workspace_dir = workspace;+ let mut options = with_parent(parent_context, SubagentRunOptions::default());+ options.checkpoint_dir = Some(scratch.path().join("checkpoints"));+ options.run_context.thread_id = Some("stopped-driver-thread".into());+ let parent = options.run_context.clone().into_tinyagents(+ tinyagents_harness::context::RunConfig::new("stopped-driver-parent")+ .with_thread("stopped-driver-thread"),+ );+ let dispatch_ctx = parent.data.dispatch_ctx();+ crate::agent::orchestration::background_completions::discard_pending_for_thread(+ &dispatch_ctx,+ "stopped-driver-thread",+ );++ let result = run_async_spawn_via_driver_tool(+ &parent,+ make_def_named_tools(&[]),+ "return the requested result".into(),+ options,+ )+ .await;++ assert!(result.is_err(), "stopped thread must reject new children");+ assert!(+ provider.captured.lock().is_empty(),+ "the child model must not run after Stop"+ );+}+#[tokio::test]async fn detached_driver_spawn_repairs_replayed_host_outcome_without_reexecution() {let scratch = tempfile::tempdir().expect("isolated async spawn fixture");diff --git a/crates/openhuman-core/src/threads/ops/crud.rs b/crates/openhuman-core/src/threads/ops/crud.rsindex 948532fe82..023d22feb4 100644--- a/crates/openhuman-core/src/threads/ops/crud.rs+++ b/crates/openhuman-core/src/threads/ops/crud.rs@@ -494,13 +494,14 @@ async fn thread_delete_inner(let jobs = crate::core::runtime::slot_for::<tinyagents_orchestration::subagent::SubAgentJobRegistry,>(&ctx);- let cancelled_driver = crate::agent::orchestration::subagent_sessions::cancel_driver_jobs_for_thread(- &crate::agent::orchestration::subagent_sessions::SubagentSessionStore::new(dir.clone()),- &dir,- &jobs,- &request.thread_id,- )- .len();+ let cancelled_driver =+ crate::agent::orchestration::subagent_sessions::cancel_driver_jobs_for_thread(+ &crate::agent::orchestration::subagent_sessions::SubagentSessionStore::new(dir.clone()),+ &dir,+ &jobs,+ &request.thread_id,+ )+ .len();let cancelled = cancelled_legacy + cancelled_driver;let discarded = crate::agent::orchestration::background_completions::discard_for_thread(&ctx,