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_host): move native trace export test into its own module
Steven Enamakel945cb37b36a4
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops_tests_driver_bridge_tests.rs b/crates/openhuman-core/src/agent/subagent_host/ops_tests_driver_bridge_tests.rsindex f42a35ee37..ba4079c714 100644--- a/crates/openhuman-core/src/agent/subagent_host/ops_tests_driver_bridge_tests.rs+++ b/crates/openhuman-core/src/agent/subagent_host/ops_tests_driver_bridge_tests.rs@@ -43,229 +43,6 @@ async fn prepared_subagent_runs_through_driver_jobs_dispatcher() {);}-/// The native journal tree must preserve the exact run identity handed to the-/// prepared child by Tiny's driver, including the host lifecycle link and the-/// durable child observations. This exercises the OpenHuman executor, not a-/// collector fixture assembled from synthetic observations.-#[tokio::test]-async fn prepared_child_run_is_exported_from_its_native_journal_lineage() {- use tinyagents_harness::events::AgentEvent;- use tinyagents_harness::observability::trace_export::{- collector::SpanCollector, serialize::spans_to_ndjson, TraceContext,- };-- let scratch = tempfile::tempdir().expect("isolated native trace fixture");- let workspace = scratch.path().join("workspace");- std::fs::create_dir_all(&workspace).expect("create isolated workspace");- let mut config = crate::config::Config::default();- config.workspace_dir = workspace.clone();- config.components.juice = false;- config.observability.agent_tracing.capture_content = false;- let capture_content = config.observability.agent_tracing.capture_content;- let core = crate::core::runtime::CoreContext::for_test_with_config(- crate::core::runtime::DomainSet::full(),- config,- );-- let mut response = text_response("private-child-answer-should-not-be-exported");- let reported_usage = tinyinference_llm::usage::Usage {- input_tokens: 120,- output_tokens: 8,- total_tokens: 128,- cache_read_tokens: 20,- charged_amount: Some(tinyinference_llm::usage::ChargedAmount::usd_micros(4_200)),- ..Default::default()- };- response.usage = Some(reported_usage);- response.message.usage = Some(reported_usage);- let provider = ScriptedProvider::new(vec![response]);- let mut parent_context = make_parent(provider.clone(), vec![]);- parent_context.workspace_dir = workspace.clone();- let mut options = with_parent(parent_context, SubagentRunOptions::default());- options.run_context = options.run_context.with_core(Some(Arc::clone(&core)));- options.run_context.thread_id = Some("native-trace-thread".into());- let root_config = tinyagents_harness::context::RunConfig::new("native-trace-root")- .with_thread("native-trace-thread");- let root_run_id = root_config.run_id.clone();- let parent = options.run_context.clone().into_tinyagents(root_config);- let dispatch = parent.data.dispatch_ctx();- let _parent_journal = crate::agent::tinyagents::journal::attach_turn_journal(- &dispatch,- &parent.events,- "parent-model",- root_run_id.clone(),- parent.config.thread_id.clone(),- None,- root_run_id.clone(),- )- .await- .expect("the isolated workspace attaches the root journal");- parent.events.emit(AgentEvent::RunStarted {- run_id: root_run_id.clone(),- thread_id: parent.config.thread_id.clone(),- });-- let mut options = options;- options.checkpoint_dir = Some(scratch.path().join("checkpoints"));- options.thread_id = Some("native-trace-thread".into());- options.model_override = Some("gpt-4o".into());- let (outcome, _job_id) = run_subagent_via_driver_tool(- &parent,- make_def_named_tools(&[]),- "answer without exposing the private sentinel".into(),- options,- )- .await- .expect("driver-backed child run completes");- assert!(matches!(outcome.status, SubagentRunStatus::Completed));- assert_eq!(provider.captured.lock().len(), 1);-- parent.events.emit(AgentEvent::RunCompleted {- run_id: root_run_id.clone(),- outcome: None,- });- parent.events.emit(AgentEvent::RunFinalized {- run_id: root_run_id.clone(),- });- _parent_journal.finish_completed().await;-- let observations =- crate::agent::tinyagents::journal::read_run_tree_events(&dispatch, root_run_id.as_str())- .await- .expect("lineage-indexed journals load as a tree");- assert!(!observations.is_empty(), "the root stream is durable");- let child_run_id = observations- .iter()- .find_map(|observation| match &observation.event {- AgentEvent::SubAgentRunStarted { run_id, .. } => Some(run_id.clone()),- _ => None,- })- .expect("the host lifecycle link names the actual prepared child run");- let child_observations: Vec<_> = observations- .iter()- .filter(|observation| observation.run_id == child_run_id)- .collect();- let child_finalized_at = child_observations- .iter()- .find_map(|observation| match &observation.event {- AgentEvent::RunFinalized { run_id } if run_id == &child_run_id => {- Some(observation.ts_ms)- }- _ => None,- })- .expect("the child journal is finalized after the host adapter returns");- let parent_ack_at = observations- .iter()- .find_map(|observation| match &observation.event {- AgentEvent::SubAgentRunCompleted { run_id } if run_id == &child_run_id => {- Some(observation.ts_ms)- }- _ => None,- })- .expect("the parent acknowledges the same child identity");- assert!(- parent_ack_at >= child_finalized_at,- "parent completion follows child durable finalization"- );- assert!(- child_observations.iter().all(|observation| {- observation.parent_run_id.as_ref() == Some(&root_run_id)- && observation.root_run_id == root_run_id- }),- "the persisted child stream keeps actual parent/root lineage"- );- let reported_call = child_observations- .iter()- .find_map(|observation| match &observation.event {- AgentEvent::ModelCompleted {- call_id,- usage: Some(usage),- input,- output,- ..- } => {- assert_eq!(- usage.charged_amount.map(|amount| amount.micros),- Some(4_200)- );- assert_eq!(usage.input_tokens, 120);- assert_eq!(usage.output_tokens, 8);- assert!(- input.is_some() && output.is_some(),- "the private native journal retains source observations"- );- Some(call_id.clone())- }- _ => None,- })- .expect("the real host model response is journaled with provider usage");- assert!(- child_observations.iter().any(|observation| matches!(- &observation.event,- AgentEvent::GenerationEnriched { call_id, enrichment }- if call_id == &reported_call- && enrichment.provider_id.is_some()- && enrichment.pricing.is_some()- )),- "host provider and catalog pricing accompany the actual generation"- );-- let trace_context = TraceContext::new("native-trace-root", None)- .with_session_group("native-trace-thread")- .with_capture_content(capture_content)- .with_run_lineage(- Some(root_run_id.as_str().into()),- None,- Some(root_run_id.as_str().into()),- );- let mut collector = SpanCollector::new(trace_context);- for observation in &observations {- collector.record(observation);- }- collector.finish(- observations- .iter()- .map(|observation| observation.ts_ms)- .max()- .unwrap_or_default()- .saturating_add(1),- );- let spans = collector.spans();- let child_span = spans- .iter()- .find(|span| {- span.attributes- .get("run_id")- .is_some_and(|id| id == child_run_id.as_str())- })- .expect("native collector projects the actual linked child");- assert_eq!(child_span.attributes["parent_run_id"], root_run_id.as_str());- assert_eq!(child_span.attributes["root_run_id"], root_run_id.as_str());- let generation = spans- .iter()- .find(|span| {- span.attributes- .get("gen_ai.request.model")- .is_some_and(|_| {- span.attributes.get("gen_ai.usage.cost_usd") == Some(&serde_json::json!(0.0042))- })- })- .expect("native projection preserves the provider-reported charge");- assert_eq!(generation.attributes["gen_ai.usage.input_tokens"], 120);- assert_eq!(generation.attributes["gen_ai.usage.output_tokens"], 8);- assert!(generation- .attributes- .contains_key("gen_ai.pricing.input_per_mtok_usd"));- let exported = spans_to_ndjson(- tinyagents_harness::observability::trace_export::serialize::SpanEnvelope::Otel,- spans,- );- assert!(- !exported.contains("private-child-answer-should-not-be-exported"),- "the native export keeps captured content off"- );-}-struct BlockingCrossBundleTool {started: tokio::sync::mpsc::Sender<()>,release: Arc<tokio::sync::Notify>,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 83d6f607c6..a665d6c8ab 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@@ -683,3 +683,6 @@ fn nested_subagent_dispatch_runs_on_a_constrained_worker_stack() {#[path = "ops_tests_driver_bridge_tests.rs"]mod driver_bridge_tests;++#[path = "ops_tests_trace_export_tests.rs"]+mod trace_export_tests;diff --git a/crates/openhuman-core/src/agent/subagent_host/ops_tests_trace_export_tests.rs b/crates/openhuman-core/src/agent/subagent_host/ops_tests_trace_export_tests.rsnew file mode 100644index 0000000000..f859256861--- /dev/null+++ b/crates/openhuman-core/src/agent/subagent_host/ops_tests_trace_export_tests.rs@@ -0,0 +1,225 @@+use super::*;++/// The native journal tree must preserve the exact run identity handed to the+/// prepared child by Tiny's driver, including the host lifecycle link and the+/// durable child observations. This exercises the OpenHuman executor, not a+/// collector fixture assembled from synthetic observations.+#[tokio::test]+async fn prepared_child_run_is_exported_from_its_native_journal_lineage() {+ use tinyagents_harness::events::AgentEvent;+ use tinyagents_harness::observability::trace_export::{+ collector::SpanCollector, serialize::spans_to_ndjson, TraceContext,+ };++ let scratch = tempfile::tempdir().expect("isolated native trace fixture");+ let workspace = scratch.path().join("workspace");+ std::fs::create_dir_all(&workspace).expect("create isolated workspace");+ let mut config = crate::config::Config::default();+ config.workspace_dir = workspace.clone();+ config.components.juice = false;+ config.observability.agent_tracing.capture_content = false;+ let capture_content = config.observability.agent_tracing.capture_content;+ let core = crate::core::runtime::CoreContext::for_test_with_config(+ crate::core::runtime::DomainSet::full(),+ config,+ );++ let mut response = text_response("private-child-answer-should-not-be-exported");+ let reported_usage = tinyinference_llm::usage::Usage {+ input_tokens: 120,+ output_tokens: 8,+ total_tokens: 128,+ cache_read_tokens: 20,+ charged_amount: Some(tinyinference_llm::usage::ChargedAmount::usd_micros(4_200)),+ ..Default::default()+ };+ response.usage = Some(reported_usage);+ response.message.usage = Some(reported_usage);+ let provider = ScriptedProvider::new(vec![response]);+ let mut parent_context = make_parent(provider.clone(), vec![]);+ parent_context.workspace_dir = workspace.clone();+ let mut options = with_parent(parent_context, SubagentRunOptions::default());+ options.run_context = options.run_context.with_core(Some(Arc::clone(&core)));+ options.run_context.thread_id = Some("native-trace-thread".into());+ let root_config = tinyagents_harness::context::RunConfig::new("native-trace-root")+ .with_thread("native-trace-thread");+ let root_run_id = root_config.run_id.clone();+ let parent = options.run_context.clone().into_tinyagents(root_config);+ let dispatch = parent.data.dispatch_ctx();+ let _parent_journal = crate::agent::tinyagents::journal::attach_turn_journal(+ &dispatch,+ &parent.events,+ "parent-model",+ root_run_id.clone(),+ parent.config.thread_id.clone(),+ None,+ root_run_id.clone(),+ )+ .await+ .expect("the isolated workspace attaches the root journal");+ parent.events.emit(AgentEvent::RunStarted {+ run_id: root_run_id.clone(),+ thread_id: parent.config.thread_id.clone(),+ });++ let mut options = options;+ options.checkpoint_dir = Some(scratch.path().join("checkpoints"));+ options.thread_id = Some("native-trace-thread".into());+ options.model_override = Some("gpt-4o".into());+ let (outcome, _job_id) = run_subagent_via_driver_tool(+ &parent,+ make_def_named_tools(&[]),+ "answer without exposing the private sentinel".into(),+ options,+ )+ .await+ .expect("driver-backed child run completes");+ assert!(matches!(outcome.status, SubagentRunStatus::Completed));+ assert_eq!(provider.captured.lock().len(), 1);++ parent.events.emit(AgentEvent::RunCompleted {+ run_id: root_run_id.clone(),+ outcome: None,+ });+ parent.events.emit(AgentEvent::RunFinalized {+ run_id: root_run_id.clone(),+ });+ _parent_journal.finish_completed().await;++ let observations =+ crate::agent::tinyagents::journal::read_run_tree_events(&dispatch, root_run_id.as_str())+ .await+ .expect("lineage-indexed journals load as a tree");+ assert!(!observations.is_empty(), "the root stream is durable");+ let child_run_id = observations+ .iter()+ .find_map(|observation| match &observation.event {+ AgentEvent::SubAgentRunStarted { run_id, .. } => Some(run_id.clone()),+ _ => None,+ })+ .expect("the host lifecycle link names the actual prepared child run");+ let child_observations: Vec<_> = observations+ .iter()+ .filter(|observation| observation.run_id == child_run_id)+ .collect();+ let child_finalized_at = child_observations+ .iter()+ .find_map(|observation| match &observation.event {+ AgentEvent::RunFinalized { run_id } if run_id == &child_run_id => {+ Some(observation.ts_ms)+ }+ _ => None,+ })+ .expect("the child journal is finalized after the host adapter returns");+ let parent_ack_at = observations+ .iter()+ .find_map(|observation| match &observation.event {+ AgentEvent::SubAgentRunCompleted { run_id } if run_id == &child_run_id => {+ Some(observation.ts_ms)+ }+ _ => None,+ })+ .expect("the parent acknowledges the same child identity");+ assert!(+ parent_ack_at >= child_finalized_at,+ "parent completion follows child durable finalization"+ );+ assert!(+ child_observations.iter().all(|observation| {+ observation.parent_run_id.as_ref() == Some(&root_run_id)+ && observation.root_run_id == root_run_id+ }),+ "the persisted child stream keeps actual parent/root lineage"+ );+ let reported_call = child_observations+ .iter()+ .find_map(|observation| match &observation.event {+ AgentEvent::ModelCompleted {+ call_id,+ usage: Some(usage),+ input,+ output,+ ..+ } => {+ assert_eq!(+ usage.charged_amount.map(|amount| amount.micros),+ Some(4_200)+ );+ assert_eq!(usage.input_tokens, 120);+ assert_eq!(usage.output_tokens, 8);+ assert!(+ input.is_some() && output.is_some(),+ "the private native journal retains source observations"+ );+ Some(call_id.clone())+ }+ _ => None,+ })+ .expect("the real host model response is journaled with provider usage");+ assert!(+ child_observations.iter().any(|observation| matches!(+ &observation.event,+ AgentEvent::GenerationEnriched { call_id, enrichment }+ if call_id == &reported_call+ && enrichment.provider_id.is_some()+ && enrichment.pricing.is_some()+ )),+ "host provider and catalog pricing accompany the actual generation"+ );++ let trace_context = TraceContext::new("native-trace-root", None)+ .with_session_group("native-trace-thread")+ .with_capture_content(capture_content)+ .with_run_lineage(+ Some(root_run_id.as_str().into()),+ None,+ Some(root_run_id.as_str().into()),+ );+ let mut collector = SpanCollector::new(trace_context);+ for observation in &observations {+ collector.record(observation);+ }+ collector.finish(+ observations+ .iter()+ .map(|observation| observation.ts_ms)+ .max()+ .unwrap_or_default()+ .saturating_add(1),+ );+ let spans = collector.spans();+ let child_span = spans+ .iter()+ .find(|span| {+ span.attributes+ .get("run_id")+ .is_some_and(|id| id == child_run_id.as_str())+ })+ .expect("native collector projects the actual linked child");+ assert_eq!(child_span.attributes["parent_run_id"], root_run_id.as_str());+ assert_eq!(child_span.attributes["root_run_id"], root_run_id.as_str());+ let generation = spans+ .iter()+ .find(|span| {+ span.attributes+ .get("gen_ai.request.model")+ .is_some_and(|_| {+ span.attributes.get("gen_ai.usage.cost_usd") == Some(&serde_json::json!(0.0042))+ })+ })+ .expect("native projection preserves the provider-reported charge");+ assert_eq!(generation.attributes["gen_ai.usage.input_tokens"], 120);+ assert_eq!(generation.attributes["gen_ai.usage.output_tokens"], 8);+ assert!(generation+ .attributes+ .contains_key("gen_ai.pricing.input_per_mtok_usd"));+ let exported = spans_to_ndjson(+ tinyagents_harness::observability::trace_export::serialize::SpanEnvelope::Otel,+ spans,+ );+ assert!(+ !exported.contains("private-child-answer-should-not-be-exported"),+ "the native export keeps captured content off"+ );+}+