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
feat(cron): give each embedded agent its own job store and run its jobs under its context (#7032)
oxoxDevb834b536fc18
diff --git a/crates/openhuman-core/src/cron/mod.rs b/crates/openhuman-core/src/cron/mod.rsindex 572864689b..639e5fe035 100644--- a/crates/openhuman-core/src/cron/mod.rs+++ b/crates/openhuman-core/src/cron/mod.rs@@ -16,7 +16,7 @@ pub mod ops;pub mod origin;mod schemas;pub mod seed;-mod store;+pub(crate) mod store;pub mod system_jobs;pub mod tools;diff --git a/crates/openhuman-core/src/cron/scheduler.rs b/crates/openhuman-core/src/cron/scheduler.rsindex 8e87f3fa2f..dbf6ce99af 100644--- a/crates/openhuman-core/src/cron/scheduler.rs+++ b/crates/openhuman-core/src/cron/scheduler.rs@@ -75,6 +75,46 @@ pub async fn run(config: Config) -> Result<()> {loop {interval.tick().await;tick_once(&config, &security, &mut last_emitted_health).await;+ tick_live_agents().await;+ }+}++/// Runs the due jobs of every live embedded agent, each under that agent's+/// own context: its config, provider route, policy and job database. An+/// agent that is not live has no context to run under, so its jobs stay+/// dormant until it is instantiated again.+pub(crate) async fn tick_live_agents() {+ for (agent_id, ctx) in crate::core::runtime::AgentContextRegistry::live() {+ let agent = agent_id.clone();+ crate::core::runtime::CoreContext::scope(ctx, async move {+ let config = match crate::config::ops::load_current_or_init().await {+ Ok(config) => config,+ Err(error) => {+ tracing::debug!(agent = %agent, %error, "[cron:scheduler] agent config unavailable");+ return;+ }+ };+ if !crate::cron::store::db_path(&config).exists() {+ return;+ }+ let jobs = match due_jobs(&config, Utc::now()) {+ Ok(jobs) => jobs,+ Err(error) => {+ tracing::warn!(agent = %agent, "[cron:scheduler] agent poll db_error: {error}");+ return;+ }+ };+ if jobs.is_empty() {+ return;+ }+ let Some(security) = crate::security::live_policy::effective() else {+ tracing::warn!(agent = %agent, "[cron:scheduler] agent has no policy; jobs skipped");+ return;+ };+ tracing::debug!(agent = %agent, due_count = jobs.len(), "[cron:scheduler] running agent jobs");+ process_due_jobs(&config, &security, jobs).await;+ })+ .await;}}diff --git a/crates/openhuman-core/src/cron/scheduler/origin_delivery.rs b/crates/openhuman-core/src/cron/scheduler/origin_delivery.rsindex 0e5e2f0c97..5491ead204 100644--- a/crates/openhuman-core/src/cron/scheduler/origin_delivery.rs+++ b/crates/openhuman-core/src/cron/scheduler/origin_delivery.rs@@ -69,8 +69,14 @@ pub(crate) async fn append_to_origin_transcript(append_background_message, BackgroundAppend, BackgroundAppendOutcome,FileTranscriptLocator, SessionRef, TranscriptMessage,};- let locator = FileTranscriptLocator::new(workspace_dir.to_path_buf());let session = SessionRef::scoped(append.thread_id.to_string(), append.agent_id.to_string());+ if let Some(agent) = crate::core::runtime::agent_scope::current_agent_id() {+ use tinyagents_session::transcript::TranscriptLocator;+ crate::agent::session_store::AgentTranscriptFiles::new(workspace_dir, &agent)+ .session_exists(&session);+ }+ let locator =+ FileTranscriptLocator::new(crate::agent::session_store::transcript_root(workspace_dir));let options = BackgroundAppend::new(append.idempotency_key,serde_json::json!({diff --git a/crates/openhuman-core/src/cron/store.rs b/crates/openhuman-core/src/cron/store.rsindex 374d6bcb3f..045efb4aa9 100644--- a/crates/openhuman-core/src/cron/store.rs+++ b/crates/openhuman-core/src/cron/store.rs@@ -12,11 +12,20 @@ use tinyflows_schedule::DeliveryStatus;use tinyflows_schedule::{CronJob, CronJobPatch, CronRun, DeliveryConfig, Schedule, SessionTarget};use tinyflows_sqlite::schedule::{self as upstream, AgentJobSpec, CronStoreOptions};-/// Builds the store options from the host config: `<workspace>/cron/jobs.db`,+/// The job database for `config`: `<workspace>/cron/jobs.db`, or the agent's+/// own `<workspace>/agents/<id>/cron/jobs.db` under an embedded agent's+/// context, so an agent lists, edits and runs only the jobs it created.+pub fn db_path(config: &Config) -> std::path::PathBuf {+ crate::core::runtime::agent_scope_dir(config)+ .join("cron")+ .join("jobs.db")+}++/// Builds the store options from the host config: [`db_path`],/// `cron.max_run_history`, `scheduler.max_tasks`.fn opts(config: &Config) -> CronStoreOptions {CronStoreOptions {- db_path: config.workspace_dir.join("cron").join("jobs.db"),+ db_path: db_path(config),max_run_history: config.cron.max_run_history,max_tasks: config.scheduler.max_tasks,}