Skip to content

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

refactor(agent): move subagent run ids out of the public usage entry

Steven Enamakeldc13efc73ae9
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 86a9a4ad92..abf24896a7 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
@@ -111,7 +111,6 @@ fn codec_attaches_only_this_agents_own_sidecar_usage_to_atomic_append() {
});
}
context.append_subagent_usage(crate::agent::tinyagents::host::SubagentUsageEntry {
- run_id: "run-child-usage".into(),
task_id: "child-usage".into(),
agent_id: "researcher".into(),
usage: crate::agent::subagent_host::SubagentUsage {
@@ -196,7 +195,6 @@ fn last_turn_usage_reports_the_same_holistic_totals_as_transcript_billing() {
sidecar
.subagents
.push(crate::agent::tinyagents::host::SubagentUsageEntry {
- run_id: "run-child-ui".into(),
task_id: "child-ui".into(),
agent_id: "researcher".into(),
usage: crate::agent::subagent_host::SubagentUsage {
@@ -227,7 +225,6 @@ fn child_usage_rollup_deduplicates_runs_without_merging_repeated_task_ids() {
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 {
@@ -252,7 +249,6 @@ fn child_usage_rollup_deduplicates_runs_without_merging_repeated_task_ids() {
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 {
@@ -357,7 +353,6 @@ async fn committed_goal_accounting_uses_direct_and_completed_child_usage() {
sidecar
.subagents
.push(crate::agent::tinyagents::host::SubagentUsageEntry {
- run_id: "run-child-goal".into(),
task_id: "child-goal".into(),
agent_id: "researcher".into(),
usage: crate::agent::subagent_host::SubagentUsage {
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
index c47d8c5502..b1a0ba56d3 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
@@ -358,7 +358,6 @@ pub(crate) async fn run_subagent_direct(
// offload. A cancellation while that filesystem work is pending must
// not erase direct model usage or descendants that already finished.
usage_finalizer.finish(crate::agent::tinyagents::host::SubagentUsageEntry {
- run_id: usage_finalizer.run_id.clone(),
task_id: task_id.clone(),
agent_id: definition.id.clone(),
usage: outcome.usage,
diff --git a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
index 8df54c8f90..d04d3c7251 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -76,15 +76,18 @@ pub(crate) fn direct_subagent_child(
/// usage breakdown.
#[derive(Debug, Clone, PartialEq)]
pub struct SubagentUsageEntry {
- /// Identity for this actual execution, shared across cloned/promoted
- /// completion records so usage rollup can ignore replayed entries without
- /// conflating separate runs of the same task.
- pub run_id: String,
pub task_id: String,
pub agent_id: String,
pub usage: SubagentUsage,
}
+/// Internal run identity paired with its host-facing usage projection.
+#[derive(Debug, Clone, PartialEq)]
+pub(crate) struct SubagentUsageRecord {
+ pub(crate) run_id: String,
+ pub(crate) entry: SubagentUsageEntry,
+}
+
/// Complete usage for a completed root turn, including synchronous children.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct LastTurnUsage {
@@ -337,11 +340,11 @@ pub struct OpenHumanRunContext {
/// Zero-based OpenHuman subagent depth (the root is zero).
pub spawn_depth: usize,
/// This run's subagent usage roll-up; intentionally isolated for children.
- pub subagent_usage: Arc<Mutex<Vec<SubagentUsageEntry>>>,
+ subagent_usage: Arc<Mutex<Vec<SubagentUsageRecord>>>,
/// The immediate parent's ledger. A child writes its own completed total to
/// this explicit handle, while nested children first collect in this run's
/// isolated ledger. It is never a task-local or a root-global collector.
- parent_subagent_usage: Option<Arc<Mutex<Vec<SubagentUsageEntry>>>>,
+ parent_subagent_usage: Option<Arc<Mutex<Vec<SubagentUsageRecord>>>>,
/// Provider/model/host-route observation for this run, written from the
/// canonical response metadata by typed model middleware. Intentionally
/// isolated for children.
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 42a69dee52..821af67226 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
@@ -163,7 +163,6 @@ fn child_ledgers_are_isolated_and_parent_keeps_completed_child_totals() {
let left = root.child();
let right = root.child();
left.append_subagent_usage(SubagentUsageEntry {
- run_id: "run-left".into(),
task_id: "left-task".into(),
agent_id: "researcher".into(),
usage: crate::agent::subagent_host::SubagentUsage {
@@ -177,7 +176,6 @@ fn child_ledgers_are_isolated_and_parent_keeps_completed_child_totals() {
assert!(right.subagent_usage_entries().is_empty());
left.record_completed_subagent_usage(SubagentUsageEntry {
- run_id: "run-completed".into(),
task_id: "completed-child".into(),
agent_id: "researcher".into(),
usage: crate::agent::subagent_host::SubagentUsage::default(),
@@ -191,7 +189,6 @@ fn failed_outer_run_promotes_completed_nested_usage_once() {
let root = OpenHumanRunContext::new();
let outer = root.child();
outer.append_subagent_usage(SubagentUsageEntry {
- run_id: "run-nested".into(),
task_id: "nested".into(),
agent_id: "researcher".into(),
usage: crate::agent::subagent_host::SubagentUsage {
@@ -206,7 +203,6 @@ 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]
@@ -223,7 +219,6 @@ fn detached_children_reset_turn_accounting_and_cancellation() {
root.cancellation.cancel();
assert!(!detached.cancellation.is_cancelled());
detached.record_completed_subagent_usage(SubagentUsageEntry {
- run_id: "run-background".into(),
task_id: "background".into(),
agent_id: "archivist".into(),
usage: Default::default(),