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): add retry and run record tracking to scheduler
Steven Enamakelb900aabb31fe
diff --git a/crates/openhuman-core/src/cron/scheduler/retry.rs b/crates/openhuman-core/src/cron/scheduler/retry.rsindex 2d9f180f88..bf3a650f5b 100644--- a/crates/openhuman-core/src/cron/scheduler/retry.rs+++ b/crates/openhuman-core/src/cron/scheduler/retry.rs@@ -1,7 +1,7 @@//! The per-job retry loop with exponential backoff, its permanent-halt//! short-circuits, and the retries-exhausted observability report.-use super::agent_run::{run_agent_job, run_flow_schedule_job};+use super::agent_run::{run_agent_job_for_run, run_flow_schedule_job};use super::failure_classification::{is_api_key_unset_failure, is_budget_exhausted_failure, is_insufficient_credits_failure,is_local_provider_unreachable_failure, is_session_expired_failure, permanent_halt_message,@@ -17,19 +17,34 @@ pub(super) fn agent_session_target_tag(target: &SessionTarget) -> &'static str {match target {SessionTarget::Main => "main",SessionTarget::Isolated => "isolated",+ SessionTarget::Current => "current",}}-pub async fn execute_job_now(config: &Config, job: &CronJob) -> (bool, String) {+/// Run `job` now under the caller's `run_id` (also the id its delivery and+/// run record use).+pub async fn execute_job_now(config: &Config, job: &CronJob, run_id: &str) -> (bool, String) {let security =SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, &config.action_dir);- execute_job_with_retry(config, &security, job).await+ execute_job_with_retry_for_run(config, &security, job, run_id).await}+/// [`execute_job_with_retry_for_run`] under a fresh run id.+#[cfg(test)]pub(super) async fn execute_job_with_retry(config: &Config,security: &SecurityPolicy,job: &CronJob,+) -> (bool, String) {+ let run_id = uuid::Uuid::new_v4().to_string();+ execute_job_with_retry_for_run(config, security, job, &run_id).await+}++pub(super) async fn execute_job_with_retry_for_run(+ config: &Config,+ security: &SecurityPolicy,+ job: &CronJob,+ run_id: &str,) -> (bool, String) {let mut last_output = String::new();let mut last_agent_error: Option<String> = None;@@ -47,7 +62,7 @@ pub(super) async fn execute_job_with_retry(let (success, output) = run_job_command(config, security, job).await;(success, output, None)}- JobType::Agent => run_agent_job(config, job).await,+ JobType::Agent => run_agent_job_for_run(config, job, run_id).await,JobType::Flow => {let (success, output) = run_flow_schedule_job(job);(success, output, None)diff --git a/crates/openhuman-core/src/cron/scheduler/run_record.rs b/crates/openhuman-core/src/cron/scheduler/run_record.rsindex 44a6d7046a..b27ab79951 100644--- a/crates/openhuman-core/src/cron/scheduler/run_record.rs+++ b/crates/openhuman-core/src/cron/scheduler/run_record.rs@@ -1,17 +1,33 @@//! Persisting a finished run: delivery, run history, one-shot termination,//! rescheduling, and the high-frequency agent-job warning.-use super::delivery::deliver_if_configured;+use super::delivery::deliver_run;use crate::config::Config;use crate::cron::{- record_last_run, record_run, remove_job, reschedule_after_run, runs_closer_than, update_job,- CronJob, CronJobPatch, JobType, Schedule, TooFrequent, MIN_AGENT_JOB_INTERVAL,+ record_last_run, record_run_with_delivery, remove_job, reschedule_after_run, runs_closer_than,+ update_job, CronJob, DeliveryStatus, CronJobPatch, JobType, Schedule, TooFrequent, MIN_AGENT_JOB_INTERVAL,};use chrono::{DateTime, Utc};+/// [`persist_job_result_for_run`] under a fresh run id.+#[cfg(test)]pub(super) async fn persist_job_result(config: &Config,job: &CronJob,+ success: bool,+ output: &str,+ started_at: DateTime<Utc>,+ finished_at: DateTime<Utc>,+) -> bool {+ let run_id = uuid::Uuid::new_v4().to_string();+ persist_job_result_for_run(config, job, &run_id, success, output, started_at, finished_at)+ .await+}++pub(super) async fn persist_job_result_for_run(+ config: &Config,+ job: &CronJob,+ run_id: &str,mut success: bool,output: &str,started_at: DateTime<Utc>,@@ -19,16 +35,20 @@ pub(super) async fn persist_job_result() -> bool {let duration_ms = (finished_at - started_at).num_milliseconds();- if let Err(e) = deliver_if_configured(config, job, output, success).await {- if job.delivery.best_effort {- tracing::warn!("Cron delivery failed (best_effort): {e}");- } else {- success = false;- tracing::warn!("Cron delivery failed: {e}");+ let delivery_status = match deliver_run(config, job, run_id, output, success).await {+ Ok(status) => status,+ Err(e) => {+ if job.delivery.best_effort {+ tracing::warn!("Cron delivery failed (best_effort): {e}");+ } else {+ success = false;+ tracing::warn!("Cron delivery failed: {e}");+ }+ DeliveryStatus::Failed}- }+ };- let _ = record_run(+ let _ = record_run_with_delivery(config,&job.id,started_at,@@ -36,6 +56,7 @@ pub(super) async fn persist_job_result(if success { "ok" } else { "error" },Some(output),duration_ms,+ Some(delivery_status),);// A fixed-instant (`Schedule::At`) job is inherently one-shot: its `at` is in