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): remove legacy cron scheduling module
Steven Enamakel20a4b56ec7f9
diff --git a/crates/openhuman-core/src/cron/schedule.rs b/crates/openhuman-core/src/cron/schedule.rsdeleted file mode 100644index 89ab59589f..0000000000--- a/crates/openhuman-core/src/cron/schedule.rs+++ /dev/null@@ -1,368 +0,0 @@-use crate::cron::{ActiveHours, Schedule};-use anyhow::{Context, Result};-use chrono::{DateTime, Duration as ChronoDuration, NaiveTime, Timelike, Utc};-use cron::Schedule as CronExprSchedule;-use std::fmt;-use std::str::FromStr;--/// The closest together two runs of an *agent* job may be scheduled. Every-/// run is a full inference turn, so a tighter cadence is almost always a-/// misconfiguration that bills accordingly. Shell and flow jobs are not-/// subject to it. Enforced by [`validate_agent_schedule`] when an agent job is-/// created or its schedule changed; the scheduler warns about rows that-/// predate the rule.-pub const MIN_AGENT_JOB_INTERVAL: ChronoDuration = ChronoDuration::minutes(5);--/// Upper bound on cron candidates walked while looking for an occurrence that-/// falls inside `active_hours`. `next_run_for_schedule` gets a fresh budget-/// per call; a `runs_closer_than` scan shares one across all of its steps.-const ACTIVE_WINDOW_CANDIDATE_LIMIT: usize = 100_000;--/// How many consecutive occurrences [`runs_closer_than`] walks before it-/// concludes a cron schedule keeps its distance. Every gap an hour- or-/// day-periodic expression can produce shows up well inside this many runs-/// (a schedule that respects a 5-minute floor fires at most 288 times a day),-/// so the verdict does not depend on the instant the scan starts from.-const RUN_GAP_SCAN_OCCURRENCES: usize = 1_000;--pub fn next_run_for_schedule(schedule: &Schedule, from: DateTime<Utc>) -> Result<DateTime<Utc>> {- match schedule {- Schedule::Cron {- expr,- tz,- active_hours,- } => {- let plan = CronPlan::parse(expr, tz.as_deref(), active_hours.as_ref())?;- let mut budget = ACTIVE_WINDOW_CANDIDATE_LIMIT;- plan.next_after(from, &mut budget)- }- Schedule::At { at } => Ok(*at),- Schedule::Every { every_ms } => {- if *every_ms == 0 {- anyhow::bail!("Invalid schedule: every_ms must be > 0");- }- let ms = i64::try_from(*every_ms).context("every_ms is too large")?;- let delta = ChronoDuration::milliseconds(ms);- from.checked_add_signed(delta)- .ok_or_else(|| anyhow::anyhow!("every_ms overflowed DateTime"))- }- }-}--pub fn validate_schedule(schedule: &Schedule, now: DateTime<Utc>) -> Result<()> {- match schedule {- Schedule::Cron {- expr,- tz,- active_hours,- } => {- let _ = normalize_expression(expr)?;- if let Some(active) = active_hours {- let _ = ActiveWindow::parse(active)?;- }- let _ = ScheduleTimeZone::parse(tz.as_deref())?;- let _ = next_run_for_schedule(schedule, now)?;- Ok(())- }- Schedule::At { at } => {- if *at <= now {- anyhow::bail!("Invalid schedule: 'at' must be in the future");- }- Ok(())- }- Schedule::Every { every_ms } => {- if *every_ms == 0 {- anyhow::bail!("Invalid schedule: every_ms must be > 0");- }- Ok(())- }- }-}--/// [`validate_schedule`] plus the agent-only floor: an agent job may not run-/// closer together than [`MIN_AGENT_JOB_INTERVAL`]. The error names the two-/// runs (or the fixed interval) that break the rule, so the caller — an agent-/// using `cron_add`, or the settings form — can say exactly what to change.-pub fn validate_agent_schedule(schedule: &Schedule, now: DateTime<Utc>) -> Result<()> {- validate_schedule(schedule, now)?;- if let Some(too_frequent) = runs_closer_than(schedule, now, MIN_AGENT_JOB_INTERVAL) {- anyhow::bail!(- "Invalid schedule: agent jobs must run at least {} apart, but this schedule {too_frequent}",- describe_gap(MIN_AGENT_JOB_INTERVAL)- );- }- Ok(())-}--/// Why a schedule runs more often than a threshold allows. Carries the-/// evidence, not only the verdict, so a log line or an error can quote it.-#[derive(Debug, Clone, Copy, PartialEq, Eq)]-pub enum TooFrequent {- /// A fixed `every_ms` interval shorter than the threshold.- FixedInterval(ChronoDuration),- /// Two consecutive cron occurrences closer together than the threshold.- ConsecutiveRuns {- first: DateTime<Utc>,- second: DateTime<Utc>,- },-}--impl TooFrequent {- /// The offending gap.- pub fn gap(&self) -> ChronoDuration {- match self {- Self::FixedInterval(gap) => *gap,- Self::ConsecutiveRuns { first, second } => *second - *first,- }- }-}--impl fmt::Display for TooFrequent {- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {- match self {- Self::FixedInterval(gap) => write!(f, "fires every {}", describe_gap(*gap)),- Self::ConsecutiveRuns { first, second } => write!(- f,- "fires at {} and again at {}, {} apart",- first.format("%Y-%m-%d %H:%M:%S UTC"),- second.format("%Y-%m-%d %H:%M:%S UTC"),- describe_gap(*second - *first)- ),- }- }-}--/// The two consecutive runs of `schedule` after `from` that are closest-/// together, if that gap is under `min_gap`.-///-/// Consecutive occurrences are walked in order and the smallest gap is kept,-/// so an irregular expression such as `1,3,4,30 * * * *` is judged by its-/// :03 → :04 pair — not by the first pair under the floor (:01 → :03) and not-/// by whichever pair happens to follow `from`. The wrap-around gap counts too:-/// `*/7 * * * *` fires at :56 and then at :00, four minutes apart, and is-/// reported as such. Ties keep the earliest pair.-///-/// The walk is bounded ([`RUN_GAP_SCAN_OCCURRENCES`] runs, one shared-/// [`ACTIVE_WINDOW_CANDIDATE_LIMIT`] budget), so a sparse or window-restricted-/// expression stays cheap; if the budget runs out mid-walk, the closest pair-/// seen so far is still reported. An expression that cannot be parsed, or that-/// has no second occurrence, is not evidence of anything and yields `None`;-/// [`validate_schedule`] is where a bad expression gets rejected.-pub fn runs_closer_than(- schedule: &Schedule,- from: DateTime<Utc>,- min_gap: ChronoDuration,-) -> Option<TooFrequent> {- match schedule {- Schedule::At { .. } => None,- Schedule::Every { every_ms } => {- let gap = ChronoDuration::try_milliseconds(i64::try_from(*every_ms).ok()?)?;- (gap < min_gap).then_some(TooFrequent::FixedInterval(gap))- }- Schedule::Cron {- expr,- tz,- active_hours,- } => {- let plan = CronPlan::parse(expr, tz.as_deref(), active_hours.as_ref()).ok()?;- let mut budget = ACTIVE_WINDOW_CANDIDATE_LIMIT;- let mut previous = plan.next_after(from, &mut budget).ok()?;- let mut closest: Option<TooFrequent> = None;- for _ in 1..RUN_GAP_SCAN_OCCURRENCES {- // Running out of budget (or of occurrences) ends the walk but- // does not discard a pair already found.- let Ok(next) = plan.next_after(previous, &mut budget) else {- break;- };- let gap = next - previous;- if gap < min_gap && closest.is_none_or(|seen| gap < seen.gap()) {- closest = Some(TooFrequent::ConsecutiveRuns {- first: previous,- second: next,- });- }- previous = next;- }- closest- }- }-}--/// `4 minutes`, `30 seconds`, `1 minute 30 seconds` — whole seconds only.-fn describe_gap(gap: ChronoDuration) -> String {- fn count(n: i64, unit: &str) -> String {- if n == 1 {- format!("{n} {unit}")- } else {- format!("{n} {unit}s")- }- }- let seconds = gap.num_seconds();- match (seconds / 60, seconds % 60) {- (0, s) => count(s, "second"),- (m, 0) => count(m, "minute"),- (m, s) => format!("{} {}", count(m, "minute"), count(s, "second")),- }-}--pub fn schedule_cron_expression(schedule: &Schedule) -> Option<String> {- match schedule {- Schedule::Cron { expr, .. } => Some(expr.clone()),- _ => None,- }-}--/// A [`Schedule::Cron`] parsed once, so walking many occurrences does not pay-/// for the expression, timezone and active-window parsing on every step.-struct CronPlan<'a> {- expr: &'a str,- cron: CronExprSchedule,- timezone: ScheduleTimeZone,- active_window: Option<ActiveWindow>,-}--impl<'a> CronPlan<'a> {- fn parse(expr: &'a str, tz: Option<&str>, active_hours: Option<&ActiveHours>) -> Result<Self> {- let normalized = normalize_expression(expr)?;- let cron = CronExprSchedule::from_str(&normalized)- .with_context(|| format!("Invalid cron expression: {expr}"))?;- let timezone = ScheduleTimeZone::parse(tz)?;- let active_window = active_hours.map(ActiveWindow::parse).transpose()?;- Ok(Self {- expr,- cron,- timezone,- active_window,- })- }-- /// The first occurrence strictly after `from` that falls inside the active- /// window, spending at most `budget` cron candidates to find it.- fn next_after(&self, from: DateTime<Utc>, budget: &mut usize) -> Result<DateTime<Utc>> {- let mut current_from = from;- while *budget > 0 {- *budget -= 1;- let next_utc = self- .timezone- .next_after(&self.cron, current_from, self.expr)?;- let Some(active) = &self.active_window else {- return Ok(next_utc);- };- if active.contains(self.timezone.local_time_of_day(next_utc)) {- return Ok(next_utc);- }- tracing::debug!(- "[cron] next_run candidate {} outside active window {}–{}, advancing",- next_utc,- active.start,- active.end- );- current_from = next_utc;- }- tracing::warn!(- "[cron] no occurrence found within active_hours for expr={} after 100,000 candidates",- self.expr- );- anyhow::bail!("No future occurrence found within active hours after 100,000 attempts")- }-}--#[derive(Debug, Clone, Copy)]-enum ScheduleTimeZone {- Local,- Named(chrono_tz::Tz),-}--impl ScheduleTimeZone {- fn parse(tz: Option<&str>) -> Result<Self> {- match tz {- Some(tz_name) => chrono_tz::Tz::from_str(tz_name)- .map(Self::Named)- .with_context(|| format!("Invalid IANA timezone: {tz_name}")),- None => Ok(Self::Local),- }- }-- fn next_after(- self,- cron: &CronExprSchedule,- from: DateTime<Utc>,- expr: &str,- ) -> Result<DateTime<Utc>> {- match self {- Self::Named(timezone) => {- let localized_from = from.with_timezone(&timezone);- let next_local = cron.after(&localized_from).next().ok_or_else(|| {- anyhow::anyhow!("No future occurrence for expression: {expr}")- })?;- Ok(next_local.with_timezone(&Utc))- }- Self::Local => {- let localized_from = from.with_timezone(&chrono::Local);- let next_local = cron.after(&localized_from).next().ok_or_else(|| {- anyhow::anyhow!("No future occurrence for expression: {expr}")- })?;- Ok(next_local.with_timezone(&Utc))- }- }- }-- fn local_time_of_day(self, time: DateTime<Utc>) -> NaiveTime {- match self {- Self::Named(timezone) => {- let localized = time.with_timezone(&timezone);- NaiveTime::from_hms_opt(localized.hour(), localized.minute(), 0)- .expect("hour() and minute() from a valid DateTime are always in-range")- }- Self::Local => {- let localized = time.with_timezone(&chrono::Local);- NaiveTime::from_hms_opt(localized.hour(), localized.minute(), 0)- .expect("hour() and minute() from a valid DateTime are always in-range")- }- }- }-}--#[derive(Debug, Clone, Copy)]-struct ActiveWindow {- start: NaiveTime,- end: NaiveTime,-}--impl ActiveWindow {- fn parse(active: &ActiveHours) -> Result<Self> {- let start = NaiveTime::parse_from_str(&active.start, "%H:%M")- .with_context(|| format!("Invalid active_hours.start: {}", active.start))?;- let end = NaiveTime::parse_from_str(&active.end, "%H:%M")- .with_context(|| format!("Invalid active_hours.end: {}", active.end))?;- Ok(Self { start, end })- }-- fn contains(self, time: NaiveTime) -> bool {- if self.start <= self.end {- time >= self.start && time <= self.end- } else {- // Window spans midnight (e.g. 22:00 to 06:00).- time >= self.start || time <= self.end- }- }-}--pub fn normalize_expression(expression: &str) -> Result<String> {- let expression = expression.trim();- let field_count = expression.split_whitespace().count();-- match field_count {- // standard crontab syntax: minute hour day month weekday- 5 => Ok(format!("0 {expression}")),- // crate-native syntax includes seconds (+ optional year)- 6 | 7 => Ok(expression.to_string()),- _ => anyhow::bail!(- "Invalid cron expression: {expression} (expected 5, 6, or 7 fields, got {field_count})"- ),- }-}--#[cfg(test)]-#[path = "schedule_tests.rs"]-mod tests;diff --git a/crates/openhuman-core/src/cron/schedule_tests.rs b/crates/openhuman-core/src/cron/schedule_tests.rsdeleted file mode 100644index e1aa26c816..0000000000--- a/crates/openhuman-core/src/cron/schedule_tests.rs+++ /dev/null@@ -1,532 +0,0 @@-use super::*;-use chrono::TimeZone;--#[test]-fn next_run_for_schedule_supports_every_and_at() {- let now = Utc::now();- let every = Schedule::Every { every_ms: 60_000 };- let next = next_run_for_schedule(&every, now).unwrap();- assert!(next > now);-- let at = now + ChronoDuration::minutes(10);- let at_schedule = Schedule::At { at };- let next_at = next_run_for_schedule(&at_schedule, now).unwrap();- assert_eq!(next_at, at);-}--#[test]-fn next_run_for_schedule_supports_timezone() {- let from = Utc.with_ymd_and_hms(2026, 2, 16, 0, 0, 0).unwrap();- let schedule = Schedule::Cron {- expr: "0 9 * * *".into(),- tz: Some("America/Los_Angeles".into()),- active_hours: None,- };-- let next = next_run_for_schedule(&schedule, from).unwrap();- assert_eq!(next, Utc.with_ymd_and_hms(2026, 2, 16, 17, 0, 0).unwrap());-}--// ── normalize_expression ────────────────────────────────────────--#[test]-fn normalize_expression_accepts_standard_5_field_crontab() {- // 5 fields → seconds column prepended so `cron` crate is happy.- assert_eq!(normalize_expression("0 9 * * *").unwrap(), "0 0 9 * * *");- assert_eq!(- normalize_expression("*/5 * * * *").unwrap(),- "0 */5 * * * *"- );-}--#[test]-fn normalize_expression_accepts_6_and_7_field_crate_native() {- // 6 = second minute hour dom mon dow- assert_eq!(normalize_expression("0 0 9 * * *").unwrap(), "0 0 9 * * *");- // 7 adds year- assert_eq!(- normalize_expression("0 0 9 * * * 2027").unwrap(),- "0 0 9 * * * 2027"- );-}--#[test]-fn normalize_expression_trims_whitespace() {- assert_eq!(- normalize_expression(" 0 9 * * * ").unwrap(),- "0 0 9 * * *"- );-}--#[test]-fn normalize_expression_rejects_wrong_field_counts() {- assert!(normalize_expression("").is_err());- assert!(normalize_expression("* *").is_err());- assert!(normalize_expression("* * *").is_err());- assert!(normalize_expression("* * * *").is_err());- assert!(normalize_expression("* * * * * * * *").is_err());-}--// ── next_run_for_schedule ───────────────────────────────────────--#[test]-fn next_run_cron_without_tz_uses_local_by_default() {- // Express `from` as local midnight so the expected next-09:00 is always on the- // same calendar day, regardless of the host timezone. A UTC-fixed `from` would- // land at different local times on different machines (e.g. already 10:00 local- // on a UTC+10 host), making the expected date machine-dependent.- let from_local = chrono::Local- .with_ymd_and_hms(2026, 2, 16, 0, 0, 0)- .unwrap();- let from = from_local.with_timezone(&Utc);- let schedule = Schedule::Cron {- expr: "0 9 * * *".into(),- tz: None,- active_hours: None,- };- let next = next_run_for_schedule(&schedule, from).unwrap();-- let expected_local = chrono::Local- .with_ymd_and_hms(2026, 2, 16, 9, 0, 0)- .unwrap();- assert_eq!(next, expected_local.with_timezone(&Utc));-}--#[test]-fn next_run_rejects_invalid_cron_expression() {- let schedule = Schedule::Cron {- expr: "not a cron".into(),- tz: None,- active_hours: None,- };- let err = next_run_for_schedule(&schedule, Utc::now()).unwrap_err();- assert!(err.to_string().to_lowercase().contains("invalid"));-}--#[test]-fn next_run_rejects_invalid_timezone() {- let schedule = Schedule::Cron {- expr: "0 9 * * *".into(),- tz: Some("Not/A_Real_Tz".into()),- active_hours: None,- };- let err = next_run_for_schedule(&schedule, Utc::now()).unwrap_err();- assert!(err- .to_string()- .to_lowercase()- .contains("invalid iana timezone"));-}--#[test]-fn next_run_every_zero_is_rejected() {- let schedule = Schedule::Every { every_ms: 0 };- let err = next_run_for_schedule(&schedule, Utc::now()).unwrap_err();- assert!(err.to_string().contains("every_ms must be > 0"));-}--#[test]-fn next_run_at_returns_the_exact_time() {- let at = Utc.with_ymd_and_hms(2026, 3, 1, 12, 0, 0).unwrap();- let schedule = Schedule::At { at };- let next = next_run_for_schedule(&schedule, Utc::now()).unwrap();- assert_eq!(next, at);-}--// ── validate_schedule ───────────────────────────────────────────--#[test]-fn validate_schedule_rejects_past_at_time() {- let now = Utc::now();- let past = now - ChronoDuration::minutes(5);- let schedule = Schedule::At { at: past };- let err = validate_schedule(&schedule, now).unwrap_err();- assert!(err.to_string().contains("'at' must be in the future"));-}--#[test]-fn validate_schedule_accepts_future_at_time() {- let now = Utc::now();- let future = now + ChronoDuration::minutes(5);- let schedule = Schedule::At { at: future };- assert!(validate_schedule(&schedule, now).is_ok());-}--#[test]-fn validate_schedule_rejects_every_zero() {- let schedule = Schedule::Every { every_ms: 0 };- assert!(validate_schedule(&schedule, Utc::now()).is_err());-}--#[test]-fn validate_schedule_accepts_valid_cron() {- let now = Utc::now();- let schedule = Schedule::Cron {- expr: "*/5 * * * *".into(),- tz: None,- active_hours: None,- };- assert!(validate_schedule(&schedule, now).is_ok());-}--#[test]-fn validate_schedule_rejects_garbage_cron_expression() {- let schedule = Schedule::Cron {- expr: "not a cron".into(),- tz: None,- active_hours: None,- };- assert!(validate_schedule(&schedule, Utc::now()).is_err());-}--// ── schedule_cron_expression ────────────────────────────────────--#[test]-fn schedule_cron_expression_returns_expr_for_cron_variant() {- let s = Schedule::Cron {- expr: "0 9 * * *".into(),- tz: Some("UTC".into()),- active_hours: None,- };- assert_eq!(schedule_cron_expression(&s).as_deref(), Some("0 9 * * *"));-}--#[test]-fn schedule_cron_expression_returns_none_for_non_cron_variants() {- assert!(schedule_cron_expression(&Schedule::Every { every_ms: 1000 }).is_none());- assert!(schedule_cron_expression(&Schedule::At { at: Utc::now() }).is_none());-}--#[test]-fn next_run_respects_active_hours() {- // Schedule: every minute- // Active hours: 09:00 - 09:05- let schedule = Schedule::Cron {- expr: "* * * * *".into(),- tz: Some("UTC".into()),- active_hours: Some(ActiveHours {- start: "09:00".into(),- end: "09:05".into(),- }),- };-- // If it's 08:00, next run should be 09:00- let from = Utc.with_ymd_and_hms(2026, 2, 16, 8, 0, 0).unwrap();- let next = next_run_for_schedule(&schedule, from).unwrap();- assert_eq!(next, Utc.with_ymd_and_hms(2026, 2, 16, 9, 0, 0).unwrap());-- // If it's 09:02, next run should be 09:03- let from = Utc.with_ymd_and_hms(2026, 2, 16, 9, 2, 0).unwrap();- let next = next_run_for_schedule(&schedule, from).unwrap();- assert_eq!(next, Utc.with_ymd_and_hms(2026, 2, 16, 9, 3, 0).unwrap());-- // If it's 09:05, next run should be 09:00 NEXT DAY- let from = Utc.with_ymd_and_hms(2026, 2, 16, 9, 5, 0).unwrap();- let next = next_run_for_schedule(&schedule, from).unwrap();- assert_eq!(next, Utc.with_ymd_and_hms(2026, 2, 17, 9, 0, 0).unwrap());-}--#[test]-fn next_run_respects_active_hours_spanning_midnight() {- // Active hours: 22:00 - 02:00- let schedule = Schedule::Cron {- expr: "0 * * * *".into(), // every hour- tz: Some("UTC".into()),- active_hours: Some(ActiveHours {- start: "22:00".into(),- end: "02:00".into(),- }),- };-- // 20:00 -> 22:00- let from = Utc.with_ymd_and_hms(2026, 2, 16, 20, 0, 0).unwrap();- let next = next_run_for_schedule(&schedule, from).unwrap();- assert_eq!(next, Utc.with_ymd_and_hms(2026, 2, 16, 22, 0, 0).unwrap());-- // 23:00 -> 00:00- let from = Utc.with_ymd_and_hms(2026, 2, 16, 23, 0, 0).unwrap();- let next = next_run_for_schedule(&schedule, from).unwrap();- assert_eq!(next, Utc.with_ymd_and_hms(2026, 2, 17, 0, 0, 0).unwrap());-- // 01:00 -> 02:00- let from = Utc.with_ymd_and_hms(2026, 2, 17, 1, 0, 0).unwrap();- let next = next_run_for_schedule(&schedule, from).unwrap();- assert_eq!(next, Utc.with_ymd_and_hms(2026, 2, 17, 2, 0, 0).unwrap());-- // 03:00 -> 22:00 SAME DAY (since it's early morning)- let from = Utc.with_ymd_and_hms(2026, 2, 17, 3, 0, 0).unwrap();- let next = next_run_for_schedule(&schedule, from).unwrap();- assert_eq!(next, Utc.with_ymd_and_hms(2026, 2, 17, 22, 0, 0).unwrap());-}--#[test]-fn next_run_respects_active_hours_in_schedule_timezone() {- let schedule = Schedule::Cron {- expr: "0 * * * *".into(),- tz: Some("America/Los_Angeles".into()),- active_hours: Some(ActiveHours {- start: "09:00".into(),- end: "10:00".into(),- }),- };-- let from = Utc.with_ymd_and_hms(2026, 2, 16, 15, 30, 0).unwrap();- let next = next_run_for_schedule(&schedule, from).unwrap();-- assert_eq!(next, Utc.with_ymd_and_hms(2026, 2, 16, 17, 0, 0).unwrap());-}--#[test]-fn validate_schedule_rejects_invalid_active_hours() {- let now = Utc::now();- let schedule = Schedule::Cron {- expr: "* * * * *".into(),- tz: None,- active_hours: Some(ActiveHours {- start: "invalid".into(),- end: "09:00".into(),- }),- };- assert!(validate_schedule(&schedule, now).is_err());-}--#[test]-fn validate_schedule_rejects_invalid_active_hours_end() {- let now = Utc::now();- let schedule = Schedule::Cron {- expr: "* * * * *".into(),- tz: Some("UTC".into()),- active_hours: Some(ActiveHours {- start: "09:00".into(),- end: "24:00".into(),- }),- };- let err = validate_schedule(&schedule, now).unwrap_err();- assert!(err.to_string().contains("active_hours.end"));-}--// ── runs_closer_than / validate_agent_schedule (#6158) ──────────--fn utc_cron(expr: &str) -> Schedule {- Schedule::Cron {- expr: expr.into(),- tz: Some("UTC".into()),- active_hours: None,- }-}--#[test]-fn runs_closer_than_reports_the_shortest_gap_of_an_irregular_expression() {- // From :03 the pair that follows is :30 → 1:01 — 31 minutes apart, which- // is what a "the pair after now" check would have judged the schedule by.- // The :01 → :02 pair one minute apart is what counts.- let from = Utc.with_ymd_and_hms(2026, 3, 2, 10, 3, 0).unwrap();- let hit = runs_closer_than(&utc_cron("1,2,30 * * * *"), from, MIN_AGENT_JOB_INTERVAL)- .expect("the one-minute gap must be found");- assert_eq!(- hit,- TooFrequent::ConsecutiveRuns {- first: Utc.with_ymd_and_hms(2026, 3, 2, 11, 1, 0).unwrap(),- second: Utc.with_ymd_and_hms(2026, 3, 2, 11, 2, 0).unwrap(),- }- );- assert_eq!(hit.gap(), ChronoDuration::minutes(1));-}--#[test]-fn runs_closer_than_does_not_depend_on_the_instant_it_starts_from() {- for minute in [0, 1, 2, 3, 15, 29, 30, 31, 59] {- let from = Utc.with_ymd_and_hms(2026, 3, 2, 10, minute, 0).unwrap();- for expr in ["1,2,30 * * * *", "0,1 * * * *", "0,3 9 * * *"] {- assert!(- runs_closer_than(&utc_cron(expr), from, MIN_AGENT_JOB_INTERVAL).is_some(),- "{expr} from :{minute:02}"- );- }- for expr in ["*/10 * * * *", "0 * * * *", "0,30 9 * * *"] {- assert!(- runs_closer_than(&utc_cron(expr), from, MIN_AGENT_JOB_INTERVAL).is_none(),- "{expr} from :{minute:02}"- );- }- }-}--/// The closest pair is reported, not the first one under the floor: `1,3,4,30`-/// has :01 → :03 (2 min) before :03 → :04 (1 min), and the message must name-/// the latter. Ties keep the earliest pair.-#[test]-fn runs_closer_than_reports_the_closest_pair_not_the_first_one_under_the_floor() {- let from = Utc.with_ymd_and_hms(2026, 3, 2, 10, 0, 0).unwrap();- let hit =- runs_closer_than(&utc_cron("1,3,4,30 * * * *"), from, MIN_AGENT_JOB_INTERVAL).unwrap();- assert_eq!(- hit,- TooFrequent::ConsecutiveRuns {- first: Utc.with_ymd_and_hms(2026, 3, 2, 10, 3, 0).unwrap(),- second: Utc.with_ymd_and_hms(2026, 3, 2, 10, 4, 0).unwrap(),- }- );- // All gaps equal: the earliest pair wins.- let hit = runs_closer_than(&utc_cron("*/2 * * * *"), from, MIN_AGENT_JOB_INTERVAL).unwrap();- assert_eq!(- hit,- TooFrequent::ConsecutiveRuns {- first: Utc.with_ymd_and_hms(2026, 3, 2, 10, 2, 0).unwrap(),- second: Utc.with_ymd_and_hms(2026, 3, 2, 10, 4, 0).unwrap(),- }- );-}--/// `*/7` is 0,7,…,56: the :56 → :00 step is four minutes, and it counts.-#[test]-fn runs_closer_than_counts_the_wrap_around_gap() {- let from = Utc.with_ymd_and_hms(2026, 3, 2, 10, 0, 0).unwrap();- let hit = runs_closer_than(&utc_cron("*/7 * * * *"), from, MIN_AGENT_JOB_INTERVAL).unwrap();- assert_eq!(hit.gap(), ChronoDuration::minutes(4));- assert_eq!(- hit.to_string(),- "fires at 2026-03-02 10:56:00 UTC and again at 2026-03-02 11:00:00 UTC, 4 minutes apart"- );-}--#[test]-fn runs_closer_than_is_quiet_at_and_above_the_threshold() {- let from = Utc.with_ymd_and_hms(2026, 3, 2, 10, 0, 0).unwrap();- for expr in [- "*/5 * * * *",- "*/6 * * * *",- "0 * * * *",- "0 9 * * *",- "0 9 * * 1",- "0 0 1 1 *",- "0 */5 * * * *",- ] {- assert!(- runs_closer_than(&utc_cron(expr), from, MIN_AGENT_JOB_INTERVAL).is_none(),- "{expr}"- );- }- let every_five = Schedule::Every { every_ms: 300_000 };- assert!(runs_closer_than(&every_five, from, MIN_AGENT_JOB_INTERVAL).is_none());- let once = Schedule::At { at: from };- assert!(runs_closer_than(&once, from, MIN_AGENT_JOB_INTERVAL).is_none());-}--#[test]-fn runs_closer_than_reports_a_fixed_interval() {- let from = Utc::now();- let hit = runs_closer_than(- &Schedule::Every { every_ms: 90_000 },- from,- MIN_AGENT_JOB_INTERVAL,- )- .unwrap();- assert_eq!(hit, TooFrequent::FixedInterval(ChronoDuration::seconds(90)));- assert_eq!(hit.to_string(), "fires every 1 minute 30 seconds");- let just_under = Schedule::Every { every_ms: 299_999 };- assert!(runs_closer_than(&just_under, from, MIN_AGENT_JOB_INTERVAL).is_some());-}--#[test]-fn runs_closer_than_sees_seconds_level_expressions() {- let from = Utc.with_ymd_and_hms(2026, 3, 2, 10, 0, 0).unwrap();- let hit = runs_closer_than(&utc_cron("*/30 * * * * *"), from, MIN_AGENT_JOB_INTERVAL).unwrap();- assert_eq!(hit.gap(), ChronoDuration::seconds(30));-}--#[test]-fn runs_closer_than_judges_the_effective_cadence_inside_the_active_window() {- let from = Utc.with_ymd_and_hms(2026, 3, 2, 10, 0, 0).unwrap();- let every_minute_during = |start: &str, end: &str| Schedule::Cron {- expr: "* * * * *".into(),- tz: Some("UTC".into()),- active_hours: Some(ActiveHours {- start: start.into(),- end: end.into(),- }),- };- // Every minute, but only during one minute of the day: effectively daily.- let daily = every_minute_during("09:00", "09:00");- assert!(runs_closer_than(&daily, from, MIN_AGENT_JOB_INTERVAL).is_none());- // A two-minute window lets two adjacent runs through. Skipping ~1,438- // out-of-window candidates per day exhausts the shared budget long before- // the 1,000-run walk ends; the pair found before that is still reported.- let hit = runs_closer_than(- &every_minute_during("09:00", "09:01"),- from,- MIN_AGENT_JOB_INTERVAL,- )- .unwrap();- assert_eq!(hit.gap(), ChronoDuration::minutes(1));-}--#[test]-fn runs_closer_than_treats_an_unreadable_expression_as_no_evidence() {- let from = Utc::now();- assert!(runs_closer_than(&utc_cron("not a cron"), from, MIN_AGENT_JOB_INTERVAL).is_none());- let bad_tz = Schedule::Cron {- expr: "* * * * *".into(),- tz: Some("Mars/Olympus_Mons".into()),- active_hours: None,- };- assert!(runs_closer_than(&bad_tz, from, MIN_AGENT_JOB_INTERVAL).is_none());-}--#[test]-fn validate_agent_schedule_rejects_tight_schedules_and_names_the_evidence() {- let now = Utc.with_ymd_and_hms(2026, 3, 2, 10, 0, 0).unwrap();- let err = validate_agent_schedule(&utc_cron("*/3 * * * *"), now)- .unwrap_err()- .to_string();- assert_eq!(- err,- "Invalid schedule: agent jobs must run at least 5 minutes apart, but this schedule \- fires at 2026-03-02 10:03:00 UTC and again at 2026-03-02 10:06:00 UTC, 3 minutes apart"- );- let err = validate_agent_schedule(&Schedule::Every { every_ms: 60_000 }, now)- .unwrap_err()- .to_string();- assert_eq!(- err,- "Invalid schedule: agent jobs must run at least 5 minutes apart, but this schedule \- fires every 1 minute"- );-}--#[test]-fn validate_agent_schedule_accepts_the_floor_and_keeps_the_generic_checks() {- let now = Utc::now();- assert!(validate_agent_schedule(&utc_cron("*/5 * * * *"), now).is_ok());- assert!(validate_agent_schedule(&Schedule::Every { every_ms: 300_000 }, now).is_ok());- let soon = Schedule::At {- at: now + ChronoDuration::minutes(1),- };- assert!(validate_agent_schedule(&soon, now).is_ok());-- // The generic validation runs first: a broken schedule is rejected as- // broken, not as "too frequent".- let err = validate_agent_schedule(&utc_cron("not a cron"), now)- .unwrap_err()- .to_string();- assert!(err.contains("Invalid cron expression"), "{err}");- let err = validate_agent_schedule(&Schedule::Every { every_ms: 0 }, now)- .unwrap_err()- .to_string();- assert!(err.contains("every_ms must be > 0"), "{err}");- let err = validate_agent_schedule(&Schedule::At { at: now }, now)- .unwrap_err()- .to_string();- assert!(err.contains("'at' must be in the future"), "{err}");-}--#[test]-fn describe_gap_reads_naturally() {- assert_eq!(describe_gap(ChronoDuration::seconds(1)), "1 second");- assert_eq!(describe_gap(ChronoDuration::seconds(30)), "30 seconds");- assert_eq!(describe_gap(ChronoDuration::minutes(1)), "1 minute");- assert_eq!(describe_gap(ChronoDuration::minutes(5)), "5 minutes");- assert_eq!(- describe_gap(ChronoDuration::seconds(90)),- "1 minute 30 seconds"- );-}diff --git a/crates/openhuman-core/src/cron/types.rs b/crates/openhuman-core/src/cron/types.rsdeleted file mode 100644index 3470eccd7f..0000000000--- a/crates/openhuman-core/src/cron/types.rs+++ /dev/null@@ -1,301 +0,0 @@-use chrono::{DateTime, Utc};-use serde::{Deserialize, Deserializer, Serialize};--#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]-#[serde(rename_all = "lowercase")]-pub enum JobType {- #[default]- Shell,- Agent,- /// A `flows::Flow` schedule trigger binding (issue B2). The job's- /// `command` column carries the bound flow's id (there is no shell- /// command / agent prompt to run); on fire the scheduler publishes- /// `DomainEvent::FlowScheduleTick { flow_id }` instead of running- /// anything itself — `flows::bus::FlowTriggerSubscriber` does the actual- /// dispatch. Created by `flows::ops::flows_set_enabled` (via- /// `cron::add_flow_schedule_job`), never via the `cron_add` agent tool.- Flow,-}--impl JobType {- pub(crate) fn as_str(&self) -> &'static str {- match self {- Self::Shell => "shell",- Self::Agent => "agent",- Self::Flow => "flow",- }- }-- pub(crate) fn parse(raw: &str) -> Self {- if raw.eq_ignore_ascii_case("agent") {- Self::Agent- } else if raw.eq_ignore_ascii_case("flow") {- Self::Flow- } else {- Self::Shell- }- }-}--#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]-#[serde(rename_all = "lowercase")]-pub enum SessionTarget {- #[default]- Isolated,- Main,-}--impl SessionTarget {- pub(crate) fn as_str(&self) -> &'static str {- match self {- Self::Isolated => "isolated",- Self::Main => "main",- }- }-- pub(crate) fn parse(raw: &str) -> Self {- if raw.eq_ignore_ascii_case("main") {- Self::Main- } else {- Self::Isolated- }- }-}--#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]-pub struct ActiveHours {- pub start: String,- pub end: String,-}--/// A cron-job schedule.-///-/// Serializes as an internally-tagged object (`{"kind": "cron", ...}`).-/// Deserializes from **either** that object form **or** a bare cron-expression-/// string like `"0 9 * * 1"` — the bare-string form is treated as-/// `Schedule::Cron { expr, tz: None, active_hours: None }`.-///-/// The bare-string shorthand exists because agents and some older frontend-/// callers pass `schedule: "0 9 * * 1"` directly instead of the structured-/// object. Accepting it here prevents Sentry issue CORE-RUST-FY-/// ("invalid type: string, expected internally tagged enum Schedule").-#[derive(Debug, Clone, Serialize, PartialEq, Eq)]-#[serde(tag = "kind", rename_all = "lowercase")]-pub enum Schedule {- Cron {- expr: String,- #[serde(default)]- tz: Option<String>,- #[serde(default)]- active_hours: Option<ActiveHours>,- },- At {- at: DateTime<Utc>,- },- Every {- every_ms: u64,- },-}--impl<'de> Deserialize<'de> for Schedule {- fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {- use serde::de::{self, MapAccess, Visitor};- use std::fmt;-- struct ScheduleVisitor;-- impl<'de> Visitor<'de> for ScheduleVisitor {- type Value = Schedule;-- fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {- write!(- f,- "a cron-schedule object ({{\"kind\":\"cron\",\"expr\":\"...\"}}) \- or a bare cron-expression string"- )- }-- /// Accept a bare string as `Schedule::Cron { expr, .. }`.- /// This handles callers that send `schedule: "0 9 * * 1"` directly- /// instead of the structured form.- fn visit_str<E: de::Error>(self, value: &str) -> Result<Self::Value, E> {- tracing::debug!(- "[cron] Schedule::deserialize: got bare string '{}', \- coercing to Cron variant",- value- );- Ok(Schedule::Cron {- expr: value.to_owned(),- tz: None,- active_hours: None,- })- }-- fn visit_string<E: de::Error>(self, value: String) -> Result<Self::Value, E> {- tracing::debug!(- "[cron] Schedule::deserialize: got bare string '{}', \- coercing to Cron variant",- value- );- Ok(Schedule::Cron {- expr: value,- tz: None,- active_hours: None,- })- }-- /// Accept the standard internally-tagged object form.- fn visit_map<A: MapAccess<'de>>(self, map: A) -> Result<Self::Value, A::Error> {- // Delegate to the serde-derived tagged-enum logic by- // deserializing from a collected map value.- #[derive(Deserialize)]- #[serde(tag = "kind", rename_all = "lowercase")]- enum ScheduleTagged {- Cron {- expr: String,- #[serde(default)]- tz: Option<String>,- #[serde(default)]- active_hours: Option<ActiveHours>,- },- At {- at: DateTime<Utc>,- },- Every {- every_ms: u64,- },- }-- let tagged =- ScheduleTagged::deserialize(de::value::MapAccessDeserializer::new(map))?;- Ok(match tagged {- ScheduleTagged::Cron {- expr,- tz,- active_hours,- } => Schedule::Cron {- expr,- tz,- active_hours,- },- ScheduleTagged::At { at } => Schedule::At { at },- ScheduleTagged::Every { every_ms } => Schedule::Every { every_ms },- })- }- }-- deserializer.deserialize_any(ScheduleVisitor)- }-}--#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]-pub struct DeliveryConfig {- #[serde(default)]- pub mode: String,- #[serde(default)]- pub channel: Option<String>,- #[serde(default)]- pub to: Option<String>,- #[serde(default = "default_true")]- pub best_effort: bool,-}--impl Default for DeliveryConfig {- fn default() -> Self {- Self {- mode: "none".to_string(),- channel: None,- to: None,- best_effort: true,- }- }-}--fn default_true() -> bool {- true-}--#[derive(Debug, Clone, Serialize, Deserialize)]-pub struct CronJob {- pub id: String,- pub expression: String,- pub schedule: Schedule,- pub command: String,- pub prompt: Option<String>,- pub name: Option<String>,- pub job_type: JobType,- pub session_target: SessionTarget,- pub model: Option<String>,- /// Optional built-in agent definition ID (e.g. `"welcome"`,- /// `"morning_briefing"`). When set, [`crate::cron::scheduler`]- /// resolves the agent definition from the registry and runs with the- /// definition's prompt, tool allowlist, iteration cap, and model hint- /// instead of the generic `OpenHumanSessionHost::from_config` path.- pub agent_id: Option<String>,- pub enabled: bool,- pub delivery: DeliveryConfig,- pub delete_after_run: bool,- pub created_at: DateTime<Utc>,- pub next_run: DateTime<Utc>,- pub last_run: Option<DateTime<Utc>>,- pub last_status: Option<String>,- pub last_output: Option<String>,-}--#[derive(Debug, Clone, Serialize, Deserialize)]-pub struct CronRun {- pub id: i64,- pub job_id: String,- pub started_at: DateTime<Utc>,- pub finished_at: DateTime<Utc>,- pub status: String,- pub output: Option<String>,- pub duration_ms: Option<i64>,-}--/// Deserialize a nullable patch field with true double-option semantics:-///-/// | wire | result | meaning |-/// | --------------- | ------------- | ------------- |-/// | key absent | `None` | no change |-/// | key present `null` | `Some(None)` | clear the value |-/// | key present value | `Some(Some(v))` | set the value |-///-/// A plain `#[derive(Deserialize)]` on `Option<Option<T>>` collapses the absent-/// and the `null` cases *both* to the outer `None`, so "clear over the wire"-/// (for example, `{"agent_id": null}`) silently deserializes as "no change" — a no-op. Used-/// with `#[serde(default, deserialize_with = "deserialize_double_option")]`,-/// this helper restores the distinction: serde only invokes it when the key is-/// *present*, so a present `null` becomes `Some(None)` and a present value-/// becomes `Some(Some(v))`, while an absent key falls back to the `default`-/// (`None`).-fn deserialize_double_option<'de, D, T>(deserializer: D) -> Result<Option<Option<T>>, D::Error>-where- D: Deserializer<'de>,- T: Deserialize<'de>,-{- Ok(Some(Option::<T>::deserialize(deserializer)?))-}--#[derive(Debug, Clone, Default, Serialize, Deserialize)]-pub struct CronJobPatch {- pub schedule: Option<Schedule>,- pub command: Option<String>,- pub prompt: Option<String>,- pub name: Option<String>,- pub enabled: Option<bool>,- pub delivery: Option<DeliveryConfig>,- pub model: Option<String>,- pub session_target: Option<SessionTarget>,- pub delete_after_run: Option<bool>,- /// `Option<Option<String>>` distinguishes "no change" (`None`) from- /// "clear the agent definition" (`Some(None)`). See- /// [`deserialize_double_option`] for why the custom deserializer is required- /// to honor a wire `null` as a clear rather than a silent no-op.- #[serde(default, deserialize_with = "deserialize_double_option")]- pub agent_id: Option<Option<String>>,-}--#[cfg(test)]-#[path = "types_tests.rs"]-mod tests;diff --git a/crates/openhuman-core/src/cron/types_tests.rs b/crates/openhuman-core/src/cron/types_tests.rsdeleted file mode 100644index a8bda0f2a9..0000000000--- a/crates/openhuman-core/src/cron/types_tests.rs+++ /dev/null@@ -1,265 +0,0 @@-use super::*;-use chrono::TimeZone;-use serde_json::json;--// ── JobType ────────────────────────────────────────────────────--#[test]-fn job_type_parse_and_as_str_roundtrip() {- assert_eq!(JobType::parse("shell").as_str(), "shell");- assert_eq!(JobType::parse("agent").as_str(), "agent");- assert_eq!(JobType::parse("flow").as_str(), "flow");- // Case-insensitive- assert_eq!(JobType::parse("AGENT"), JobType::Agent);- assert_eq!(JobType::parse("Agent"), JobType::Agent);- assert_eq!(JobType::parse("FLOW"), JobType::Flow);- // Anything unknown falls back to Shell (the default) — guards- // against unexpected legacy DB rows silently turning into Agent.- assert_eq!(JobType::parse(""), JobType::Shell);- assert_eq!(JobType::parse("garbage"), JobType::Shell);-}--#[test]-fn job_type_default_is_shell() {- assert_eq!(JobType::default(), JobType::Shell);-}--#[test]-fn job_type_serializes_lowercase() {- assert_eq!(serde_json::to_string(&JobType::Shell).unwrap(), "\"shell\"");- assert_eq!(serde_json::to_string(&JobType::Agent).unwrap(), "\"agent\"");-}--// ── SessionTarget ──────────────────────────────────────────────--#[test]-fn session_target_parse_and_as_str_roundtrip() {- assert_eq!(SessionTarget::parse("isolated").as_str(), "isolated");- assert_eq!(SessionTarget::parse("main").as_str(), "main");- // Case-insensitive + unknown falls back to Isolated (the default).- assert_eq!(SessionTarget::parse("MAIN"), SessionTarget::Main);- assert_eq!(SessionTarget::parse(""), SessionTarget::Isolated);- assert_eq!(SessionTarget::parse("unknown"), SessionTarget::Isolated);-}--#[test]-fn session_target_default_is_isolated() {- assert_eq!(SessionTarget::default(), SessionTarget::Isolated);-}--#[test]-fn session_target_serializes_lowercase() {- assert_eq!(- serde_json::to_string(&SessionTarget::Isolated).unwrap(),- "\"isolated\""- );- assert_eq!(- serde_json::to_string(&SessionTarget::Main).unwrap(),- "\"main\""- );-}--// ── Schedule ───────────────────────────────────────────────────--#[test]-fn schedule_cron_variant_roundtrips_with_optional_tz() {- let s = Schedule::Cron {- expr: "0 9 * * *".into(),- tz: Some("America/Los_Angeles".into()),- active_hours: None,- };- let v = serde_json::to_value(&s).unwrap();- assert_eq!(v["kind"], "cron");- assert_eq!(v["expr"], "0 9 * * *");- assert_eq!(v["tz"], "America/Los_Angeles");- let back: Schedule = serde_json::from_value(v).unwrap();- assert_eq!(back, s);-}--#[test]-fn schedule_cron_variant_accepts_missing_tz() {- let raw = json!({ "kind": "cron", "expr": "*/5 * * * *" });- let s: Schedule = serde_json::from_value(raw).unwrap();- assert_eq!(- s,- Schedule::Cron {- expr: "*/5 * * * *".into(),- tz: None,- active_hours: None,- }- );-}--#[test]-fn schedule_cron_variant_roundtrips_with_active_hours() {- let s = Schedule::Cron {- expr: "*/15 * * * *".into(),- tz: Some("UTC".into()),- active_hours: Some(ActiveHours {- start: "09:00".into(),- end: "17:30".into(),- }),- };- let v = serde_json::to_value(&s).unwrap();- assert_eq!(v["active_hours"]["start"], "09:00");- assert_eq!(v["active_hours"]["end"], "17:30");- let back: Schedule = serde_json::from_value(v).unwrap();- assert_eq!(back, s);-}--#[test]-fn schedule_at_variant_roundtrips_with_utc_timestamp() {- let at = Utc.with_ymd_and_hms(2027, 1, 15, 12, 0, 0).unwrap();- let s = Schedule::At { at };- let v = serde_json::to_value(&s).unwrap();- assert_eq!(v["kind"], "at");- let back: Schedule = serde_json::from_value(v).unwrap();- assert_eq!(back, s);-}--#[test]-fn schedule_every_variant_roundtrips() {- let s = Schedule::Every { every_ms: 60_000 };- let v = serde_json::to_value(&s).unwrap();- assert_eq!(v["kind"], "every");- assert_eq!(v["every_ms"], 60_000);- let back: Schedule = serde_json::from_value(v).unwrap();- assert_eq!(back, s);-}--// ── Schedule bare-string deserialization (CORE-RUST-FY fix) ──────-// Callers (agents, older frontend) sometimes pass a bare cron-// expression string like `"0 9 * * 1"` instead of the structured-// `{"kind":"cron","expr":"0 9 * * 1"}` form. Both must parse.--#[test]-fn schedule_deserializes_bare_cron_string() {- let s: Schedule = serde_json::from_value(json!("0 9 * * 1")).unwrap();- assert_eq!(- s,- Schedule::Cron {- expr: "0 9 * * 1".into(),- tz: None,- active_hours: None,- }- );-}--#[test]-fn schedule_deserializes_bare_5_field_cron_string() {- let s: Schedule = serde_json::from_str("\"*/5 * * * *\"").unwrap();- assert_eq!(- s,- Schedule::Cron {- expr: "*/5 * * * *".into(),- tz: None,- active_hours: None,- }- );-}--#[test]-fn cron_job_patch_accepts_bare_schedule_string() {- // This is the exact payload shape that triggered CORE-RUST-FY:- // {"schedule": "0 9 * * 1"}- let raw = json!({ "schedule": "0 9 * * 1" });- let patch: CronJobPatch = serde_json::from_value(raw).unwrap();- assert_eq!(- patch.schedule,- Some(Schedule::Cron {- expr: "0 9 * * 1".into(),- tz: None,- active_hours: None,- })- );-}--#[test]-fn cron_job_patch_still_accepts_structured_schedule_object() {- let raw = json!({ "schedule": { "kind": "cron", "expr": "0 9 * * 1" } });- let patch: CronJobPatch = serde_json::from_value(raw).unwrap();- assert_eq!(- patch.schedule,- Some(Schedule::Cron {- expr: "0 9 * * 1".into(),- tz: None,- active_hours: None,- })- );-}--// ── DeliveryConfig ─────────────────────────────────────────────--#[test]-fn delivery_config_default_is_none_mode_best_effort() {- let d = DeliveryConfig::default();- assert_eq!(d.mode, "none");- assert!(d.channel.is_none());- assert!(d.to.is_none());- assert!(d.best_effort, "default best_effort must be true");-}--#[test]-fn delivery_config_parses_empty_object_with_defaults() {- // A bare `{}` must deserialize with the `#[serde(default)]` / default- // fn fallbacks — otherwise legacy rows without delivery fields would- // fail to load.- let d: DeliveryConfig = serde_json::from_str("{}").unwrap();- assert_eq!(d.mode, "");- assert!(d.channel.is_none());- assert!(d.to.is_none());- assert!(d.best_effort, "best_effort must default to true");-}--#[test]-fn delivery_config_preserves_best_effort_false_override() {- let raw = json!({ "mode": "channel", "best_effort": false });- let d: DeliveryConfig = serde_json::from_value(raw).unwrap();- assert_eq!(d.mode, "channel");- assert!(!d.best_effort);-}--// ── CronJobPatch ───────────────────────────────────────────────--#[test]-fn cron_job_patch_default_is_all_none() {- let p = CronJobPatch::default();- assert!(p.schedule.is_none());- assert!(p.command.is_none());- assert!(p.prompt.is_none());- assert!(p.name.is_none());- assert!(p.enabled.is_none());- assert!(p.delivery.is_none());- assert!(p.model.is_none());- assert!(p.session_target.is_none());- assert!(p.delete_after_run.is_none());- assert!(p.agent_id.is_none());-}--#[test]-fn patch_agent_id_wire_double_option_semantics() {- // Same fix applied consistently to `agent_id` (its doc + the struct-level- // clearing test already document the Some(None)=clear intent).- let absent: CronJobPatch = serde_json::from_value(json!({})).unwrap();- assert_eq!(absent.agent_id, None, "absent key means no change");- let cleared: CronJobPatch = serde_json::from_value(json!({ "agent_id": null })).unwrap();- assert_eq!(- cleared.agent_id,- Some(None),- "wire null must clear the agent definition"- );- let set: CronJobPatch = serde_json::from_value(json!({ "agent_id": "welcome" })).unwrap();- assert_eq!(set.agent_id, Some(Some("welcome".to_string())));-}--#[test]-fn cron_job_patch_agent_id_supports_explicit_none_clearing() {- // Option<Option<String>> lets callers distinguish "no change"- // (None) from "clear the agent_id" (Some(None)).- let p = CronJobPatch {- agent_id: Some(None),- ..Default::default()- };- assert!(p.agent_id.is_some());- assert!(p.agent_id.as_ref().unwrap().is_none());-}diff --git a/vendor/tinyflows b/vendor/tinyflowsindex 2d7a73b3ac..5aca914b93 160000--- a/vendor/tinyflows+++ b/vendor/tinyflows@@ -1 +1 @@-Subproject commit 2d7a73b3ac97faa8150b79cd1ee6812797e9b4a5+Subproject commit 5aca914b937034c068c3a9c5c24d4cec17e1d267