Skip to content

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

fix(subagent_host): tag usage entries with a per-run id

Steven Enamakelbf7d9647780a
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 ba49cd4c1e..c47d8c5502 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/runner.rs
@@ -128,6 +128,7 @@ 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 {
@@ -143,14 +144,18 @@ pub(crate) async fn run_subagent_direct(
}
}
}
- let mut usage_finalizer = UsageFinalizer {
- context: options.run_context.clone(),
- complete: false,
- };
let task_id = options
.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,
+ };
// Turn-scoped dispatch gate (#5804) — deliberately the FIRST gate, for
// the same reason the depth gate is synchronous and pre-dispatch: a
@@ -353,6 +358,7 @@ 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 cd1658a430..8df54c8f90 100644
--- a/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/host/run_context.rs
@@ -76,6 +76,10 @@ 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,