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
fix(cron): deliver scheduled agent results to the originating channel
Steven Enamakeld6af15ba1256
diff --git a/crates/openhuman-core/src/cron/scheduler/agent_run.rs b/crates/openhuman-core/src/cron/scheduler/agent_run.rsindex 16a7479ddc..09a6b000a0 100644--- a/crates/openhuman-core/src/cron/scheduler/agent_run.rs+++ b/crates/openhuman-core/src/cron/scheduler/agent_run.rs@@ -20,16 +20,17 @@ pub(super) async fn run_agent_job(job: &CronJob,) -> (bool, String, Option<String>) {let run_id = uuid::Uuid::new_v4().to_string();- run_agent_job_for_run(config, job, &run_id).await+ run_agent_job_for_run(&crate::core::runtime::DispatchCtx::host_default(), config, job, &run_id).await}pub(super) async fn run_agent_job_for_run(+ ctx: &crate::core::runtime::DispatchCtx,config: &Config,job: &CronJob,run_id: &str,) -> (bool, String, Option<String>) {let name = job.name.clone().unwrap_or_else(|| "cron-job".to_string());- let prefixed_prompt = build_run_prompt(config, job, &name).await;+ let prefixed_prompt = build_run_prompt(ctx, config, job, &name).await;// Apply per-job model override onto a cloned Config, so the Agent// sees it through the normal `default_model` path without mutating@@ -152,11 +153,7 @@ pub(super) async fn run_agent_job_for_run(target = ?job.session_target,"[cron] building isolated agent for scheduled job");- match build_agent_for_cron_job(- &crate::core::runtime::DispatchCtx::ambient(),- &effective,- job,- ) {+ match build_agent_for_cron_job(ctx, &effective, job) {Ok(BuiltCronAgent { mut agent, context }) => {// Tag events so downstream subscribers can correlate// cron-triggered turns. `cron` is the channel so thediff --git a/crates/openhuman-core/src/cron/scheduler/executor.rs b/crates/openhuman-core/src/cron/scheduler/executor.rsindex d809be4d3d..90ec106f1f 100644--- a/crates/openhuman-core/src/cron/scheduler/executor.rs+++ b/crates/openhuman-core/src/cron/scheduler/executor.rs@@ -124,7 +124,9 @@ impl HostExecutor {run_job_command(&config, self.binding.security.as_ref(), job).await;(success, output, None)}- JobType::Agent => run_agent_job_for_run(&config, job, run_id).await,+ JobType::Agent => {+ run_agent_job_for_run(&self.binding.dispatch_ctx(), &config, job, run_id).await+ }JobType::Flow => (false,"flow jobs run through the trigger sink, not the executor".to_string(),diff --git a/crates/openhuman-core/src/cron/scheduler/origin_context.rs b/crates/openhuman-core/src/cron/scheduler/origin_context.rsindex fc3b78166f..23328ce4a3 100644--- a/crates/openhuman-core/src/cron/scheduler/origin_context.rs+++ b/crates/openhuman-core/src/cron/scheduler/origin_context.rs@@ -54,11 +54,15 @@ pub(crate) fn bounded_tail(}/// The origin conversation's recent messages, oldest first.-async fn origin_messages(config: &Config, origin: &JobOrigin) -> Vec<(String, String)> {+async fn origin_messages(+ ctx: &DispatchCtx,+ config: &Config,+ origin: &JobOrigin,+) -> Vec<(String, String)> {match origin {JobOrigin::Web { thread_id, .. } => {match crate::threads::store::blocking::get_messages(- DispatchCtx::ambient(),+ ctx.clone(),config.workspace_dir.clone(),thread_id.clone(),)@@ -101,7 +105,12 @@ pub(crate) fn compose_current_prompt(job_id: &str, name: &str, prompt: &str, tai/// The prompt a job runs with. `isolated` (and an origin-less job) keeps the/// plain tagged prompt; `current` and `main` get the context and preamble.-pub(crate) async fn build_run_prompt(config: &Config, job: &CronJob, name: &str) -> String {+pub(crate) async fn build_run_prompt(+ ctx: &DispatchCtx,+ config: &Config,+ job: &CronJob,+ name: &str,+) -> String {let prompt = job.prompt.clone().unwrap_or_default();use tinyflows_schedule::types::SessionTarget;match (&job.session_target, &job.origin) {@@ -115,7 +124,7 @@ pub(crate) async fn build_run_prompt(config: &Config, job: &CronJob, name: &str)}let tail = match origin {Some(origin) => {- let messages = origin_messages(config, origin).await;+ let messages = origin_messages(ctx, config, origin).await;bounded_tail(&messages, CONTEXT_MAX_MESSAGES, CONTEXT_MAX_CHARS)}None => String::new(),diff --git a/crates/openhuman-core/src/cron/scheduler/origin_delivery.rs b/crates/openhuman-core/src/cron/scheduler/origin_delivery.rsindex 2a6ff1c61e..3dca4b95f4 100644--- a/crates/openhuman-core/src/cron/scheduler/origin_delivery.rs+++ b/crates/openhuman-core/src/cron/scheduler/origin_delivery.rs@@ -200,6 +200,7 @@ pub(crate) async fn deliver_to_origin(agent_id,} => {deliver_to_web_thread(+ ctx,config,tenant.as_ref(),job,@@ -240,6 +241,7 @@ pub(crate) async fn deliver_to_origin(}async fn deliver_to_web_thread(+ ctx: &DispatchCtx,config: &Config,tenant: Option<&crate::core::runtime::Tenant>,job: &CronJob,@@ -260,7 +262,7 @@ async fn deliver_to_web_thread(let persist_thread = thread_id.to_string();let persist_request = request_id.clone();let persist_text = text.to_string();- let persist_ctx = DispatchCtx::ambient();+ let persist_ctx = ctx.clone();crate::core::runtime::spawn_blocking_scoped(move || {crate::web_chat::persist_delivered_reply(&persist_ctx,