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
chore: files changed crates/openhuman-core/src/core/README.md,crates/openhuman-core/src/core/bus.rs,
Steven Enamakel67d0030956a4
diff --git a/crates/openhuman-core/src/core/README.md b/crates/openhuman-core/src/core/README.mdindex 83b2eeb21b..aa95253d3e 100644--- a/crates/openhuman-core/src/core/README.md+++ b/crates/openhuman-core/src/core/README.md@@ -155,7 +155,7 @@ and the host is the one that knows `E`. [`events.rs`](./events.rs) is the event`DomainEvent`, a `#[non_exhaustive]` enum whose `domain()` value is appendedto `EVENTS_ROOT` (`/ai/tinyhumans/openhuman/events`) as the routing key.The catalog is published under `EVENTS_INTERFACE`-(`ai.tinyhumans.openhuman.Events2`) at `EVENTS_VERSION`, currently `2.0.0`.+(`ai.tinyhumans.openhuman.Events2`) at `EVENTS_VERSION`, currently `2.1.0`.`bus::init()` starts the in-process broker and announces a peer manifest(advisory; failure only logs). Every accessor is safe before `init`:diff --git a/crates/openhuman-core/src/core/bus.rs b/crates/openhuman-core/src/core/bus.rsindex 2596c4c2e7..269f97c28d 100644--- a/crates/openhuman-core/src/core/bus.rs+++ b/crates/openhuman-core/src/core/bus.rs@@ -96,7 +96,9 @@ pub const EVENTS_INTERFACE: &str = "ai.tinyhumans.openhuman.Events2";/// ambient one./// `2.0.0` removes `CronDeliveryRequested`; announce delivery now sends/// synchronously through the cron channel bridge.-pub const EVENTS_VERSION: Version = Version::new(2, 0, 0);+/// `2.1.0` adds an optional `tenant` to `CronJobCompleted` so subscribers+/// retain the job's owner after a one-shot row is deleted.+pub const EVENTS_VERSION: Version = Version::new(2, 1, 0);/// The bus. Initialised once by [`init`]; safe to touch before that.pub static BUS: OnceBus<DomainEvent> = OnceBus::new();diff --git a/crates/openhuman-core/src/core/events.rs b/crates/openhuman-core/src/core/events.rsindex 749bfa3a2c..d8987e3262 100644--- a/crates/openhuman-core/src/core/events.rs+++ b/crates/openhuman-core/src/core/events.rs@@ -384,6 +384,10 @@ pub enum DomainEvent {job_id: String,success: bool,output: String,+ /// The tenant that ran the job. A one-shot job may be deleted before+ /// subscribers process this event, so ownership must travel with it.+ #[serde(default, skip_serializing_if = "Option::is_none")]+ tenant: Option<crate::core::runtime::Tenant>,},/// A proactive message (morning briefing, welcome, cron output, etc.)/// needs to be delivered to the user. The channels module routes it todiff --git a/crates/openhuman-core/src/core/events_tests.rs b/crates/openhuman-core/src/core/events_tests.rsindex 2a53165a2d..e0132ca8e2 100644--- a/crates/openhuman-core/src/core/events_tests.rs+++ b/crates/openhuman-core/src/core/events_tests.rs@@ -776,6 +776,7 @@ fn events_outside_the_supervisor_have_no_event_log_detail() {job_id: "job-1".into(),success: true,output: "done".into(),+ tenant: None,}.log_detail().is_none());@@ -930,6 +931,7 @@ fn events_without_a_workspace_report_none() {job_id: "job-1".into(),success: true,output: "done".into(),+ tenant: None,}.workspace_dir(),Nonediff --git a/crates/openhuman-core/src/cron/completion_owner.rs b/crates/openhuman-core/src/cron/completion_owner.rsdeleted file mode 100644index c2db8736ee..0000000000--- a/crates/openhuman-core/src/cron/completion_owner.rs+++ /dev/null@@ -1,47 +0,0 @@-//! Which agent a just-completed cron job belonged to.-//!-//! `CronJobCompleted` names only the job, and a one-shot job-//! (`delete_after_run`) is already gone from the store by the time a-//! subscriber sees the event, so its owner cannot be looked up there. The-//! scheduler publishes the event inside the job's own task, which carries the-//! agent's context, and notes the owner here first; the notification bridge-//! takes it back out (`desktop::notifications`).-//!-//! In-process only — the bus delivers locally — and bounded: if no subscriber-//! drains it (the bridge is not registered), it is cleared rather than grown.--use std::collections::HashMap;-use std::sync::{LazyLock, Mutex};--/// Notes kept before the map is cleared outright.-const CAPACITY: usize = 1024;--/// Job id → the agent it ran as.-static OWNERS: LazyLock<Mutex<HashMap<String, String>>> = LazyLock::new(Default::default);--/// Notes that `job_id` just completed as the current context's agent, when-/// it ran as one. Call just before publishing `CronJobCompleted`.-pub fn note(ctx: &crate::core::runtime::DispatchCtx, job_id: &str) {- let Some(agent) = ctx.tenant().ok().and_then(|tenant| tenant.agent) else {- return;- };- let mut owners = OWNERS- .lock()- .unwrap_or_else(std::sync::PoisonError::into_inner);- if owners.len() >= CAPACITY {- owners.clear();- }- owners.insert(job_id.to_string(), agent);-}--/// The agent `job_id` completed as, if one was noted; removes the note.-pub fn take(job_id: &str) -> Option<String> {- OWNERS- .lock()- .unwrap_or_else(std::sync::PoisonError::into_inner)- .remove(job_id)-}--#[cfg(test)]-#[path = "completion_owner_tests.rs"]-mod tests;diff --git a/crates/openhuman-core/src/cron/completion_owner_tests.rs b/crates/openhuman-core/src/cron/completion_owner_tests.rsdeleted file mode 100644index a7e21334ef..0000000000--- a/crates/openhuman-core/src/cron/completion_owner_tests.rs+++ /dev/null@@ -1,58 +0,0 @@-use super::*;-use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet};--#[tokio::test]-async fn a_job_completed_as_an_agent_is_noted_once() {- let agent = CoreContext::for_test(DomainSet::full(), None).derive_with(- ContextOverlay::new(- crate::config::Config::default(),- DomainSet::full(),- Default::default(),- )- .session_agent("completion-owner-agent"),- );- {- let scope_ctx = crate::core::runtime::DispatchCtx::new(agent);-- note(&scope_ctx, "completion-owner-job")- };- assert_eq!(- take("completion-owner-job").as_deref(),- Some("completion-owner-agent")- );- assert_eq!(take("completion-owner-job"), None, "taken once");-}--#[test]-fn a_job_completed_without_an_agent_is_not_noted() {- note(- &crate::core::runtime::DispatchCtx::ambient(),- "completion-owner-local",- );- assert_eq!(take("completion-owner-local"), None);-}--#[tokio::test]-async fn the_explicit_context_names_the_owner_with_no_task_scope() {- let agent = CoreContext::for_test(DomainSet::full(), None).derive_with(- ContextOverlay::new(- crate::config::Config::default(),- DomainSet::full(),- Default::default(),- )- .session_agent("explicit-owner-agent"),- );- // Not inside `CoreContext::scope`: the explicit value alone decides, even- // across an await and on a spawned task.- let ctx = crate::core::runtime::DispatchCtx::new(agent);- tokio::spawn(async move {- tokio::task::yield_now().await;- note(&ctx, "explicit-owner-job");- })- .await- .expect("note task ran");- assert_eq!(- take("explicit-owner-job").as_deref(),- Some("explicit-owner-agent")- );-}diff --git a/crates/openhuman-core/src/cron/mod.rs b/crates/openhuman-core/src/cron/mod.rsindex 7e984ceed7..021112ea38 100644--- a/crates/openhuman-core/src/cron/mod.rs+++ b/crates/openhuman-core/src/cron/mod.rs@@ -15,7 +15,6 @@pub(crate) mod bus_host;pub mod channel_bridge;pub(crate) mod client;-pub mod completion_owner;pub(crate) mod documents_port;pub mod handlers;pub mod host_delivery;@@ -37,8 +36,6 @@ pub mod scheduler;mod cutover_tests;pub use ops as rpc;-#[cfg(test)]-pub use ops::update_cron_job;pub use ops::{add_once, add_once_at, pause_job, resume_job};pub use schemas::{all_controller_schemas as all_cron_controller_schemas,@@ -46,10 +43,10 @@ pub use schemas::{};#[allow(unused_imports)]pub use store::{- add_agent_job, add_agent_job_from_spec, add_agent_job_with_definition, add_flow_schedule_job,- add_job, add_shell_job, clear_all_jobs, dedup_named_jobs, delete_queued_runs, due_jobs,+ add_agent_job_from_spec, add_agent_job_with_definition, add_flow_schedule_job,+ add_job, add_shell_job, clear_all_jobs, dedup_named_jobs, delete_queued_runs,find_flow_schedule_job, get_job, list_jobs, list_runs, record_last_run, record_run,- record_run_with_delivery, remove_job, reschedule_after_run, update_job,+ record_run_with_delivery, remove_job, update_job,};// The job, run and schedule records are the tinyflows bus contract's; the// host re-exports them so `cron::Schedule` etc. keep their paths and no type isdiff --git a/crates/openhuman-core/src/cron/scheduler/run_delivery.rs b/crates/openhuman-core/src/cron/scheduler/run_delivery.rsindex 65a8939299..be1a21e99e 100644--- a/crates/openhuman-core/src/cron/scheduler/run_delivery.rs+++ b/crates/openhuman-core/src/cron/scheduler/run_delivery.rs@@ -59,11 +59,11 @@ pub(crate) fn publish_completion(success: bool,output: &str,) {- crate::cron::completion_owner::note(ctx, &job.id);BUS.publish(DomainEvent::CronJobCompleted {job_id: job.id.clone(),success,output: crate::util::truncate_with_ellipsis(output, 512),+ tenant: ctx.event_tenant(),});BUS.publish(DomainEvent::HealthChanged {component: "scheduler".to_string(),@@ -108,12 +108,6 @@ fn stand_in(flow_id: &str) -> CronJob {}}-/// A stand-in `flow` row with `command`, for tests of handlers.-#[cfg(test)]-pub(crate) fn stand_in_for_test(command: &str) -> CronJob {- stand_in(command)-}-/// Fire the `flow` row bound to `flow_id` through the registered `flow`/// handler.pub(crate) async fn trigger(binding: &Binding, flow_id: &str, run_id: &str) -> Attempt {diff --git a/crates/openhuman-core/src/desktop/notifications/bus_tests.rs b/crates/openhuman-core/src/desktop/notifications/bus_tests.rsindex 2e1521279c..bf9bdd2f75 100644--- a/crates/openhuman-core/src/desktop/notifications/bus_tests.rs+++ b/crates/openhuman-core/src/desktop/notifications/bus_tests.rs@@ -103,6 +103,7 @@ fn cron_notification_id_contains_job_id() {job_id: "daily-report".into(),success: true,output: "ok".into(),+ tenant: None,};let n = event_to_notification(&ev).unwrap();assert!(@@ -121,6 +122,7 @@ fn cron_deep_link_points_to_cron_jobs_settings() {job_id: "j1".into(),success: false,output: String::new(),+ tenant: None,};let n = event_to_notification(&ev).unwrap();assert_eq!(@@ -299,6 +301,7 @@ async fn subscriber_persists_core_notification_so_it_survives_disconnect() {job_id: "daily-digest".into(),success: true,output: "ok".into(),+ tenant: None,}).await;@@ -319,6 +322,7 @@ async fn subscriber_without_config_does_not_persist_but_still_translates() {job_id: "j".into(),success: false,output: String::new(),+ tenant: None,}).await;// Nothing to assert beyond "did not panic / persist" — the translation is@@ -401,6 +405,7 @@ fn a_process_wide_notification_names_no_workspace() {job_id: "daily-digest".into(),success: true,output: String::new(),+ tenant: None,}).expect("a completed cron job notifies");diff --git a/crates/openhuman-core/src/desktop/notifications/bus_tests_2_tests.rs b/crates/openhuman-core/src/desktop/notifications/bus_tests_2_tests.rsindex df4cbb81e2..6ea2ada01b 100644--- a/crates/openhuman-core/src/desktop/notifications/bus_tests_2_tests.rs+++ b/crates/openhuman-core/src/desktop/notifications/bus_tests_2_tests.rs@@ -86,6 +86,7 @@ fn cron_completed_produces_agents_notification() {job_id: "job-1".into(),success: true,output: "done".into(),+ tenant: None,};let n = event_to_notification(&ev).expect("should produce notification");assert_eq!(n.category, CoreNotificationCategory::Agents);@@ -116,6 +117,7 @@ fn cron_failed_uses_failure_title() {job_id: "job-1".into(),success: false,output: "error".into(),+ tenant: None,};let n = event_to_notification(&ev).unwrap();assert_eq!(n.title, "Cron job failed");@@ -458,6 +460,7 @@ fn an_event_that_names_no_workspace_uses_this_bridge_s_store() {job_id: "job-1".into(),success: true,output: "done".into(),+ tenant: None,},);assert_eq!(target.workspace_dir, own);@@ -580,6 +583,7 @@ async fn a_process_wide_event_is_announced_without_consulting_the_workspace() {job_id: "job-1".into(),success: true,output: "done".into(),+ tenant: None,}).await,super::Announce::Unbound@@ -631,6 +635,7 @@ async fn a_noted_cron_completion_names_its_agent() {job_id: "notif-owner-job".into(),success: true,output: String::new(),+ tenant: None,};let owner = event_owner(&crate::core::runtime::DispatchCtx::host_default(),