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
fix(agent-tracing): say what the journal-shadow parity check found, and stop the comment lying about it
M3gA-Mind91df34355861
diff --git a/crates/openhuman-core/src/agent/progress_tracing/journal_projection.rs b/crates/openhuman-core/src/agent/progress_tracing/journal_projection.rsindex 4bb187631e..8f45700b8f 100644--- a/crates/openhuman-core/src/agent/progress_tracing/journal_projection.rs+++ b/crates/openhuman-core/src/agent/progress_tracing/journal_projection.rs@@ -24,14 +24,32 @@//! counts are exact; treat a projected `gen_ai.usage.cost_usd` as an//! estimate. `AgentEvent::CostRecorded` would close this if the crate ever//! emits it.-//! - Sub-agent prompt/output content is not on the crate lifecycle events, so-//! subagent spans carry lifecycle/timing and child tool/model structure but-//! empty delegated prompt/final output until a richer journal event exists.-//! - `AgentProgress::SubagentAwaitingUser` has no journal source at all (the-//! crate emits no matching lifecycle event), so a subagent span parked on a-//! user prompt loses that attribute on replay.+//! - **No sub-agent spans are projected at all** (openhuman#6419). The four+//! `AgentEvent::SubAgent*` arms below are dead in production: a survey of 900+//! real run journals found **zero** sub-agent events of any kind, and every+//! journalled run is its own root (`root_run_id == run_id` in all 588+//! `run_started` records sampled, and no `root_run_id` spans more than one+//! run file), so a child run is neither recorded in its parent's journal nor+//! reachable from it. A replayed delegating turn therefore loses the whole+//! sub-agent subtree — the delegate's turn span, its iterations, and its tool+//! and model spans — which is the bulk of the span-count divergence the+//! `[agent-tracing][journal-shadow]` parity check reports. This is a gap in+//! what the crate journals, not in the projection: the arms are kept so the+//! projection is correct the moment the events exist.//!-//! Everything else is projected. In particular the match in+//! An earlier revision of this list said sub-agent spans "carry+//! lifecycle/timing and child tool/model structure but empty delegated+//! prompt/final output", i.e. that only their *content* was thin. That was+//! wrong in kind and stopped readers looking: there are no such spans to+//! carry anything.+//! - `AgentProgress::SubagentAwaitingUser` has no journal source either (the+//! crate emits no matching lifecycle event). Moot while the gap above stands,+//! and listed separately because it survives it: even once sub-agent+//! lifecycle events are journalled, a span parked on a user prompt would lose+//! that attribute on replay.+//!+//! Everything else **that the crate journals** is projected. In particular the+//! match in//! [`observation_to_progress`] is **exhaustive over `AgentEvent`** — a crate//! that adds a span-bearing event breaks the build here rather than silently//! diverging, which is exactly how the missing `UsageRecorded` roll-up wentdiff --git a/crates/openhuman-core/src/web_chat/journal_shadow.rs b/crates/openhuman-core/src/web_chat/journal_shadow.rsnew file mode 100644index 0000000000..ea8341cac1--- /dev/null+++ b/crates/openhuman-core/src/web_chat/journal_shadow.rs@@ -0,0 +1,169 @@+//! Journal-shadow parity: compare the live trace spans for a turn against the+//! spans reprojected from the durable journal, and say what differs.+//!+//! Extracted from `progress_bridge` (openhuman#6419) — that file sits on a+//! grandfathered line-limit ratchet in `scripts/ci/check-openhuman-rust-layout.mjs`,+//! so this grew out of it rather than being trimmed to fit. The three functions+//! here are one unit: build a comparable signature per span, diff two signature+//! lists, and drive the comparison for one request.+//!+//! What the comparison means is documented on+//! [`journal_projection`](crate::agent::progress_tracing::journal_projection):+//! both sides fold through the same `SpanCollector`, so span-shape parity holds+//! by construction and a divergence is a real gap rather than an artefact of+//! comparing two different abstractions. The largest such gap today is that the+//! crate journals no sub-agent events at all, so every delegating turn loses+//! that subtree on replay.++fn span_projection_signature(spans: &[crate::agent::progress_tracing::TraceSpan]) -> Vec<String> {+ spans+ .iter()+ .map(|span| {+ let attr_keys = span+ .attributes+ .keys()+ .map(String::as_str)+ .collect::<Vec<_>>()+ .join(",");+ format!(+ "{:?}|{}|{:?}|attrs:[{}]",+ span.kind, span.name, span.status, attr_keys+ )+ })+ .collect()+}++/// Summarise a signature mismatch as *what* differs, not how many.+///+/// The parity warning used to print two counts and two full signature vectors,+/// which for a delegating turn meant ~64 and ~21 entries of `kind|name|status`+/// on one line. That is a diff the reader has to do by eye, every turn, so the+/// warning went unactioned for long enough to be filed as noise (#6419) when the+/// signal was real: the journal carries no sub-agent events at all, so every+/// delegating turn loses that whole subtree.+///+/// Spans are matched as a multiset by signature, so a span present twice live+/// and once in the projection is reported as one missing occurrence rather than+/// as identical. Names are truncated and the list is capped — this is a log+/// line, and the point is to name the shape of the gap, not to reproduce it.+fn describe_signature_divergence(live: &[String], projected: &[String]) -> String {+ fn counts(sigs: &[String]) -> std::collections::BTreeMap<&str, i64> {+ let mut out = std::collections::BTreeMap::new();+ for sig in sigs {+ *out.entry(sig.as_str()).or_insert(0) += 1;+ }+ out+ }+ let (live_counts, projected_counts) = (counts(live), counts(projected));+ let mut missing: Vec<String> = Vec::new();+ let mut extra: Vec<String> = Vec::new();+ for (sig, live_n) in &live_counts {+ let delta = live_n - projected_counts.get(sig).copied().unwrap_or(0);+ if delta > 0 {+ missing.push(format!(+ "{delta}x {}",+ sig.chars().take(70).collect::<String>()+ ));+ }+ }+ for (sig, projected_n) in &projected_counts {+ let delta = projected_n - live_counts.get(sig).copied().unwrap_or(0);+ if delta > 0 {+ extra.push(format!(+ "{delta}x {}",+ sig.chars().take(70).collect::<String>()+ ));+ }+ }+ const MAX: usize = 6;+ let render = |label: &str, mut items: Vec<String>| -> String {+ if items.is_empty() {+ return String::new();+ }+ let total = items.len();+ items.truncate(MAX);+ let more = total.saturating_sub(MAX);+ let suffix = if more > 0 {+ format!(" (+{more} more)")+ } else {+ String::new()+ };+ format!(" {label}=[{}]{suffix}", items.join("; "))+ };+ format!(+ "{}{}",+ render("live_only", missing),+ render("journal_only", extra)+ )+}++pub(super) async fn shadow_compare_journal_projection(+ request_id: &str,+ trace_ctx: crate::agent::progress_tracing::TraceContext,+ max_iterations: u32,+ live_spans: &[crate::agent::progress_tracing::TraceSpan],+) -> Option<Vec<tinyagents_harness::observability::AgentObservation>> {+ let Some(journal_run_id) =+ crate::agent::tinyagents::journal::take_request_journal_run(request_id)+ else {+ log::debug!(+ "[agent-tracing][journal-shadow] no journal run registered request_id={}",+ request_id+ );+ return None;+ };++ let observations = match crate::agent::tinyagents::journal::read_run_events(&journal_run_id, 0)+ .await+ {+ Ok(observations) => observations,+ Err(err) => {+ log::warn!(+ "[agent-tracing][journal-shadow] read failed request_id={} journal_run_id={} err={err}",+ request_id,+ journal_run_id+ );+ return None;+ }+ };+ if observations.is_empty() {+ log::warn!(+ "[agent-tracing][journal-shadow] journal empty request_id={} journal_run_id={}",+ request_id,+ journal_run_id+ );+ return None;+ }++ let projected = crate::agent::progress_tracing::journal_projection::spans_from_observations(+ trace_ctx,+ max_iterations,+ &observations,+ );+ let live_sig = span_projection_signature(live_spans);+ let projected_sig = span_projection_signature(&projected);+ if live_sig == projected_sig {+ log::debug!(+ "[agent-tracing][journal-shadow] parity ok request_id={} journal_run_id={} spans={} observations={}",+ request_id,+ journal_run_id,+ live_spans.len(),+ observations.len()+ );+ } else {+ log::warn!(+ "[agent-tracing][journal-shadow] parity divergence request_id={} journal_run_id={} live_spans={} journal_spans={} observations={}{}",+ request_id,+ journal_run_id,+ live_spans.len(),+ projected.len(),+ observations.len(),+ describe_signature_divergence(&live_sig, &projected_sig)+ );+ }+ Some(observations)+}++#[cfg(test)]+#[path = "journal_shadow_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/web_chat/journal_shadow_tests.rs b/crates/openhuman-core/src/web_chat/journal_shadow_tests.rsnew file mode 100644index 0000000000..4dc377fe70--- /dev/null+++ b/crates/openhuman-core/src/web_chat/journal_shadow_tests.rs@@ -0,0 +1,73 @@+use super::describe_signature_divergence;++/// #6419: the parity warning has to name *what* diverged.+///+/// These assert the rendered description, not that the two vectors differ —+/// "they differ" is what the old warning already told us, every turn, for long+/// enough that a true signal got filed as noise.+#[test]+fn divergence_description_names_the_spans_present_live_and_absent_in_the_journal() {+ let live = vec![+ "Turn|agent.turn:orchestrator|Ok|attrs:[a]".to_string(),+ "SubAgent|subagent:researcher|Ok|attrs:[b]".to_string(),+ "Tool|tool:file_read|Ok|attrs:[c]".to_string(),+ ];+ let projected = vec![+ "Turn|agent.turn:orchestrator|Ok|attrs:[a]".to_string(),+ "Tool|tool:file_read|Ok|attrs:[c]".to_string(),+ ];++ let described = describe_signature_divergence(&live, &projected);+ assert!(+ described.contains("live_only"),+ "a span present live and absent in the journal must be named: {described}"+ );+ assert!(+ described.contains("subagent:researcher"),+ "the missing span's identity is the whole point: {described}"+ );+ // The spans both sides agree on must NOT be listed — a description that+ // repeats the whole signature set is the blob this replaces.+ assert!(+ !described.contains("file_read"),+ "agreed spans must not be reported as divergent: {described}"+ );+ assert!(+ !described.contains("journal_only"),+ "nothing was projected that the live path lacked: {described}"+ );+}++#[test]+fn divergence_description_counts_repeats_as_a_multiset() {+ // Three iterations live, one projected. Matching as sets would call these+ // "identical" and report nothing; the gap is two occurrences.+ let sig = "Iteration|agent.iteration|Ok|attrs:[i]".to_string();+ let live = vec![sig.clone(), sig.clone(), sig.clone()];+ let projected = vec![sig.clone()];++ let described = describe_signature_divergence(&live, &projected);+ assert!(+ described.contains("2x"),+ "two missing occurrences, not a set difference of zero: {described}"+ );+}++#[test]+fn divergence_description_reports_journal_only_spans_too() {+ // The projection producing something the live path did not is a different+ // bug from the projection missing something, and must read differently.+ let live: Vec<String> = Vec::new();+ let projected = vec!["Tool|tool:ghost|Ok|attrs:[]".to_string()];++ let described = describe_signature_divergence(&live, &projected);+ assert!(described.contains("journal_only"), "{described}");+ assert!(!described.contains("live_only"), "{described}");+}++#[test]+fn divergence_description_is_empty_when_the_two_agree() {+ let sig = vec!["Turn|agent.turn:orchestrator|Ok|attrs:[a]".to_string()];+ assert_eq!(describe_signature_divergence(&sig, &sig), "");+ assert_eq!(describe_signature_divergence(&[], &[]), "");+}diff --git a/crates/openhuman-core/src/web_chat/mod.rs b/crates/openhuman-core/src/web_chat/mod.rsindex 51e73b599c..f0cefb0f15 100644--- a/crates/openhuman-core/src/web_chat/mod.rs+++ b/crates/openhuman-core/src/web_chat/mod.rs@@ -26,6 +26,7 @@//! contract), `types.rs` (shared param/state types).mod event_bus;+mod journal_shadow;mod ops;// Response delivery/segmentation for the web surface (folded in from the former// standalone `presentation` provider — it is the web channel's delivery formatter).diff --git a/crates/openhuman-core/src/web_chat/progress_bridge.rs b/crates/openhuman-core/src/web_chat/progress_bridge.rsindex d7fdfb5903..37c40b56b0 100644--- a/crates/openhuman-core/src/web_chat/progress_bridge.rs+++ b/crates/openhuman-core/src/web_chat/progress_bridge.rs@@ -234,92 +234,6 @@ fn session_profile_user_attribution(config: &crate::config::Config) -> Option<St.or(state.user_id)}-fn span_projection_signature(spans: &[crate::agent::progress_tracing::TraceSpan]) -> Vec<String> {- spans- .iter()- .map(|span| {- let attr_keys = span- .attributes- .keys()- .map(String::as_str)- .collect::<Vec<_>>()- .join(",");- format!(- "{:?}|{}|{:?}|attrs:[{}]",- span.kind, span.name, span.status, attr_keys- )- })- .collect()-}--async fn shadow_compare_journal_projection(- request_id: &str,- trace_ctx: crate::agent::progress_tracing::TraceContext,- max_iterations: u32,- live_spans: &[crate::agent::progress_tracing::TraceSpan],-) -> Option<Vec<tinyagents_harness::observability::AgentObservation>> {- let Some(journal_run_id) =- crate::agent::tinyagents::journal::take_request_journal_run(request_id)- else {- log::debug!(- "[agent-tracing][journal-shadow] no journal run registered request_id={}",- request_id- );- return None;- };-- let observations = match crate::agent::tinyagents::journal::read_run_events(&journal_run_id, 0)- .await- {- Ok(observations) => observations,- Err(err) => {- log::warn!(- "[agent-tracing][journal-shadow] read failed request_id={} journal_run_id={} err={err}",- request_id,- journal_run_id- );- return None;- }- };- if observations.is_empty() {- log::warn!(- "[agent-tracing][journal-shadow] journal empty request_id={} journal_run_id={}",- request_id,- journal_run_id- );- return None;- }-- let projected = crate::agent::progress_tracing::journal_projection::spans_from_observations(- trace_ctx,- max_iterations,- &observations,- );- let live_sig = span_projection_signature(live_spans);- let projected_sig = span_projection_signature(&projected);- if live_sig == projected_sig {- log::debug!(- "[agent-tracing][journal-shadow] parity ok request_id={} journal_run_id={} spans={} observations={}",- request_id,- journal_run_id,- live_spans.len(),- observations.len()- );- } else {- log::warn!(- "[agent-tracing][journal-shadow] parity divergence request_id={} journal_run_id={} live_spans={} journal_spans={} observations={} live_sig={:?} journal_sig={:?}",- request_id,- journal_run_id,- live_spans.len(),- projected.len(),- observations.len(),- live_sig,- projected_sig- );- }- Some(observations)-}-/// Spawn a background task that reads [`AgentProgress`] events from the/// agent turn loop and translates them into [`WebChannelEvent`]s tagged/// with the correct client/thread/request IDs. The task runs until the@@ -1468,7 +1382,7 @@ pub(crate) fn spawn_progress_bridge(collector.finish(unix_epoch_ms());let live_spans = collector.spans().to_vec();let journal_export = if let Some(trace_ctx) = journal_trace_ctx.take() {- shadow_compare_journal_projection(+ super::journal_shadow::shadow_compare_journal_projection(&request_id,trace_ctx.clone(),parent_max_iterations,