Skip to content

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

fix(subagent_host): preserve sub-second elapsed time across lifecycle round-trips

Steven Enamakel6db05938481b
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs
index fff797e867..234056bafa 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle/driver_adapter.rs
@@ -335,6 +335,11 @@ pub(in crate::agent::subagent_host) fn outcome_to_host(
) -> SubagentRunOutcome {
let persistence_disposition = result.disposition;
let outcome = result.outcome;
+ let elapsed_from_neutral = outcome
+ .extensions
+ .get("elapsed_ns")
+ .and_then(serde_json::Value::as_u64)
+ .map(std::time::Duration::from_nanos);
// A driver that lost a pause/terminal CAS may have a perfectly valid local
// execution result, but it is not the authoritative lifecycle outcome.
// Reconstruct the durable winner instead of leaking the loser’s output,
@@ -407,6 +412,9 @@ pub(in crate::agent::subagent_host) fn outcome_to_host(
.collect(),
persistence_disposition,
});
+ if let Some(elapsed) = elapsed_from_neutral {
+ host.elapsed = elapsed;
+ }
let is_awaiting_input = matches!(outcome.status, SubagentOutcomeKind::AwaitingInput(_));
let status = match outcome.status {
SubagentOutcomeKind::Completed => SubagentRunStatus::Completed,
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs
index 64ba1cb44a..72c6bfd252 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle/persistence.rs
@@ -362,6 +362,7 @@ impl OpenHumanPersistence {
"skill_filter_override": checkpoint.skill_filter_override.clone(),
"model_override": checkpoint.model_override.clone(),
"elapsed_ms": checkpoint.elapsed_ms,
+ "elapsed_ns": checkpoint.elapsed_ms.saturating_mul(1_000_000),
"cost_source": checkpoint.usage.cost_source,
});
let mut outcome =
@@ -578,6 +579,7 @@ impl tinyagents_orchestration::subagent::SubagentPersistence for OpenHumanPersis
"created_at": chrono::Utc::now().to_rfc3339(),
"options": pause.outcome.extensions.get("options"),
"elapsed_ms": elapsed_ms,
+ "elapsed_ns": outcome.elapsed.as_nanos().min(u64::MAX as u128) as u64,
});
pause
.outcome
diff --git a/crates/openhuman-core/src/agent/subagent_host/lifecycle_outcome.rs b/crates/openhuman-core/src/agent/subagent_host/lifecycle_outcome.rs
index 54cf9aeda4..f3ff8b8ccf 100644
--- a/crates/openhuman-core/src/agent/subagent_host/lifecycle_outcome.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/lifecycle_outcome.rs
@@ -19,6 +19,10 @@ pub(super) fn host_outcome_to_neutral(
"elapsed_ms".into(),
serde_json::json!(outcome.elapsed.as_millis() as u64),
),
+ (
+ "elapsed_ns".into(),
+ serde_json::json!(outcome.elapsed.as_nanos().min(u64::MAX as u128) as u64),
+ ),
(
"artifact_paths".into(),
serde_json::json!(outcome.artifact_paths),