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(orchestration): expose drain scheduling to tenant tests
Steven Enamakel8d81ff3fd42b
diff --git a/crates/openhuman-core/src/agent/orchestration/background_completions.rs b/crates/openhuman-core/src/agent/orchestration/background_completions.rsindex 807f2e6f68..9dcfecd884 100644--- a/crates/openhuman-core/src/agent/orchestration/background_completions.rs+++ b/crates/openhuman-core/src/agent/orchestration/background_completions.rs@@ -167,7 +167,9 @@ fn degrade_to_memory(workspace_dir: &Path, failed: &Arc<CompletionRouter>) -> Arrouter: Arc::new(new_router(store.clone())),store,});- state().routers.insert(workspace_dir.to_path_buf(), entry.clone());+ state()+ .routers+ .insert(workspace_dir.to_path_buf(), entry.clone());log::error!("[background_completions] degraded to an in-memory queue workspace_dir={}",workspace_dir.display()diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery.rsindex 763b2bd8b2..e7b06c40ad 100644--- a/crates/openhuman-core/src/agent/orchestration/background_delivery.rs+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery.rs@@ -141,10 +141,10 @@ impl EventHandler<DomainEvent> for BackgroundDeliveryHandler {/// One drain an event asks for: the thread, how soon, and the context of the/// profile that owns it (`None` on the desktop, where nothing is per profile).-struct Drain {- owner: Option<Arc<CoreContext>>,- thread_id: String,- delay: Duration,+pub(super) struct Drain {+ pub(super) owner: Option<Arc<CoreContext>>,+ pub(super) thread_id: String,+ pub(super) delay: Duration,}/// Which thread to drain, and after how long, for an event, outside any@@ -152,7 +152,9 @@ struct Drain {/// to deliver into.#[cfg(test)]fn drain_schedule(event: &DomainEvent) -> Option<(String, Duration)> {- let drain = drain_schedule_in(false, event, |_| None).into_iter().next()?;+ let drain = drain_schedule_in(false, event, |_| None)+ .into_iter()+ .next()?;Some((drain.thread_id, drain.delay))}@@ -162,7 +164,7 @@ fn drain_schedule(event: &DomainEvent) -> Option<(String, Duration)> {/// [`completion_owners`] and each is resolved through `resolve` and drained in/// its own scope, where it reaches only its own tables. In SaaS (`saas`) an id/// with no owner is dropped; elsewhere it drains unscoped, as on the desktop.-fn drain_schedule_in(+pub(super) fn drain_schedule_in(saas: bool,event: &DomainEvent,resolve: impl Fn(&str) -> Option<Arc<CoreContext>>,@@ -201,7 +203,9 @@ fn drain_schedule_in(};// A task id is core-minted and unique, so it names its one owner; a// session id can be shared by profiles, so it may name several.- let mut profiles = task.map(|t| completion_owners::profiles_of(t)).unwrap_or_default();+ let mut profiles = task+ .map(|t| completion_owners::profiles_of(t))+ .unwrap_or_default();if profiles.is_empty() {profiles = completion_owners::profiles_of(session);}@@ -215,7 +219,11 @@ fn drain_schedule_in(if thread_id.is_none() {log::trace!("[background_delivery] session has no delivery thread; not scheduling");}- thread_id.map(|thread_id| Drain { owner, thread_id, delay })+ thread_id.map(|thread_id| Drain {+ owner,+ thread_id,+ delay,+ })};if profiles.is_empty() {if saas {diff --git a/crates/openhuman-core/src/agent/orchestration/background_delivery_tenant_tests.rs b/crates/openhuman-core/src/agent/orchestration/background_delivery_tenant_tests.rsindex 15010c7585..e771694dd2 100644--- a/crates/openhuman-core/src/agent/orchestration/background_delivery_tenant_tests.rs+++ b/crates/openhuman-core/src/agent/orchestration/background_delivery_tenant_tests.rs@@ -69,7 +69,14 @@ async fn an_off_task_completion_drains_only_its_owners_thread() {for (ctx, ws, task) in [(&alice, &ws_a, &task_a), (&bob, &ws_b, &task_b)] {CoreContext::scope(Arc::clone(ctx),- record_completion(ws.path(), &session, task.as_str(), "r", "done", Some(thread.into())),+ record_completion(+ ws.path(),+ &session,+ task.as_str(),+ "r",+ "done",+ Some(thread.into()),+ ),).await;}@@ -86,7 +93,11 @@ async fn an_off_task_completion_drains_only_its_owners_thread() {let (owner, drained_thread, pending) = seen_by(&drains[0]);assert_eq!(owner.as_deref(), Some(alice_id.as_str()));assert_eq!(drained_thread, thread);- assert_eq!(pending, [task_a.clone()], "alice's drain reaches only her result");+ assert_eq!(+ pending,+ [task_a.clone()],+ "alice's drain reaches only her result"+ );// A turn ending on the shared session drains each owner in its own scope.let turn_done = DomainEvent::AgentTurnCompleted {@@ -111,12 +122,8 @@ async fn an_off_task_completion_drains_only_its_owners_thread() {let drains = drain_schedule_in(true, &completed(&session, &unique("sub-x")), only_bob);assert_eq!(drains.len(), 1);assert_eq!(seen_by(&drains[0]).0.as_deref(), Some(bob_id.as_str()));- assert!(drain_schedule_in(true, &completed("s", &task_b_owner_free()), only_bob).is_empty());-}--/// A task id nothing recorded.-fn task_b_owner_free() -> String {- unique("sub-nobody")+ // A task and session nothing recorded: dropped.+ assert!(drain_schedule_in(true, &completed("s", &unique("sub-none")), only_bob).is_empty());}#[test]