Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(cron): add retry handling for failed scheduled jobs

Steven Enamakel6f48d52e8961
diff --git a/crates/openhuman-core/src/cron/ops.rs b/crates/openhuman-core/src/cron/ops.rs
index e084a45af4..bfda80ccee 100644
--- a/crates/openhuman-core/src/cron/ops.rs
+++ b/crates/openhuman-core/src/cron/ops.rs
@@ -228,6 +228,8 @@ pub async fn cron_run(config: &Config, job_id: &str) -> Result<Outcome<serde_jso
// Fail closed before queueing anything: an unreadable policy refuses the run.
cron::policy::get_policy(config, job_id).map_err(|e| e.to_string())?;
+ cron::limits::check_run(config, &cron::get_job(config, job_id).map_err(|e| e.to_string())?)
+ .map_err(|e| e.to_string())?;
// Guard against duplicate concurrent executions for the same job.
{
@@ -290,6 +292,7 @@ pub async fn cron_run(config: &Config, job_id: &str) -> Result<Outcome<serde_jso
pub async fn run_job_now(config: &Config, job_id: &str) -> Result<(bool, String), String> {
let job = cron::get_job(config, job_id.trim()).map_err(|e| e.to_string())?;
cron::policy::get_policy(config, &job.id).map_err(|e| e.to_string())?;
+ cron::limits::check_run(config, &job).map_err(|e| e.to_string())?;
let Some(_guard) = try_acquire_run(&job.id) else {
tracing::debug!(job_id = %job.id, "[cron_run] job already running; refused");
return Err(format!("cron job '{}' is already running", job.id));
diff --git a/crates/openhuman-core/src/cron/scheduler/dispatch.rs b/crates/openhuman-core/src/cron/scheduler/dispatch.rs
index ed2e141dc8..3b5313a290 100644
--- a/crates/openhuman-core/src/cron/scheduler/dispatch.rs
+++ b/crates/openhuman-core/src/cron/scheduler/dispatch.rs
@@ -73,6 +73,12 @@ impl JobDispatcher {
if get_policy(config, &job.id).is_err() {
continue;
}
+ // Operator limits (`cron::limits`) also bind rows stored before
+ // they were switched on.
+ if let Err(error) = crate::cron::limits::check_run(config, &job) {
+ tracing::warn!(job_id = %job.id, %error, "[cron:dispatch] job refused by operator limits");
+ continue;
+ }
claim_slot(config, &job);
let config = config.clone();
let security = Arc::clone(security);
diff --git a/crates/openhuman-core/src/cron/scheduler/retry.rs b/crates/openhuman-core/src/cron/scheduler/retry.rs
index 0f5b5f68a5..401e4ce6cf 100644
--- a/crates/openhuman-core/src/cron/scheduler/retry.rs
+++ b/crates/openhuman-core/src/cron/scheduler/retry.rs
@@ -50,6 +50,9 @@ pub(super) async fn execute_job_with_retry_for_run(
let mut last_agent_error: Option<String> = None;
// A per-job override (`cron::policy`) wins; `Some(0)` is one attempt. An
// unreadable policy refuses the run (and any later attempt) outright.
+ if let Err(error) = crate::cron::limits::check_run(config, job) {
+ return (false, error.to_string());
+ }
let policy = match crate::cron::policy::get_policy(config, &job.id) {
Ok(policy) => policy,
Err(error) => return (false, error.to_string()),
diff --git a/crates/openhuman-core/src/cron/tools/run.rs b/crates/openhuman-core/src/cron/tools/run.rs
index 1b2da23abc..d1a3bc1c6c 100644
--- a/crates/openhuman-core/src/cron/tools/run.rs
+++ b/crates/openhuman-core/src/cron/tools/run.rs
@@ -91,6 +91,9 @@ impl Tool for CronRunTool {
if let Err(e) = cron::policy::get_policy(&self.config, &job.id) {
return Ok(ToolResult::error(e.to_string()));
}
+ if let Err(e) = cron::limits::check_run(&self.config, &job) {
+ return Ok(ToolResult::error(e.to_string()));
+ }
// Claim the job so this run cannot overlap a scheduled tick or a Run Now.
let Some(_run_guard) = cron::ops::try_acquire_run(&job.id) else {