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): allow trusted system jobs under agent-only limits
Steven Enamakelbbab42573fb7
diff --git a/crates/openhuman-core/src/cron/bus_host.rs b/crates/openhuman-core/src/cron/bus_host.rsindex 7847d99810..ef1e972c51 100644--- a/crates/openhuman-core/src/cron/bus_host.rs+++ b/crates/openhuman-core/src/cron/bus_host.rs@@ -282,11 +282,16 @@ pub(crate) async fn register(binding: Binding) -> Result<HostRegistration, Strin/// Whether a job of `job_type` may run under `binding`, and the refusal text/// if not.-pub(crate) fn kind_refusal(binding: &Binding, job_type: &JobType) -> Option<String> {- (binding.is_agent_only() && !matches!(job_type, JobType::Agent)).then(|| {+pub(crate) fn kind_refusal(binding: &Binding, job: &CronJob) -> Option<String> {+ let owner_allowed =+ crate::cron::system_jobs::trusted_system_job_owner(job).is_some();+ (binding.is_agent_only()+ && !matches!(job.job_type, JobType::Agent)+ && !owner_allowed)+ .then(|| {"blocked by hosting policy: only agent cron jobs run here; shell and flow jobs are disabled".to_string()- })+ })}#[cfg(test)]diff --git a/crates/openhuman-core/src/cron/limits.rs b/crates/openhuman-core/src/cron/limits.rsindex 424fceba60..c4d93ffda8 100644--- a/crates/openhuman-core/src/cron/limits.rs+++ b/crates/openhuman-core/src/cron/limits.rs@@ -14,6 +14,7 @@ use chrono::{Duration, Utc};use crate::config::Config;use crate::cron::{delivery_mode, CronJob, CronJobPatch, DeliveryConfig, JobType, Schedule};+use crate::cron::system_jobs::TrustedSystemJobOwner;/// Whether `config` restricts cron to agent jobs.pub fn enforced(config: &Config) -> bool {@@ -61,6 +62,25 @@ fn install_capacity_limit(config: &Config) -> Result<()> {Ok(())}+/// Admit a job for an owning system domain. The typed owner comes from the+/// internal seeding call, never from a request or stored metadata.+pub(crate) fn check_trusted_system_job(+ config: &Config,+ owner: TrustedSystemJobOwner,+ name: &str,+ schedule: &Schedule,+) -> Result<()> {+ if !owner.owns(name) {+ bail!("system job name is outside its owning domain");+ }+ if !enforced(config) {+ clear_capacity_limit_if_supported(config)?;+ return Ok(());+ }+ check_schedule(config, schedule)?;+ install_capacity_limit(config)+}+/// Clear a prior operator cap when enforcement is off. Backends without/// transactions cannot clear it, so skip the unsupported write; TinyFlows'/// admission ledger guard refuses mutations if an earlier policy is present.@@ -128,6 +148,15 @@ pub(crate) fn check_run(config: &Config, job: &CronJob) -> Result<()> {if !enforced(config) {return Ok(());}+ if let Some(owner) = crate::cron::system_jobs::trusted_system_job_owner(job) {+ let name = crate::cron::system_jobs::system_job_name(job)+ .expect("trusted system rows have a system job name");+ if owner.owns(name) {+ check_schedule(config, &job.schedule)?;+ check_delivery(&job.delivery)?;+ return Ok(());+ }+ }check_type(&job.job_type)?;check_schedule(config, &job.schedule)?;check_delivery(&job.delivery)diff --git a/crates/openhuman-core/src/cron/scheduler/executor.rs b/crates/openhuman-core/src/cron/scheduler/executor.rsindex d0527ac3cf..a2edfc2a37 100644--- a/crates/openhuman-core/src/cron/scheduler/executor.rs+++ b/crates/openhuman-core/src/cron/scheduler/executor.rs@@ -101,7 +101,7 @@ impl HostExecutor {self.binding.publish_triggered_once(job, run_id);}// A hosted-profile sweep runs agent jobs only.- if let Some(refusal) = kind_refusal(&self.binding, &job.job_type) {+ if let Some(refusal) = kind_refusal(&self.binding, job) {self.halt(run_id, Halt::Refused);return Attempt {success: false,diff --git a/crates/openhuman-core/src/cron/scheduler/run_delivery.rs b/crates/openhuman-core/src/cron/scheduler/run_delivery.rsindex dcf1d0ed54..4557b2c87b 100644--- a/crates/openhuman-core/src/cron/scheduler/run_delivery.rs+++ b/crates/openhuman-core/src/cron/scheduler/run_delivery.rs@@ -137,7 +137,7 @@ pub(crate) async fn trigger(binding: &Binding, flow_id: &str, run_id: &str) -> Aretryable: false,};}- if let Some(refusal) = kind_refusal(binding, &job.job_type) {+ if let Some(refusal) = kind_refusal(binding, &job) {return Attempt {success: false,output: refusal,diff --git a/crates/openhuman-core/src/cron/system_jobs.rs b/crates/openhuman-core/src/cron/system_jobs.rsindex d3dc63b757..512d483d93 100644--- a/crates/openhuman-core/src/cron/system_jobs.rs+++ b/crates/openhuman-core/src/cron/system_jobs.rs@@ -26,6 +26,22 @@ use {tinyflows_bus::schedule::types::JobType, tinyflows_bus::schedule::types::Schedule,};+/// Code-owned system-job owner; it is never read from a job field or request.+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub(crate) enum TrustedSystemJobOwner {+ /// Memory maintenance (`memory_background` and `memory_sources_sync`).+ Memory,+}++impl TrustedSystemJobOwner {+ /// Whether this owner controls `name`.+ pub(crate) fn owns(self, name: &str) -> bool {+ match self {+ Self::Memory => name == BACKGROUND_JOB || name == SOURCES_SYNC_JOB,+ }+ }+}+/// Command prefix that marks a `flow` row as a system job.pub const SYSTEM_COMMAND_PREFIX: &str = "system:";@@ -41,6 +57,14 @@ pub fn system_job_name(job: &CronJob) -> Option<&str> {system_command_name(&job.command)}+/// The code-owned system-job owner for a stored row, if one exists.+pub(crate) fn trusted_system_job_owner(job: &CronJob) -> Option<TrustedSystemJobOwner> {+ let name = system_job_name(job)?;+ [TrustedSystemJobOwner::Memory]+ .into_iter()+ .find(|owner| owner.owns(name))+}+/// The system job a `flow` row's command names, when it names one.#[must_use]pub fn system_command_name(command: &str) -> Option<&str> {@@ -57,6 +81,31 @@ fn every(mins: u32) -> Schedule {/// Creates or reschedules system job `name` to run on `schedule`.pub fn ensure_system_job(config: &Config, name: &str, schedule: Schedule) -> Result<CronJob> {+ if crate::cron::limits::enforced(config) {+ anyhow::bail!("only the owning domain may seed system jobs under agent-only limits");+ }+ ensure_system_job_inner(config, None, name, schedule)+}++fn ensure_owned_system_job(+ config: &Config,+ owner: TrustedSystemJobOwner,+ name: &str,+ schedule: Schedule,+) -> Result<CronJob> {+ if !owner.owns(name) {+ anyhow::bail!("system job name is outside its owning domain");+ }+ crate::cron::limits::check_trusted_system_job(config, owner, name, &schedule)?;+ ensure_system_job_inner(config, Some(owner), name, schedule)+}++fn ensure_system_job_inner(+ config: &Config,+ owner: Option<TrustedSystemJobOwner>,+ name: &str,+ schedule: Schedule,+) -> Result<CronJob> {let command = format!("{SYSTEM_COMMAND_PREFIX}{name}");let existing = list_jobs(config)?.into_iter()@@ -77,7 +126,16 @@ pub fn ensure_system_job(config: &Config, name: &str, schedule: Schedule) -> Res}None => {tracing::info!(job = %name, "[cron::system_jobs] seeding");- let job = add_flow_schedule_job(config, &command, schedule)?;+ let job = match owner {+ Some(owner) if owner.owns(name) => crate::cron::client::store_blocking(+ config,+ tinyflows_bus::schedule::StoreOperation::AddFlow {+ flow_id: command,+ schedule,+ },+ )?,+ _ => add_flow_schedule_job(config, &command, schedule)?,+ };update_job(config,&job.id,@@ -94,8 +152,18 @@ pub fn ensure_system_job(config: &Config, name: &str, schedule: Schedule) -> Res/// the ones memory retired.pub fn ensure_memory_jobs(config: &Config) -> Result<()> {let background_mins = u32::try_from(BACKGROUND_INTERVAL_MINS).unwrap_or(u32::MAX);- ensure_system_job(config, BACKGROUND_JOB, every(background_mins))?;- ensure_system_job(config, SOURCES_SYNC_JOB, every(SOURCES_SYNC_INTERVAL_MINS))?;+ ensure_owned_system_job(+ config,+ TrustedSystemJobOwner::Memory,+ BACKGROUND_JOB,+ every(background_mins),+ )?;+ ensure_owned_system_job(+ config,+ TrustedSystemJobOwner::Memory,+ SOURCES_SYNC_JOB,+ every(SOURCES_SYNC_INTERVAL_MINS),+ )?;for job in list_jobs(config)? {if system_job_name(&job) == Some(RETIRED_CONTEXT_REFRESH_JOB) {tracing::info!(id = %job.id, "[cron:system] removing the retired context refresh job");