Skip to content

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

test(session_host): cover child usage rollup deduplication

Steven Enamakela781f34ea07f
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs
index c0f08988a9..86a9a4ad92 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs
@@ -220,6 +220,62 @@ fn last_turn_usage_reports_the_same_holistic_totals_as_transcript_billing() {
assert_eq!(usage.subagents.len(), 1, "detail breakdown is retained");
}
+#[test]
+fn child_usage_rollup_deduplicates_runs_without_merging_repeated_task_ids() {
+ let charged = tinyagents_harness::cost::CostTally {
+ known_usd: 0.004,
+ source: tinyagents_harness::cost::CostSource::Charged,
+ };
+ let inclusive_child = crate::agent::tinyagents::host::SubagentUsageEntry {
+ run_id: "run-inclusive-child".into(),
+ task_id: "reused-task".into(),
+ agent_id: "researcher".into(),
+ usage: crate::agent::subagent_host::SubagentUsage {
+ // This completed child's total already includes its own model
+ // calls and the grandchild which completed inside its isolated
+ // ledger. The host records the subtree once as this one entry.
+ input_tokens: 20,
+ output_tokens: 8,
+ cached_input_tokens: 3,
+ charged_amount_usd: charged.known_usd,
+ cost_source: charged.source,
+ },
+ };
+ let mut sidecar = crate::agent::tinyagents::host::run_context::SessionTurnSidecar {
+ input_tokens: 10,
+ output_tokens: 4,
+ cost: charged,
+ ..Default::default()
+ };
+ sidecar.subagents.extend([
+ inclusive_child.clone(),
+ inclusive_child,
+ crate::agent::tinyagents::host::SubagentUsageEntry {
+ // Same task, distinct actual execution: its usage is retained.
+ run_id: "run-second-execution".into(),
+ task_id: "reused-task".into(),
+ agent_id: "researcher".into(),
+ usage: crate::agent::subagent_host::SubagentUsage {
+ input_tokens: 7,
+ output_tokens: 2,
+ cost_source: tinyagents_harness::cost::CostSource::Unknown,
+ ..Default::default()
+ },
+ },
+ ]);
+
+ let usage = holistic_last_turn_usage(&sidecar);
+ assert_eq!(usage.input_tokens, 37);
+ assert_eq!(usage.output_tokens, 14);
+ assert_eq!(usage.cached_input_tokens, 3);
+ assert_eq!(usage.subagents.len(), 2, "duplicate run rows are omitted");
+ assert_eq!(usage.cost_usd, None, "unknown child cost remains unknown");
+ assert_eq!(
+ usage.cost_source,
+ tinyagents_harness::cost::CostSource::Unknown
+ );
+}
+
#[test]
fn explicit_hidden_delegate_stays_hidden_across_dynamic_refreshes() {
let mut visible = ["read_file".to_string()]
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
index d25a668ff0..42a69dee52 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context_tests.rs
@@ -206,6 +206,7 @@ fn failed_outer_run_promotes_completed_nested_usage_once() {
outer.promote_completed_descendant_usage();
assert_eq!(root.subagent_usage_entries().len(), 1);
assert_eq!(root.subagent_usage_entries()[0].task_id, "nested");
+ assert_eq!(root.subagent_usage_entries()[0].run_id, "run-nested");
}
#[test]