Skip to content

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

refactor(subagent): drop per-run usage record ids

Steven Enamakelf3bd66d39b55
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 e43d27c562..f17dda865d 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
@@ -128,13 +128,11 @@ pub(crate) async fn run_subagent_direct(
// same entries into this run's single terminal total.
struct UsageFinalizer {
context: crate::agent::tinyagents::host::OpenHumanRunContext,
- run_id: String,
complete: bool,
}
impl UsageFinalizer {
fn finish(&mut self, entry: crate::agent::tinyagents::host::SubagentUsageEntry) {
- self.context
- .record_completed_subagent_usage_with_run_id(self.run_id.clone(), entry);
+ self.context.record_completed_subagent_usage(entry);
self.complete = true;
}
}
@@ -149,12 +147,8 @@ pub(crate) async fn run_subagent_direct(
.task_id
.clone()
.unwrap_or_else(|| format!("sub-{}", uuid::Uuid::new_v4()));
- // This point is inside the actual executor, after shared-flight
- // coalescing has selected the run owner. Carry the same id through
- // every completion record cloned or promoted by this run.
let mut usage_finalizer = UsageFinalizer {
context: options.run_context.clone(),
- run_id: uuid::Uuid::new_v4().to_string(),
complete: false,
};
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 8fff26c43d..cd1658a430 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -81,13 +81,6 @@ pub struct SubagentUsageEntry {
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 {
@@ -340,11 +333,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.
- subagent_usage: Arc<Mutex<Vec<SubagentUsageRecord>>>,
+ pub subagent_usage: Arc<Mutex<Vec<SubagentUsageEntry>>>,
/// 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<SubagentUsageRecord>>>>,
+ parent_subagent_usage: Option<Arc<Mutex<Vec<SubagentUsageEntry>>>>,
/// Provider/model/host-route observation for this run, written from the
/// canonical response metadata by typed model middleware. Intentionally
/// isolated for children.
@@ -707,27 +700,13 @@ impl OpenHumanRunContext {
self.subagent_usage
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner())
- .push(SubagentUsageRecord {
- run_id: uuid::Uuid::new_v4().to_string(),
- entry,
- });
+ .push(entry);
}
/// Record a completed child on the immediate parent's ledger. This makes
/// completed children visible at the root without leaking siblings into one
/// another's in-flight ledger. Direct/root callers retain their own entry.
pub fn record_completed_subagent_usage(&self, entry: SubagentUsageEntry) {
- self.record_completed_subagent_usage_with_run_id(uuid::Uuid::new_v4().to_string(), entry);
- }
-
- /// Records one actual child execution with its stable identity. The runner
- /// mints this once inside the executor, so clones and failure promotion
- /// deduplicate the same run while repeated task IDs remain distinct.
- pub(crate) fn record_completed_subagent_usage_with_run_id(
- &self,
- run_id: String,
- entry: SubagentUsageEntry,
- ) {
let ledger = self
.parent_subagent_usage
.as_ref()
@@ -735,23 +714,13 @@ impl OpenHumanRunContext {
ledger
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner())
- .push(SubagentUsageRecord { run_id, entry });
+ .push(entry);
}
/// Snapshot child totals after the child has returned. A snapshot, rather
/// than a task-local drain, preserves totals even when sibling futures are
/// cancelled or one child fails after another has completed.
pub fn subagent_usage_entries(&self) -> Vec<SubagentUsageEntry> {
- self.subagent_usage
- .lock()
- .unwrap_or_else(|poisoned| poisoned.into_inner())
- .iter()
- .map(|record| record.entry.clone())
- .collect()
- }
-
- /// Internal snapshot retaining actual execution IDs for cost rollup.
- pub(crate) fn subagent_usage_records(&self) -> Vec<SubagentUsageRecord> {
self.subagent_usage
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner())
@@ -763,8 +732,8 @@ impl OpenHumanRunContext {
/// it only from one terminal finalizer, so every completed descendant is
/// promoted once without exposing a shared, in-flight sibling ledger.
pub fn promote_completed_descendant_usage(&self) {
- for record in self.subagent_usage_records() {
- self.record_completed_subagent_usage_with_run_id(record.run_id, record.entry);
+ for entry in self.subagent_usage_entries() {
+ self.record_completed_subagent_usage(entry);
}
}
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 b3f13299c2..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
@@ -196,7 +196,6 @@ fn failed_outer_run_promotes_completed_nested_usage_once() {
..Default::default()
},
});
- let nested_run_id = outer.subagent_usage_records()[0].run_id.clone();
// This is the failure/cancellation finalizer path. Calling it once leaves
// the root with the completed nested work even though the outer run has no
@@ -204,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_records()[0].run_id, nested_run_id);
}
#[test]