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
refactor(cron): drop per-run state from the scheduler executor
Steven Enamakel8417f9fdc177
diff --git a/crates/openhuman-core/src/cron/scheduler/executor.rs b/crates/openhuman-core/src/cron/scheduler/executor.rsindex 7036249ce4..74ca75a0ee 100644--- a/crates/openhuman-core/src/cron/scheduler/executor.rs+++ b/crates/openhuman-core/src/cron/scheduler/executor.rs@@ -16,111 +16,41 @@ use super::failure_classification::{};use crate::cron::bus_host::{kind_refusal, Binding};use crate::cron::handlers::{kind_handler, JobRunContext};-use std::collections::HashMap;-use std::sync::Mutex;use tinyflows_bus::schedule::types::{CronJob, JobType, SessionTarget};use tinyflows_bus::schedule::Attempt;-/// Run states kept before the map is cleared outright (a run whose task was-/// aborted never reaches `failed`).-const CAPACITY: usize = 1024;--/// Why a run stopped retrying, which decides what its final report says.-#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]-enum Halt {- #[default]- None,- /// Refused before running (operator limits, security policy).- Refused,- SessionExpired,- LocalUnreachable,- InsufficientCredits,- BudgetExhausted,- ApiKeyUnset,-}--/// What the executor remembers about a run across its attempts.-#[derive(Default)]-struct RunState {- last_agent_error: Option<String>,- halt: Halt,-}-pub(crate) struct HostExecutor {binding: Binding,- runs: Mutex<HashMap<String, RunState>>,}impl HostExecutor {pub(crate) fn new(binding: Binding) -> Self {- Self {- binding,- runs: Mutex::new(HashMap::new()),- }- }-- /// Registers `run_id`; `true` on its first attempt.- fn begin(&self, run_id: &str) -> bool {- let mut runs = self.runs.lock().unwrap_or_else(|e| e.into_inner());- if runs.contains_key(run_id) {- return false;- }- if runs.len() >= CAPACITY {- runs.clear();- }- runs.insert(run_id.to_string(), RunState::default());- true- }-- fn forget(&self, run_id: &str) -> Option<RunState> {- self.runs- .lock()- .unwrap_or_else(|e| e.into_inner())- .remove(run_id)- }-- /// Records the attempt's agent error and returns the latest one seen.- fn note_error(&self, run_id: &str, agent_error: Option<String>) -> Option<String> {- let mut runs = self.runs.lock().unwrap_or_else(|e| e.into_inner());- let state = runs.entry(run_id.to_string()).or_default();- if agent_error.is_some() {- state.last_agent_error = agent_error;- }- state.last_agent_error.clone()- }-- fn halt(&self, run_id: &str, halt: Halt) {- let mut runs = self.runs.lock().unwrap_or_else(|e| e.into_inner());- runs.entry(run_id.to_string()).or_default().halt = halt;+ Self { binding }}async fn attempt(&self, job: &CronJob, run_id: &str) -> Attempt {let config = self.binding.config();- if self.begin(run_id) {- warn_if_high_frequency_agent_job(&config, job).await;- self.binding.publish_triggered_once(job, run_id);- }+ self.binding.publish_triggered_once(job, run_id);// A hosted-profile sweep runs agent jobs and trusted memory jobs.if let Some(refusal) = kind_refusal(&self.binding, job) {- self.halt(run_id, Halt::Refused);return Attempt {success: false,output: refusal,retryable: false,+ raw_detail: None,};}// Operator limits (`cron::limits`) also bind rows stored before they// were switched on.if let Err(error) = crate::cron::limits::check_run(&config, job) {- self.halt(run_id, Halt::Refused);return Attempt {success: false,output: error.to_string(),retryable: false,+ raw_detail: None,};}let Some(handler) = kind_handler(&job.job_type) else {- self.halt(run_id, Halt::Refused);return Attempt {success: false,output: format!(@@ -128,6 +58,7 @@ impl HostExecutor {job.job_type.as_str()),retryable: false,+ raw_detail: None,};};tracing::debug!(@@ -145,86 +76,76 @@ impl HostExecutor {outcome.permanent,);if success {- self.forget(run_id);return Attempt {success: true,output,retryable: true,+ raw_detail: None,};}- let last_agent_error = self.note_error(run_id, agent_error);if permanent {- self.halt(run_id, Halt::Refused);return Attempt {success: false,output,retryable: false,+ raw_detail: agent_error,};}- self.classify_failure(job, run_id, output, last_agent_error.as_deref())+ Self::classify_failure(job, output, agent_error.as_deref())}/// Whether a failed attempt may be retried, and the output to record.- fn classify_failure(- &self,- job: &CronJob,- run_id: &str,- output: String,- last_agent_error: Option<&str>,- ) -> Attempt {- let permanent = |halt: Halt, output: String| {- self.halt(run_id, halt);+ fn classify_failure(job: &CronJob, output: String, agent_error: Option<&str>) -> Attempt {+ let permanent = |output: String| {Attempt {success: false,output,retryable: false,+ raw_detail: agent_error.map(str::to_string),}};if output.starts_with("blocked by security policy:") {// Deterministic policy violations are not retryable.- return permanent(Halt::Refused, output);+ return permanent(output);}let job_type = &job.job_type;- if is_session_expired_failure(job_type, last_agent_error, &output) {+ if is_session_expired_failure(job_type, agent_error, &output) {// The inference layer already published `SessionExpired`; retries// cannot recover until the user re-auths (TAURI-RUST-N).- return permanent(Halt::SessionExpired, output);+ return permanent(output);}- let config_halt = if is_insufficient_credits_failure(job_type, last_agent_error, &output) {- Some((Halt::InsufficientCredits, "insufficient_credits"))- } else if is_budget_exhausted_failure(job_type, last_agent_error, &output) {- Some((Halt::BudgetExhausted, "budget_exceeded"))- } else if is_api_key_unset_failure(job_type, last_agent_error, &output) {- Some((Halt::ApiKeyUnset, "api_key_missing"))+ let user_error_kind = if is_insufficient_credits_failure(job_type, agent_error, &output) {+ Some("insufficient_credits")+ } else if is_budget_exhausted_failure(job_type, agent_error, &output) {+ Some("budget_exceeded")+ } else if is_api_key_unset_failure(job_type, agent_error, &output) {+ Some("api_key_missing")} else {None};- if let Some((halt, user_error_kind)) = config_halt {- tracing::debug!(- job_id = %job.id,- ?halt,- "[cron:executor] permanent user-config halt; not retrying"- );+ if let Some(user_error_kind) = user_error_kind {+ tracing::debug!(job_id = %job.id, "[cron:executor] permanent user-config halt; not retrying");// The specific, actionable (static, leak-safe) copy replaces the// generic agent-failure text; the raw error chain is never shown.let message = permanent_halt_message(- halt == Halt::InsufficientCredits,- halt == Halt::BudgetExhausted,+ user_error_kind == "insufficient_credits",+ user_error_kind == "budget_exceeded",);// Also reach the UserErrorCenter so the user can fix it with no// chat thread open (metadata-only; #4165 / TAURI-RUST-HCK).publish_cron_user_error(user_error_kind);- return permanent(halt, message.to_string());+ return permanent(message.to_string());}- if is_local_provider_unreachable_failure(job_type, last_agent_error, &output) {+ if is_local_provider_unreachable_failure(job_type, agent_error, &output) {// A local LLM server refusing the loopback connection cannot// recover across the backoff loop (TAURI-RUST-12K).- return permanent(Halt::LocalUnreachable, output);+ return permanent(output);}Attempt {success: false,output,retryable: true,+ raw_detail: agent_error.map(str::to_string),}}}@@ -237,38 +158,22 @@ impl HostExecutor {/// The retries-exhausted (or permanent) report, once per failed run.pub(crate) async fn failed(&self, job: &CronJob, run_id: &str, attempt: &Attempt) {- let state = self.forget(run_id).unwrap_or_default();self.binding.finish_triggered_run(run_id);- if !matches!(job.job_type, JobType::Agent) {+ if !matches!(job.job_type, JobType::Agent) || !attempt.retryable {return;}- match state.halt {- Halt::None => {- let message = state- .last_agent_error- .as_deref()- .unwrap_or(attempt.output.as_str());- crate::core::observability::report_error(- message,- "cron",- "agent_job",- &[- ("job_id", job.id.as_str()),- ("agent_id", job.agent_id.as_deref().unwrap_or("none")),- (- "session_target",- agent_session_target_tag(&job.session_target),- ),- ("failure", "retries_exhausted"),- ],- );- }- halt => tracing::debug!(- job_id = %job.id,- ?halt,- "[cron:executor] suppressed the retries-exhausted report for a permanent halt"- ),- }+ let message = attempt.raw_detail.as_deref().unwrap_or(attempt.output.as_str());+ crate::core::observability::report_error(+ message,+ "cron",+ "agent_job",+ &[+ ("job_id", job.id.as_str()),+ ("agent_id", job.agent_id.as_deref().unwrap_or("none")),+ ("session_target", agent_session_target_tag(&job.session_target)),+ ("failure", "retries_exhausted"),+ ],+ );}}diff --git a/vendor/tinyflows b/vendor/tinyflowsindex 57086af899..98caac43b2 160000--- a/vendor/tinyflows+++ b/vendor/tinyflows@@ -1 +1 @@-Subproject commit 57086af8999979ab86afaf029c1a03f74577e1b9+Subproject commit 98caac43b202e2aefefbb9157185924aa0b291d7