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): pass parent context explicitly in team and builder tests
Steven Enamakelaf70cbec2f99
diff --git a/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime_tests.rs b/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime_tests.rsindex 2c7281492e..d32a524a2f 100644--- a/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime_tests.rs@@ -1,7 +1,7 @@//! Live-runtime unit tests (#3374 PR4).//!//! The worker-driving core ([`super::drive_member`]) is exercised directly with-//! a mock `ChatModel` installed via [`with_parent_context`] (mirroring+//! a mock `ChatModel` passed as the explicit parent (mirroring//! `workflow_runs::engine_tests`), so a teammate runs deterministically without//! touching the network. [`super::start_member_run`]'s pre-spawn outcome routing//! (blocked / already-claimed / no-claimable / unknown) is tested through the@@ -14,7 +14,7 @@ use std::sync::Arc;use async_trait::async_trait;use super::*;-use crate::agent::harness::fork_context::{with_parent_context, ParentExecutionContext};+use crate::agent::harness::fork_context::ParentExecutionContext;use crate::agent::harness::host_definition::AgentDefinitionRegistry;use crate::config::{AgentConfig, Config};use tinyagents_orchestration::teams::{SessionTeamLedger, TeamService};@@ -200,18 +200,16 @@ async fn drive_member_completes_task_with_worker_output_as_evidence() {output: "did the thing".into(),fail: false,});- with_parent_context(mock_parent(provider), async {- drive_member(- &config,- "team-1",- "m1",- "task_manager_agent",- &task,- "teamrun-x",- Some("test-model".into()),- )- .await- })+ drive_member(+ &config,+ "team-1",+ "m1",+ "task_manager_agent",+ &task,+ "teamrun-x",+ Some("test-model".into()),+ mock_parent(provider),+ ).await.expect("drive_member ok");@@ -231,12 +229,12 @@ async fn drive_member_completes_task_with_worker_output_as_evidence() {}/// Covers `run_member_loop` — the `with_root_parent` wrapper around-/// `drive_member`. With a mock parent already installed, `with_root_parent`-/// reuses it (rather than building a real root), so the member drives to+/// `drive_member`. With a mock parent passed explicitly, `with_root_parent`+/// uses it (rather than building a real root), so the member drives to/// completion under the canned provider. Same setup as the `drive_member`/// happy-path test, but through the wrapper the live runtime spawns.#[tokio::test]-async fn run_member_loop_drives_member_under_ambient_parent() {+async fn run_member_loop_drives_member_under_an_explicit_parent() {AgentDefinitionRegistry::init_global_builtins().unwrap();let (_dir, config) = test_config();seed_team(&config, "team-1");@@ -268,18 +266,16 @@ async fn run_member_loop_drives_member_under_ambient_parent() {output: "did the thing".into(),fail: false,});- with_parent_context(mock_parent(provider), async {- run_member_loop(- &config,- "team-1",- "m1",- "task_manager_agent",- task,- "teamrun-y",- Some("test-model".into()),- )- .await- })+ run_member_loop(+ &config,+ "team-1",+ "m1",+ "task_manager_agent",+ task,+ "teamrun-y",+ Some("test-model".into()),+ Some(mock_parent(provider)),+ ).await;let done = run_ledger::get_agent_team_task(&config.workspace_dir, "task-a")@@ -325,18 +321,16 @@ async fn drive_member_releases_task_when_worker_fails() {output: String::new(),fail: true,});- with_parent_context(mock_parent(provider), async {- drive_member(- &config,- "team-1",- "m1",- "task_manager_agent",- &task,- "teamrun-x",- Some("test-model".into()),- )- .await- })+ drive_member(+ &config,+ "team-1",+ "m1",+ "task_manager_agent",+ &task,+ "teamrun-x",+ Some("test-model".into()),+ mock_parent(provider),+ ).await.expect("drive_member handles worker failure without erroring");diff --git a/crates/openhuman-core/src/agent/orchestration/parent_context/builder_tests.rs b/crates/openhuman-core/src/agent/orchestration/parent_context/builder_tests.rsindex 37b6e493f3..01123398de 100644--- a/crates/openhuman-core/src/agent/orchestration/parent_context/builder_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/parent_context/builder_tests.rs@@ -1,5 +1,4 @@use super::*;-use crate::agent::harness::fork_context::current_parent;fn test_config() -> (tempfile::TempDir, Config) {let dir = tempfile::tempdir().expect("tempdir");@@ -10,58 +9,65 @@ fn test_config() -> (tempfile::TempDir, Config) {(dir, config)}-/// Baseline for the bug: with no enclosing agent turn there is no ambient-/// parent — exactly the state a background surface spawned `context_scout`-/// in (TAURI-RUST-HMW / #4337), which made `run_subagent` return-/// `NoParentContext`.+/// Regression (TAURI-RUST-HMW / #4337): `with_root_parent` must hand a real+/// parent to the wrapped closure so a background orchestration surface (cron+/// job, workflow engine, team runtime) can spawn sub-agents without hitting+/// `NoParentContext`. Proven by observing the parent the closure receives.#[tokio::test]-async fn no_ambient_parent_outside_with_root_parent() {- assert!(- current_parent().is_none(),- "no parent context should be installed by default"- );-}--/// Regression (TAURI-RUST-HMW / #4337): `with_root_parent` must install a-/// real parent for the wrapped future so a background orchestration surface-/// (cron job, workflow engine, team runtime) can spawn sub-agents-/// without hitting `NoParentContext`. Proven by observing the installed-/// parent from inside the future.-#[tokio::test]-async fn with_root_parent_installs_parent_for_inner_future() {+async fn with_root_parent_hands_a_root_parent_to_the_closure() {let (_dir, config) = test_config();- let observed = with_root_parent(&config, "cron", "cron", "cron", async {- current_parent().map(|p| p.agent_definition_id)+ let observed = with_root_parent(None, &config, "cron", "cron", "cron", |parent| async move {+ parent.agent_definition_id}).await.expect("root parent builds from config");assert_eq!(- observed.as_deref(),- Some("cron"),- "inner future must observe the installed root parent"+ observed, "cron",+ "the closure must receive the root parent built from config");}-/// When a parent is already installed, `with_root_parent` reuses it instead-/// of building a second root — so a surface nested in a turn (or a test-/// driving it under a mock parent) runs under the ambient context.+/// When a parent is passed explicitly, `with_root_parent` uses it instead of+/// building a second root, so a test can drive a surface under a mock parent+/// (and thus a mock provider) hermetically.#[tokio::test]-async fn with_root_parent_reuses_ambient_parent() {+async fn with_root_parent_uses_an_explicit_parent_override() {let (_dir, config) = test_config();let outer = build_root_parent(&config, "outer", "outer", "outer").await- .expect("build ambient parent");- let observed = with_parent_context(outer, async {- with_root_parent(&config, "inner", "inner", "inner", async {- current_parent().map(|p| p.agent_definition_id)- })- .await- .expect("reuses ambient, no build error")- })- .await;+ .expect("build explicit parent");+ let observed = with_root_parent(+ Some(outer),+ &config,+ "inner",+ "inner",+ "inner",+ |parent| async move { parent.agent_definition_id },+ )+ .await+ .expect("uses the override, no build error");assert_eq!(- observed.as_deref(),- Some("outer"),- "with_root_parent must reuse the ambient parent, not build a new 'inner' root"+ observed, "outer",+ "with_root_parent must use the explicit parent, not build a new 'inner' root"+ );+}++/// The parent a surface spawns under is the value the closure received, not+/// something read from the executing task: two concurrent surfaces on one+/// runtime each see their own root.+#[tokio::test]+async fn concurrent_root_parents_do_not_cross() {+ let (_dir, config) = test_config();+ let (a, b) = tokio::join!(+ with_root_parent(None, &config, "surface_a", "a", "a", |parent| async move {+ tokio::task::yield_now().await;+ parent.agent_definition_id+ }),+ with_root_parent(None, &config, "surface_b", "b", "b", |parent| async move {+ tokio::task::yield_now().await;+ parent.agent_definition_id+ }),);+ assert_eq!(a.expect("a"), "surface_a");+ assert_eq!(b.expect("b"), "surface_b");}