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: 姫The diff is empty — no changes are shown for any of the listed files. Without any added
Steven Enamakel24a7330ae290
diff --git a/crates/openhuman-core/src/cron/scheduler.rs b/crates/openhuman-core/src/cron/scheduler.rsindex 0b51b21ac1..5eaab97436 100644--- a/crates/openhuman-core/src/cron/scheduler.rs+++ b/crates/openhuman-core/src/cron/scheduler.rs@@ -75,7 +75,7 @@ pub async fn run(config: Config) -> Result<()> {loop {interval.tick().await;tick_once(&config, &security, &mut last_emitted_health).await;- tick_agents(&config, &security).await;+ tick_agents(&config, &mut last_emitted_health).await;}}@@ -83,15 +83,32 @@ pub async fn run(config: Config) -> Result<()> {/// (`crate::storage::agents`): a job an agent scheduled from its own turn/// lives there, and runs there — under that agent's context and, when the/// agent is live, its configuration. Only the `local` pass reports the-/// scheduler's health; an agent pass still reports a failing job.-pub(crate) async fn tick_agents(config: &Config, security: &Arc<SecurityPolicy>) {+/// scheduler's health tracker (`last_emitted_health`, shared with the `local`+/// pass so a failure or recovery reported from an agent pass is seen by the+/// next one); each agent pass authorizes its jobs with a policy built from+/// that agent's own configuration.+pub(crate) async fn tick_agents(config: &Config, last_emitted_health: &mut Option<bool>) {+ let health = std::sync::Mutex::new(*last_emitted_health);crate::storage::agents::for_each_agent("cron", || async {let config = crate::core::runtime::CoreContext::current_embedder_config().unwrap_or_else(|| config.clone());- let mut steady = Some(true);- tick_once(&config, security, &mut steady).await;+ let security = Arc::new(SecurityPolicy::from_config(+ &config.autonomy,+ &config.workspace_dir,+ &config.action_dir,+ ));+ let mut steady = *health+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner);+ tick_once(&config, &security, &mut steady).await;+ *health+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner) = steady;}).await;+ *last_emitted_health = health+ .into_inner()+ .unwrap_or_else(std::sync::PoisonError::into_inner);}/// Single poll cycle of the scheduler loop, extracted so tests can drivediff --git a/crates/openhuman-core/src/flows/ops/run_management.rs b/crates/openhuman-core/src/flows/ops/run_management.rsindex 684da8c634..77fb425d3c 100644--- a/crates/openhuman-core/src/flows/ops/run_management.rs+++ b/crates/openhuman-core/src/flows/ops/run_management.rs@@ -272,6 +272,15 @@ pub async fn sweep_expired_parked_runs(config: &Config) -> usize {pub async fn sweep_orphaned_running_runs_on_boot(config: &Config) -> usize {// `local`, then every agent that keeps its runs in its own storage scope// (`crate::storage::agents`).+ //+ // On a backend other processes share (MongoDB), a `running` row below the+ // boot floor can belong to a run another replica is still driving, and+ // sweeping it would drop that run's checkpoint — so the agent scopes are+ // left alone there, as the agent run reaper does.+ if crate::storage::installed_is_shared() && !crate::core::runtime::mode::is_saas() {+ log::info!("[flows] boot sweep: agent scopes skipped, the storage backend is shared");+ return sweep_orphaned_running_runs_in_scope(config).await;+ }crate::storage::agents::for_each_scope("flows boot sweep", || {sweep_orphaned_running_runs_in_scope(config)})diff --git a/crates/openhuman-core/src/integrations/task_sources/periodic.rs b/crates/openhuman-core/src/integrations/task_sources/periodic.rsindex d1c236b003..f5464fa82e 100644--- a/crates/openhuman-core/src/integrations/task_sources/periodic.rs+++ b/crates/openhuman-core/src/integrations/task_sources/periodic.rs@@ -43,10 +43,21 @@ fn last_poll_map() -> &'static LastPollMap {LAST_POLL_AT.get_or_init(|| Mutex::new(HashMap::new()))}+/// The poll-tracking key for `source_id` in the current storage scope: the+/// same source id in two agents' scopes is two different sources.+fn poll_key(source_id: &str) -> String {+ let agent = crate::core::runtime::CoreContext::current()+ .and_then(|context| context.session_agent().map(str::to_string));+ match agent {+ Some(agent) => format!("{agent}\u{0}{source_id}"),+ None => source_id.to_string(),+ }+}+/// Record a successful (or attempted) poll for a source id.fn record_poll(source_id: &str) {if let Ok(mut map) = last_poll_map().lock() {- map.insert(source_id.to_string(), Instant::now());+ map.insert(poll_key(source_id), Instant::now());}}@@ -57,7 +68,7 @@ fn is_due(source: &TaskSource) -> bool {Ok(map) => map,Err(poisoned) => poisoned.into_inner(),};- match map.get(&source.id) {+ match map.get(&poll_key(&source.id)) {Some(when) => when.elapsed() >= Duration::from_secs(interval_secs),None => true, // never polled this run — fire immediately}diff --git a/crates/openhuman-core/src/security/devices/owner.rs b/crates/openhuman-core/src/security/devices/owner.rsindex ed5f8952eb..54fc515b68 100644--- a/crates/openhuman-core/src/security/devices/owner.rs+++ b/crates/openhuman-core/src/security/devices/owner.rs@@ -47,10 +47,12 @@ pub(super) async fn owner_of(channel_id: &str, pending: Option<&PairingSession>)if let Some(owner) = cached(channel_id) {return owner;}- let Ok(config) = crate::config::rpc::load_config_with_timeout().await else {- return None;- };+ // The configuration is loaded inside each scope: in SaaS mode loading it+ // needs an acting agent, which this tunnel task does not have.let found = crate::storage::agents::for_each_scope("device owner", || async {+ let Ok(config) = crate::config::rpc::load_config_with_timeout().await else {+ return false;+ };super::store::get_device(&config, channel_id).ok().flatten()diff --git a/crates/openhuman-core/src/storage/agents.rs b/crates/openhuman-core/src/storage/agents.rsindex 1fbc6eaf45..9d709001b2 100644--- a/crates/openhuman-core/src/storage/agents.rs+++ b/crates/openhuman-core/src/storage/agents.rs@@ -37,7 +37,11 @@ use crate::core::runtime::CoreContext;const AGENTS: &str = "storage_agents";/// Live agent contexts, by agent id.-static LIVE: LazyLock<Mutex<BTreeMap<String, Weak<CoreContext>>>> = LazyLock::new(Default::default);+///+/// Several contexts can name one agent (each `derive_with` makes one), so each+/// agent keeps all of its live contexts, newest last.+static LIVE: LazyLock<Mutex<BTreeMap<String, Vec<Weak<CoreContext>>>>> =+ LazyLock::new(Default::default);/// Agent ids this process has already recorded in the backend.static RECORDED: LazyLock<Mutex<HashSet<String>>> = LazyLock::new(Default::default);@@ -47,14 +51,28 @@ static RECORDED: LazyLock<Mutex<HashSet<String>>> = LazyLock::new(Default::defau/// context through here.pub fn registered(context: Arc<CoreContext>) -> Arc<CoreContext> {if let Some(agent) = context.session_agent() {- LIVE.lock()- .unwrap_or_else(std::sync::PoisonError::into_inner)- .insert(agent.to_string(), Arc::downgrade(&context));+ let mut live = LIVE+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner);+ let contexts = live.entry(agent.to_string()).or_default();+ contexts.retain(|existing| existing.strong_count() > 0);+ contexts.push(Arc::downgrade(&context));+ drop(live);record(agent);}context}+/// Forgets which agents were recorded, so the next [`record`] writes them to+/// the backend now installed (or removed). Called by [`super::install`] and+/// [`super::clear`]: the record cache describes one backend, not the process.+pub(super) fn reset_recorded() {+ RECORDED+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner)+ .clear();+}+/// Records every live agent in the backend — for agents derived before the/// host installed its backend. Called by [`super::install`].pub(super) fn record_live() {@@ -130,12 +148,13 @@ fn agent_contexts(fallback: Option<&Arc<CoreContext>>) -> Vec<(String, Arc<CoreClet mut live = LIVE.lock().unwrap_or_else(std::sync::PoisonError::into_inner);- live.retain(|agent, context| match context.upgrade() {- Some(context) => {+ live.retain(|agent, entries| {+ entries.retain(|entry| entry.strong_count() > 0);+ // The newest context that is still alive acts for the agent.+ if let Some(context) = entries.iter().rev().find_map(Weak::upgrade) {contexts.insert(agent.clone(), context);- true}- None => false,+ !entries.is_empty()});}if !crate::core::runtime::mode::is_saas() {@@ -157,7 +176,7 @@ pub fn context_for(agent: &str) -> Option<Arc<CoreContext>> {.lock().unwrap_or_else(std::sync::PoisonError::into_inner).get(agent)- .and_then(Weak::upgrade);+ .and_then(|entries| entries.iter().rev().find_map(Weak::upgrade));live.or_else(|| CoreContext::current().map(|current| current.for_agent(agent)))}diff --git a/crates/openhuman-core/src/storage/mod.rs b/crates/openhuman-core/src/storage/mod.rsindex 490f93423f..5d67a8f2e1 100644--- a/crates/openhuman-core/src/storage/mod.rs+++ b/crates/openhuman-core/src/storage/mod.rs@@ -104,6 +104,8 @@ pub async fn open(url: &str) -> Result<Arc<dyn StorageBackend>, StorageError> {/// Makes `backend` the process's storage backend; returns the previous one.pub fn install(backend: Arc<dyn StorageBackend>) -> Option<Arc<dyn StorageBackend>> {let previous = BACKEND.install(backend);+ // What was recorded described the previous backend.+ agents::reset_recorded();// Agents derived before the backend existed still need recording.agents::record_live();previous@@ -116,6 +118,7 @@ pub fn installed() -> Option<Arc<dyn StorageBackend>> {/// Removes the installed backend; returns whether there was one.pub fn clear() -> bool {+ agents::reset_recorded();BACKEND.clear()}