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): announce each turn again so clients see turns they did not send
Sanil2639e908523d
diff --git a/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs b/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rsindex b26d93f9c5..c67bb0fbf7 100644--- a/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs+++ b/crates/openhuman-core/src/agent/tinyagents/observability/event_bridge.rs@@ -62,6 +62,10 @@ pub(crate) struct OpenhumanEventBridge {/// run-local ordered event sink, so `ModelStarted` brackets the following/// `UsageRecorded` and terminal model event synchronously.pub(super) supplemental_call_active: AtomicBool,+ /// Set once the turn's start has been announced (`AgentProgress::TurnStarted`+ /// on the first top-level `RunStarted`), so a retried or nested run cannot+ /// announce the same turn twice.+ pub(super) turn_announced: AtomicBool,/// `None` for a parent turn; `Some` to emit child-scoped `Subagent*` events.pub(super) scope: Option<SubagentScope>,/// The agent definition the run acts as (its memory identity's agent),@@ -203,6 +207,7 @@ impl OpenhumanEventBridge {provider_id: provider_id.into(),max_iterations: max_iterations as u32,supplemental_call_active: AtomicBool::new(false),+ turn_announced: AtomicBool::new(false),scope,definition: std::sync::OnceLock::new(),cursor,diff --git a/crates/openhuman-core/src/agent/tinyagents/observability/event_projection.rs b/crates/openhuman-core/src/agent/tinyagents/observability/event_projection.rsindex 25c6d9be3e..71eda602ca 100644--- a/crates/openhuman-core/src/agent/tinyagents/observability/event_projection.rs+++ b/crates/openhuman-core/src/agent/tinyagents/observability/event_projection.rs@@ -2,6 +2,8 @@//! each `tinyagents` [`AgentEvent`] onto an [`AgentProgress`] update (or a//! grep-friendly trace lines for events with no UI surface.+use std::sync::atomic::Ordering;+use tinyagents_harness::cache::CacheLayoutEvent;use tinyagents_harness::events::{AgentEvent, EventListener, EventRecord};@@ -16,6 +18,16 @@ impl EventListener for OpenhumanEventBridge {return;}match &record.event {+ // The turn is live. The web channel turns this into `inference_start`+ // (and starts its liveness beats and the run-ledger entry), which is+ // how a client learns a turn began that it did not send itself — one+ // started right after a Stop, or from another window. Only the+ // top-level run of a parent bridge announces it, and only once.+ AgentEvent::RunStarted { .. } => {+ if self.scope.is_none() && !self.turn_announced.swap(true, Ordering::SeqCst) {+ self.send(AgentProgress::TurnStarted);+ }+ }AgentEvent::ModelStarted { .. } => {let iteration = tinyagents_harness::events::advance_iteration(&self.cursor);match &self.scope {diff --git a/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs b/crates/openhuman-core/src/agent/tinyagents/observability_tests.rsindex e57481696c..5998a425c2 100644--- a/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs@@ -106,6 +106,73 @@ async fn bridge_forwards_tool_and_cost_progress() {assert_eq!((input, output), (100, 40));}+fn run_started(id: &str) -> AgentEvent {+ AgentEvent::RunStarted {+ run_id: tinyagents_harness::ids::RunId::new(id),+ thread_id: None,+ }+}++/// A turn announces itself (`TurnStarted`, which the web channel turns into+/// `inference_start`) before anything else, exactly once. Without it a client+/// that did not send the turn — one started right after a Stop — never learns+/// a new turn is live and hides its stream until a reload.+#[tokio::test]+async fn the_top_level_run_announces_the_turn_once_and_first() {+ let (tx, mut rx) = tokio::sync::mpsc::channel(64);+ let bridge = OpenhumanEventBridge::new(Some(tx), "mock-model", 10);+ let sink = EventSink::new();+ sink.subscribe(bridge.clone());++ sink.emit(run_started("root"));+ sink.emit(AgentEvent::ModelStarted {+ call_id: "c1".into(),+ model: "mock-model".to_string(),+ });+ // A retried or nested run on the same bridge is not a new turn.+ sink.emit(run_started("again"));++ let mut kinds = Vec::new();+ while let Ok(p) = rx.try_recv() {+ kinds.push(match p {+ AgentProgress::TurnStarted => "turn",+ AgentProgress::IterationStarted { .. } => "iter",+ _ => "other",+ });+ }+ assert_eq!(kinds.first(), Some(&"turn"), "{kinds:?}");+ assert_eq!(kinds.iter().filter(|k| **k == "turn").count(), 1, "{kinds:?}");+}++#[tokio::test]+async fn a_subagent_run_does_not_announce_a_turn() {+ let (tx, mut rx) = tokio::sync::mpsc::channel(64);+ let bridge = OpenhumanEventBridge::with_scope(+ Some(tx),+ "mock-model",+ "custom",+ 10,+ Some(SubagentScope {+ agent_id: "researcher".into(),+ task_id: "t1".into(),+ extended_policy: false,+ }),+ Arc::default(),+ Arc::default(),+ Arc::default(),+ Arc::default(),+ Vec::new(),+ crate::core::runtime::DispatchCtx::unbound(),+ );+ let sink = EventSink::new();+ sink.subscribe(bridge.clone());++ sink.emit(run_started("child"));+ while let Ok(p) = rx.try_recv() {+ assert!(!matches!(p, AgentProgress::TurnStarted), "{p:?}");+ }+}+#[tokio::test]async fn host_supplemental_generation_is_journaled_without_loop_progress_or_billing() {let (tx, mut rx) = tokio::sync::mpsc::channel(16);diff --git a/crates/openhuman-core/src/agent/tinyagents/turn_exec_tests.rs b/crates/openhuman-core/src/agent/tinyagents/turn_exec_tests.rsindex fe669c76fa..1b44141e27 100644--- a/crates/openhuman-core/src/agent/tinyagents/turn_exec_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/turn_exec_tests.rs@@ -410,7 +410,7 @@ async fn a_streamed_delta_reaches_the_progress_channel_exactly_once() {vec!["one delta".to_string()],"every model delta is forwarded once, by one producer");- // The two counters have OPPOSITE contracts. Read them separately.+ // Both counters are exact, for different reasons.//// `completed` is asserted by equality at 0, and that is a documented// design: `run_root` passes `defer_turn_completed_to_caller = true`, so@@ -421,19 +421,9 @@ async fn a_streamed_delta_reaches_the_progress_channel_exactly_once() {// this test exists to prevent. So the ceiling could not fail in the// direction the test was written for. Do not loosen this one back.//- // `started` deliberately stays a ceiling. The deferral flag governs- // `TurnCompleted` only; it does not suppress the root's `Started` event.- // `host/progress_sink.rs:400` forwards `TurnStarted` for the root run, and- // the module docs at `:59` and `:185` say only the root projects a- // top-level one — and this path IS the root, so exactly one is what the- // contract calls for.- //- // It is nevertheless absent: instrumenting this test measured- // `started = 0`. `assert_eq!(started, 1)` is therefore the RIGHT eventual- // assertion and would fail today, so it is not made here — a PR tightening- // a test should not land a knowingly-red one. Tracked as #6576; tighten- // this to `== 1` as part of fixing that, not before.- assert!(started <= 1, "TurnStarted was emitted {started} times");+ // `started` is exact too: the deferral flag governs `TurnCompleted` only,+ // and this path IS the root, which announces its turn once (#6576).+ assert_eq!(started, 1, "TurnStarted was emitted {started} times");assert_eq!(completed, 0,"the deferring seam must emit no TurnCompleted — the caller owns it"