The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(progress_tracing): track model call progress in collector
Steven Enamakel3af89fd01c9d
diff --git a/crates/openhuman-core/src/agent/progress_tracing/collector/model_call.rs b/crates/openhuman-core/src/agent/progress_tracing/collector/model_call.rsindex 3be8d13637..194cb52a0f 100644--- a/crates/openhuman-core/src/agent/progress_tracing/collector/model_call.rs+++ b/crates/openhuman-core/src/agent/progress_tracing/collector/model_call.rs@@ -68,7 +68,7 @@ impl SpanCollector {.clone().or_else(|| state.last_iteration_span_id.clone());let clock = state.call_clock;- let fallback = state.last_model.clone();+ let fallback = state.last_raw_model.clone();match iteration_id {Some(id) => {let idx = self.span_index_by_id(&id);@@ -94,7 +94,7 @@ impl SpanCollector {parent,self.current_iteration_index,self.call_clock,- self.last_model.clone(),+ self.last_raw_model.clone(),)}};@@ -118,19 +118,30 @@ impl SpanCollector {Some(id) => match self.subagent_state_mut(id) {Some(state) => {state.call_clock = next_clock;- state.last_model = Some(model.clone());+ state.last_raw_model = Some(model.clone());std::mem::take(&mut state.first_deltas)}None => Default::default(),},None => {self.call_clock = next_clock;- self.last_model = Some(model.clone());+ self.last_raw_model = Some(model.clone());std::mem::take(&mut self.first_deltas)}};let labeled_model = generation::model_label(provider_id, &model);+ // Remember which model this scope is on so the tool spans it requests+ // name it (correlating tool errors to models without a join). The+ // label already drops an empty provider (the journal replay has none).+ match subagent_task_id {+ Some(id) => {+ if let Some(state) = self.subagent_state_mut(id) {+ state.last_model = Some(labeled_model.clone());+ }+ }+ None => self.last_model = Some(labeled_model.clone()),+ }let pricing = crate::agent::cost::lookup_known_pricing(&model);let usage = generation::normalize_usage(input_tokens,diff --git a/crates/openhuman-core/src/agent/progress_tracing/collector/state.rs b/crates/openhuman-core/src/agent/progress_tracing/collector/state.rsindex 844a184591..ca1225c274 100644--- a/crates/openhuman-core/src/agent/progress_tracing/collector/state.rs+++ b/crates/openhuman-core/src/agent/progress_tracing/collector/state.rs@@ -45,6 +45,67 @@ pub(super) struct SubagentState {/// Langfuse-facing label (`{provider}.{model}`) of the child's latest/// model call, stamped on the child tool spans it requests.pub(super) last_model: Option<String>,+ /// Raw model of the child's most recent call, the fallback name for a call+ /// that arrives without one.+ pub(super) last_raw_model: Option<String>,+ /// Last child iteration span opened, kept after it closes so a model call+ /// or tool event reported after the subagent finished still nests under it.+ pub(super) last_iteration_span_id: Option<String>,+ /// Start-time bookkeeping for the child's model calls (see [`CallClock`]).+ pub(super) call_clock: CallClock,+}++impl SubagentState {+ pub(super) fn new(span_index: usize) -> Self {+ Self {+ span_index,+ current_iteration_span_id: None,+ open_tools: BTreeMap::new(),+ first_deltas: FirstDeltas::default(),+ last_model: None,+ last_raw_model: None,+ last_iteration_span_id: None,+ call_clock: CallClock::default(),+ }+ }+}++/// Per-scope bookkeeping for a model call's start time.+///+/// The progress stream carries no per-call request start: a generation used+/// to start at its enclosing iteration's start, so several calls folded into+/// one iteration (retries, or a child's calls whose iteration events were+/// lost) all shared that instant and each one's latency covered every call+/// before it. A call cannot have started before the previous call in the same+/// iteration ended, so that end is the tighter bound; an explicit start+/// (the journal's `ModelCompleted.started_at_ms`) beats both.+#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]+pub(super) struct CallClock {+ /// End of the previous generation in the current iteration.+ pub(super) last_call_end_unix_ms: Option<u64>,+ /// Explicit request start for the next call, set by a source that knows+ /// it ([`SpanCollector::set_next_call_start`]).+ pub(super) explicit_start_unix_ms: Option<u64>,+}++/// How a turn ended, for the root span's status.+///+/// `AgentProgress` has no aborted/failed turn variant, so a host that knows+/// the outcome passes it to [`SpanCollector::finish_with_outcome`]; a turn+/// span still open at [`SpanCollector::finish`] (no `TurnCompleted` arrived)+/// is sealed as [`TurnOutcome::Incomplete`].+#[derive(Debug, Clone, PartialEq, Eq)]+pub enum TurnOutcome {+ /// The turn produced its reply.+ Completed,+ /// The turn failed with an error.+ Failed { message: String },+ /// A deadline or per-call timeout ended the turn.+ TimedOut { message: String },+ /// The user (or the host) cancelled the turn.+ Cancelled { reason: Option<String> },+ /// The stream closed before the turn reported an outcome.+ Incomplete,}/// Pure state machine that folds an [`crate::agent::progress::AgentProgress`]@@ -80,6 +141,23 @@ pub struct SpanCollector {/// model call. Tool calls run after the model call that requested them/// completes, so this names the model behind every tool span opened next.pub(super) last_model: Option<String>,+ /// Raw model of the parent turn's most recent call, the fallback name for+ /// a call that arrives without one.+ pub(super) last_raw_model: Option<String>,+ /// Start-time bookkeeping for the parent turn's model calls.+ pub(super) call_clock: CallClock,+ /// Subagents that already reported completion/failure, kept so their late+ /// events (tool completions, model calls) still resolve to their spans+ /// instead of being dropped or misparented under the parent iteration.+ pub(super) finished_subagents: BTreeMap<String, SubagentState>,+ /// Latest event timestamp seen; the end of a span force-closed at+ /// [`SpanCollector::finish`] when nothing tighter is known.+ pub(super) last_activity_unix_ms: u64,+ /// Whether the turn span's input is already set. The first `TurnContent`+ /// input is the originating user message; later ones (the commit path's+ /// last user-role message can be tool results or a harness nudge) must+ /// not overwrite it.+ pub(super) turn_input_recorded: bool,}impl SpanCollector {@@ -97,6 +175,11 @@ impl SpanCollector {subagents: BTreeMap::new(),first_deltas: FirstDeltas::default(),last_model: None,+ last_raw_model: None,+ call_clock: CallClock::default(),+ finished_subagents: BTreeMap::new(),+ last_activity_unix_ms: 0,+ turn_input_recorded: false,}}