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
refactor(web_chat): extract heartbeat interval as a parameter
Steven Enamakel5b1d0ad132e4
diff --git a/crates/openhuman-core/src/web_chat/turn_host.rs b/crates/openhuman-core/src/web_chat/turn_host.rsindex c65de23d12..3c4e846db3 100644--- a/crates/openhuman-core/src/web_chat/turn_host.rs+++ b/crates/openhuman-core/src/web_chat/turn_host.rs@@ -16,19 +16,19 @@ use std::sync::Arc;use std::time::Duration;use async_trait::async_trait;-use tinyagents_harness::CancellationToken;use tinyagents_harness::run_queue::RunQueue;use tinyagents_harness::turn_runner::{QueueDisposition, TurnHost, TurnRequest, TurnResult, TurnSession, TurnSignal,};+use tinyagents_harness::CancellationToken;use tinyinference_llm::failure::is_empty_provider_response_text;-use tokio::sync::{Mutex as AsyncMutex, mpsc, watch};+use tokio::sync::{mpsc, watch, Mutex as AsyncMutex};use super::ops::{self, BudgetCorrelation};-use super::progress::{INFERENCE_HEARTBEAT_SECS, ProgressProjection};+use super::progress::{ProgressProjection, INFERENCE_HEARTBEAT_SECS};use super::runner::{Admission, Shared};use super::session::{- CheckoutPolicy, checkin_session_agent, checkout_session_agent, normalize_model_override,+ checkin_session_agent, checkout_session_agent, normalize_model_override, CheckoutPolicy,};use super::surface::TurnIds;use super::turn_activity::{TurnActivity, WorkTracker};@@ -37,7 +37,7 @@ use super::web_errors::{inference_budget_exceeded_user_message, is_inference_budget_exceeded_error,};use crate::agent::queued_turn::QueuedPayload;-use crate::agent::turn_origin::{AgentTurnOrigin, with_origin};+use crate::agent::turn_origin::{with_origin, AgentTurnOrigin};use crate::core::events::DomainEvent;use crate::core::runtime::DispatchCtx;use tinyagents_harness::progress::AgentProgress;@@ -565,9 +565,21 @@ fn tap_progress(fn spawn_heartbeat(ctx: &DispatchCtx,projection: Arc<AsyncMutex<ProgressProjection>>,+) -> tokio::task::JoinHandle<()> {+ spawn_heartbeat_with_interval(+ ctx,+ projection,+ Duration::from_secs(INFERENCE_HEARTBEAT_SECS),+ )+}++fn spawn_heartbeat_with_interval(+ ctx: &DispatchCtx,+ projection: Arc<AsyncMutex<ProgressProjection>>,+ interval: Duration,) -> tokio::task::JoinHandle<()> {ctx.spawn(async move {- let mut beat = tokio::time::interval(Duration::from_secs(INFERENCE_HEARTBEAT_SECS));+ let mut beat = tokio::time::interval(interval);// Wall-clock cadence: a slow turn must not produce a burst of catch-up// beats once it finally yields control.beat.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);diff --git a/crates/openhuman-core/src/web_chat/turn_host_tests.rs b/crates/openhuman-core/src/web_chat/turn_host_tests.rsindex b8e379124a..0edd6903cf 100644--- a/crates/openhuman-core/src/web_chat/turn_host_tests.rs+++ b/crates/openhuman-core/src/web_chat/turn_host_tests.rs@@ -126,9 +126,10 @@ async fn a_dropped_runner_stops_the_tap() {assert!(*drained_rx.borrow());}-#[tokio::test(start_paused = true)]+#[tokio::test]async fn the_heartbeat_beats_only_for_a_live_turn() {use super::super::surface::TurnIds;+ let _module = crate::channels::module_fixture::client().await;let mut bus = crate::web_chat::subscribe_web_channel_events();let ids = TurnIds {client_id: "hb-client".into(),@@ -145,10 +146,14 @@ async fn the_heartbeat_beats_only_for_a_live_turn() {).await,));- let beat = AbortOnDrop(spawn_heartbeat(&DispatchCtx::ambient(), projection.clone()));+ let beat = AbortOnDrop(spawn_heartbeat_with_interval(+ &DispatchCtx::ambient(),+ projection.clone(),+ Duration::from_millis(25),+ ));// Before `TurnStarted` the turn is not live: no beat, however long it waits.- tokio::time::sleep(Duration::from_secs(INFERENCE_HEARTBEAT_SECS * 3)).await;+ tokio::time::sleep(Duration::from_millis(100)).await;assert!(bus.try_recv().is_err());projection@@ -156,7 +161,7 @@ async fn the_heartbeat_beats_only_for_a_live_turn() {.await.on_event(AgentProgress::TurnStarted).await;- tokio::time::sleep(Duration::from_secs(INFERENCE_HEARTBEAT_SECS + 1)).await;+ tokio::time::sleep(Duration::from_millis(100)).await;let mut names = Vec::new();while let Ok(event) = bus.try_recv() {if event.context().thread_id == "host-hb-thread" {