Skip to content

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

test(session_host): register runtime adapter usage tests

Steven Enamakel270c8bb20860
diff --git a/crates/openhuman-core/src/agent/session_host/mod.rs b/crates/openhuman-core/src/agent/session_host/mod.rs
index e58cc7b1f4..6726b46397 100644
--- a/crates/openhuman-core/src/agent/session_host/mod.rs
+++ b/crates/openhuman-core/src/agent/session_host/mod.rs
@@ -74,6 +74,8 @@ mod runtime_adapter_session_state_tests;
#[cfg(test)]
mod runtime_adapter_tests;
#[cfg(test)]
+mod runtime_adapter_usage_tests;
+#[cfg(test)]
mod transcript_compat_tests;
#[cfg(test)]
#[path = "transcript_resume_stable_tests.rs"]
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_adapter_usage_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_adapter_usage_tests.rs
new file mode 100644
index 0000000000..b01e3eb08a
--- /dev/null
+++ b/crates/openhuman-core/src/agent/session_host/runtime_adapter_usage_tests.rs
@@ -0,0 +1,93 @@
+use super::runtime_session::{account_committed_turn_against_goal, holistic_last_turn_usage};
+
+#[test]
+fn inclusive_child_usage_counts_each_public_entry_once_and_keeps_unknown_cost() {
+ let charged = tinyagents_harness::cost::CostTally {
+ known_usd: 0.002,
+ source: tinyagents_harness::cost::CostSource::Charged,
+ };
+ let mut sidecar = crate::agent::tinyagents::host::run_context::SessionTurnSidecar {
+ input_tokens: 10,
+ output_tokens: 4,
+ cost: charged,
+ ..Default::default()
+ };
+ sidecar.subagents = vec![
+ crate::agent::tinyagents::host::SubagentUsageEntry {
+ task_id: "reused-task".into(),
+ agent_id: "researcher".into(),
+ usage: crate::agent::subagent_host::SubagentUsage {
+ // Includes this run's grandchild totals; that grandchild is
+ // intentionally absent as a separate public ledger entry.
+ input_tokens: 20,
+ output_tokens: 8,
+ cached_input_tokens: 3,
+ charged_amount_usd: charged.known_usd,
+ cost_source: charged.source,
+ },
+ },
+ crate::agent::tinyagents::host::SubagentUsageEntry {
+ // A second entry for the same task remains a distinct legacy
+ // contribution; this public ledger carries no run identity.
+ 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);
+ assert_eq!(usage.cost_usd, None, "unknown child cost stays unknown");
+ assert_eq!(
+ usage.cost_source,
+ tinyagents_harness::cost::CostSource::Unknown
+ );
+}
+
+#[tokio::test]
+async fn committed_goal_accounting_saturates_direct_plus_inclusive_child_tokens() {
+ let workspace = tempfile::tempdir().unwrap();
+ tinyagents_graph::goals::store::set(
+ &crate::storage::sessions::stores_or_ephemeral(workspace.path()).kv,
+ "saturated-goal",
+ "complete safely",
+ Some(u64::MAX),
+ )
+ .await
+ .unwrap();
+ let mut sidecar = crate::agent::tinyagents::host::run_context::SessionTurnSidecar {
+ input_tokens: u64::MAX - 1,
+ output_tokens: u64::MAX - 2,
+ ..Default::default()
+ };
+ sidecar
+ .subagents
+ .push(crate::agent::tinyagents::host::SubagentUsageEntry {
+ task_id: "large-child".into(),
+ agent_id: "researcher".into(),
+ usage: crate::agent::subagent_host::SubagentUsage {
+ input_tokens: 10,
+ output_tokens: 10,
+ ..Default::default()
+ },
+ });
+
+ account_committed_turn_against_goal(workspace.path(), Some("saturated-goal"), &sidecar).await;
+
+ let goal = tinyagents_graph::goals::store::get(
+ &crate::storage::sessions::stores_or_ephemeral(workspace.path()).kv,
+ "saturated-goal",
+ )
+ .await
+ .unwrap()
+ .unwrap();
+ assert_eq!(goal.tokens_used, u64::MAX);
+}
diff --git a/scripts/ci/check-openhuman-rust-layout.mjs b/scripts/ci/check-openhuman-rust-layout.mjs
index 5d3cf1bf3d..c692d300cd 100644
--- a/scripts/ci/check-openhuman-rust-layout.mjs
+++ b/scripts/ci/check-openhuman-rust-layout.mjs
@@ -27,12 +27,11 @@ const LEGACY_LIMIT_ENTRIES = [
// under the general 750 limit, so it needs no exception at all.
// The session-todo integration added transcript metadata construction to
// this already-exempt composition seam. Keep its allowance exact.
- ["crates/openhuman-core/src/agent/session_host/runtime_session.rs", 967],
// Session-host factory still assembles the product's deliberately coupled
// provider, security, memory, tool and prompt policy. Generic session
// state moved to tinyagents-runtime; this remaining composition is split in
// a follow-up without reintroducing an old harness/session exception.
- ["crates/openhuman-core/src/agent/session_host/builder/factory.rs", 964],
+ ["crates/openhuman-core/src/agent/session_host/builder/factory.rs", 925],
["crates/openhuman-core/src/agent/subagent_host/lifecycle.rs", 754],
["crates/openhuman-core/src/agent/subagent_host/ops/runner.rs", 925],
["crates/openhuman-core/src/web_chat/progress_bridge.rs", 1117],