Skip to content

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

fix(cron): prevent overlapping cron runs and skip delivery for tool runs

Steven Enamakel32301ba5b089
diff --git a/crates/openhuman-core/src/cron/tools/run.rs b/crates/openhuman-core/src/cron/tools/run.rs
index 0358d6d605..3a1ce85418 100644
--- a/crates/openhuman-core/src/cron/tools/run.rs
+++ b/crates/openhuman-core/src/cron/tools/run.rs
@@ -88,6 +88,14 @@ impl Tool for CronRunTool {
}
};
+ // 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 {
+ return Ok(ToolResult::error(format!(
+ "cron job '{}' is already running",
+ job.id
+ )));
+ };
+
let started_at = Utc::now();
let run_id = uuid::Uuid::new_v4().to_string();
let (success, output) = cron::scheduler::execute_job_now(&self.config, &job, &run_id).await;
@@ -95,7 +103,11 @@ impl Tool for CronRunTool {
let duration_ms = (finished_at - started_at).num_milliseconds();
let status = if success { "ok" } else { "error" };
- let _ = cron::record_run(
+ // The output is returned to the calling agent below, so nothing is
+ // delivered here: an origin delivery would append to the transcript
+ // of the very session this tool call is running inside, and wait on
+ // that session's own turn lock.
+ let _ = cron::record_run_with_delivery(
&self.config,
&job.id,
started_at,
@@ -103,6 +115,7 @@ impl Tool for CronRunTool {
status,
Some(&output),
duration_ms,
+ Some(cron::DeliveryStatus::NotRequested),
);
let _ = cron::record_last_run(&self.config, &job.id, finished_at, success, &output);