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): add cron scheduler module
Steven Enamakel16907ed0298f
diff --git a/crates/openhuman-core/src/core/runtime/subscribers.rs b/crates/openhuman-core/src/core/runtime/subscribers.rsindex 867cd6e1d3..352c99de1e 100644--- a/crates/openhuman-core/src/core/runtime/subscribers.rs+++ b/crates/openhuman-core/src/core/runtime/subscribers.rs@@ -327,7 +327,7 @@ pub(super) fn register_domain_subscribers("[event_bus] Channels subscribers (inbound + web-only proactive) SKIPPED — channels feature disabled at compile time");- // Flows trigger dispatch (issue B2): maps FlowScheduleTick /+ // Flows trigger dispatch (issue B2): maps// ComposioTriggerReceived / WebhookIncomingRequest onto enabled flows and// runs `flows::ops::flows_run`, so schedule/app-event workflows still// dispatch when no realtime channel is configured ordiff --git a/crates/openhuman-core/src/cron/README.md b/crates/openhuman-core/src/cron/README.mdindex 2800ea5ac0..5f4bbb4be1 100644--- a/crates/openhuman-core/src/cron/README.md+++ b/crates/openhuman-core/src/cron/README.md@@ -55,19 +55,23 @@ jobs, the turn's message id.### Run claims-[`ops.rs`](./ops.rs) keeps a process-wide `ACTIVE_RUNS` set. The poll loop claims each due-job through `try_acquire_run`, which returns an `ActiveRunGuard` that releases-the claim on drop (including panic and cancellation). The `cron.run` "Run Now"-RPC uses the same set and rejects a second concurrent run of one job. A job-that is already running is skipped on a tick and picked up on a later one, so-a scheduled run and a manual run never overlap.+The schedule runtime (`tinyflows_schedule::runtime`) keeps process-wide run+claims (`RunClaim`). The poll loop claims each due job, and `ops::try_acquire_run`+takes the same claim for the `cron.run` "Run Now" RPC and the run tool, so a+second concurrent run of one job is rejected. A claim releases on drop+(including panic and cancellation). A job that is already running is skipped on+a tick and picked up on a later one, so a scheduled run and a manual run never+overlap.### Executing a job-`execute_job_with_retry_for_run` (in [`scheduler/retry.rs`](./scheduler/retry.rs)) dispatches on-`JobType` and wraps all three types in `reliability.scheduler_retries` retries-with exponential backoff starting at `reliability.provider_backoff_ms` (at-least 200 ms).+The runtime's `execute_with_retry` wraps all three job types in+`reliability.scheduler_retries` retries (a job's own `policy.retries` wins) with+exponential backoff starting at `reliability.provider_backoff_ms` (at least+200 ms). `shell` and `agent` attempts go to the host `JobExecutor`+([`scheduler/executor.rs`](./scheduler/executor.rs)), which returns each+failure classified `retryable` or permanent; `flow` rows go to the+`TriggerSink` ([`scheduler/run_delivery.rs`](./scheduler/run_delivery.rs)).`shell` jobs run through `run_job_command_with_timeout`([`scheduler/shell_job.rs`](./scheduler/shell_job.rs)). Before spawning anything,@@ -113,17 +117,17 @@ the retries-exhausted error report: backend session expired, providerinsufficient credits (402), managed-backend budget exhausted (400), API keyunset, and a local LLM that is unreachable or has no model loaded.-`flow` jobs run nothing in cron. `run_flow_schedule_job` publishes an event-and returns. If the row's `command` is `system:<name>` (see system jobs below)-it publishes `DomainEvent::CronSystemJobDue`; otherwise the command is a flow-id and it publishes `DomainEvent::FlowScheduleTick { flow_id }`, which-`flows::bus::FlowTriggerSubscriber` dispatches.+`flow` jobs run nothing in cron. The runtime hands the row's `command` to the+host `TriggerSink`. If it is `system:<name>` (see system jobs below) the sink+publishes `DomainEvent::CronSystemJobDue` and awaits the registered handler;+otherwise the command is a flow id and the sink calls+`flows::bus::FlowTriggerSubscriber::dispatch_schedule_tick` directly, with no+event in between.### After the run-`persist_job_result_for_run` ([`scheduler/run_record.rs`](./scheduler/run_record.rs)) calls `deliver_run`-first, records the run with its `DeliveryStatus`, then decides the job's-future:+The runtime calls the host `RunDelivery` (`deliver_run`) first, records the+run with its `DeliveryStatus`, then decides the job's future:- A `Schedule::At` job is one-shot. If it has `delete_after_run` and succeeded,it is removed. Otherwise it is disabled and keeps its run history.@@ -261,17 +265,19 @@ so two processes sharing one database don't double-advance it.| --- | --- || [`mod.rs`](./mod.rs) | Module wiring and re-exports. Re-exports the schedule types and pure schedule functions from `tinyflows_schedule` so `cron::CronJob`, `cron::Schedule` and friends resolve here. || [`store.rs`](./store.rs) | Thin wrapper over `tinyflows_drivers::schedule::CronDocuments`. Resolves the storage (`storage::local::open_standing`), applies `cron.max_run_history` and `scheduler.max_tasks`, and forwards job CRUD, due-job queries and run history. |-| `ops.rs` | Business operations: `add_once`, `add_once_at`, `parse_human_delay`, pause/resume, `update_cron_job`, the `ACTIVE_RUNS` claim set, and the async `cron_*` RPC operations. Also re-exported as `cron::rpc`. |+| `ops.rs` | Business operations: `add_once`, `add_once_at`, pause/resume, `update_cron_job`, `try_acquire_run`, and the async `cron_*` RPC operations. Also re-exported as `cron::rpc`. || [`schemas.rs`](./schemas.rs) | Controller schemas and handlers for the `cron` namespace. |-| [`scheduler.rs`](./scheduler.rs) | `run`, `tick_once`, `process_due_jobs`, `execute_and_persist_job`. |-| `scheduler/retry.rs` | `execute_job_now` (Run Now) and the retry loop across job types. |+| [`scheduler.rs`](./scheduler.rs) | The loop: `run`, `tick_once`, the live-agent pass, `execute_job_now` (Run Now) and the health signals. The runtime itself is `tinyflows_schedule::runtime`. |+| `scheduler/host.rs` | The host's port wiring: `HostStore` over the cron documents, `JobDispatcher` (one runtime `Scheduler` per scope), the shared run claim scope. |+| `scheduler/executor.rs` | `JobExecutor`: one shell or agent attempt, failure classification, the retries-exhausted report. |+| `scheduler/run_delivery.rs` | `RunDelivery` (delivery plus completion events) and `TriggerSink` (flow schedule trigger, system jobs). || `scheduler/failure_classification.rs` | Canned user messages and the permanent-failure classifiers that halt retries. || `scheduler/shell_job.rs` | Security-gated shell execution with a timeout. |-| `scheduler/agent_run.rs` | Agent-job turns, `build_agent_for_cron_job`, and `run_flow_schedule_job`. |+| `scheduler/agent_run.rs` | Agent-job turns, and `build_agent_for_cron_job`. || `scheduler/origin_context.rs` | `build_run_prompt`: the isolated prefix or the `current` preamble plus conversation tail. || `scheduler/delivery.rs` | `deliver_run` and `deliver_job`, the mode switch, and `push_cron_alert`. || `scheduler/origin_delivery.rs` | `deliver_to_origin`, `NO_REPLY` suppression, transcript append. |-| `scheduler/run_record.rs` | Persisting a run, one-shot handling, the high-frequency warning. |+| `scheduler/run_record.rs` | The high-frequency agent-job warning. || [`origin.rs`](./origin.rs) | `JobOrigin` capture from the live turn, the approval-gate exemption, and the turn origin a run executes under. || [`job_builder.rs`](./job_builder.rs) | `create_agent_job`: origin-aware defaults and delivery validation shared by the `cron` and `schedule` tools. || [`channel_bridge.rs`](./channel_bridge.rs) | Cron's handle on the channel runtime: per-chat history and live channels, registered by `start_channels`. |@@ -337,7 +343,6 @@ Cron publishes, through [`core/bus.rs`](../core/bus.rs), these `DomainEvent` var`channels::proactive`.- `CronDeliveryRequested` (`announce` delivery), consumed by`cron::bus::CronDeliverySubscriber`.-- `FlowScheduleTick`, consumed by `flows::bus::FlowTriggerSubscriber`.- `CronSystemJobDue`, consumed by `memory::bus`.## Who calls in@@ -365,7 +370,7 @@ Cron publishes, through [`core/bus.rs`](../core/bus.rs), these `DomainEvent` varsubmodule ([`vendor/tinyflows/crates/tinyflows-schedule`](../../../../vendor/tinyflows/crates/tinyflows-schedule/) and`tinyflows-drivers`). Change them there, not in `store.rs`.- Shell sandboxing policy is `security::SecurityPolicy`. Cron only asks it.-- Flow execution is the `flows` domain. Cron only emits `FlowScheduleTick`.+- Flow execution is the `flows` domain. Cron only fires the schedule trigger through its `TriggerSink`.- Channel construction and sending belong to `channels`. Cron reaches channelsthrough events and `channel_bridge`.- Memory's background work is memory's. Cron only fires the system job.@@ -377,14 +382,14 @@ Cron publishes, through [`core/bus.rs`](../core/bus.rs), these `DomainEvent` varconsult it. Its consumers are `modules/memory_host.rs` and[`security/credentials/`](../security/credentials/).- Dispatch is non-blocking: each due job is spawned onto a `JoinSet` bounded by- `scheduler.max_concurrent` (`scheduler/dispatch.rs`), so one long job does not hold- up the poll loop. A job is claimed (`scheduler/in_flight.rs`, shared with Run Now and+ `scheduler.max_concurrent` (the runtime's `Scheduler`), so one long job does not hold+ up the poll loop. A job is claimed (`RunClaim`, shared with Run Now andthe `cron_run` tool) from dispatch until its run is persisted, and the scheduler neverdispatches a claimed job. A recurring job's `next_run` is advanced at dispatch(at-most-once per slot), then recomputed from the finish time as before.- Per-job `JobPolicy { retries, single_flight }` is a field of the job- (`CronJob::policy`, from `tinyflows-schedule`); `policy.rs` only reads and- writes it through the store. The default policy is stored as none.+ (`CronJob::policy`, from `tinyflows-schedule`), read and written through the+ job store. The default policy is stored as none.`retries: Some(0)` means exactly one attempt; with `single_flight` a slot thatcomes due mid-run is recorded as a `skipped` run, and Run Now refuses while thejob runs. Policies kept apart from the job before (the `cron_job_policies`diff --git a/crates/openhuman-core/src/cron/mod.rs b/crates/openhuman-core/src/cron/mod.rsindex 7365285d81..3da2da000a 100644--- a/crates/openhuman-core/src/cron/mod.rs+++ b/crates/openhuman-core/src/cron/mod.rs@@ -1,8 +1,8 @@-//! Scheduled-job runtime: cron/human-delay parsing, the job + run store, the-//! polling scheduler, and delivery of job output into the agent / channel-//! pipelines. Shell jobs sandbox through `security::SecurityPolicy`; agent-//! jobs build an `Agent` directly; flow jobs hand off to-//! `flows::bus::FlowTriggerSubscriber` via `DomainEvent::FlowScheduleTick`.+//! Scheduled-job host: the job + run store, the loop that drives the+//! `tinyflows-schedule` runtime, and delivery of job output into the agent /+//! channel pipelines. Shell jobs sandbox through `security::SecurityPolicy`;+//! agent jobs build an `Agent` directly; flow jobs fire the flow's schedule+//! trigger through the runtime's `TriggerSink`.//! See `README.md` for the full module map.// Host-condition policy (battery / AC / CPU) that throttles background LLMdiff --git a/crates/openhuman-core/src/flows/bus.rs b/crates/openhuman-core/src/flows/bus.rsindex a196a4d065..064aea9752 100644--- a/crates/openhuman-core/src/flows/bus.rs+++ b/crates/openhuman-core/src/flows/bus.rs@@ -3,7 +3,7 @@//!//! [`FlowTriggerSubscriber`] is the trigger → run bridge: it listens for the//! normalized events a saved flow's trigger node can bind to-//! (`DomainEvent::FlowScheduleTick`, `ComposioTriggerReceived`,+//! (`FlowTriggerSubscriber::dispatch_schedule_tick`, `ComposioTriggerReceived`,//! `WebhookIncomingRequest`), matches them against enabled flows, and spawns//! `flows::ops::flows_run` for each match. Matching helpers//! ([`extract_trigger_kind`], [`extract_trigger_config`]) are also reused bydiff --git a/crates/openhuman-core/src/flows/bus/owner.rs b/crates/openhuman-core/src/flows/bus/owner.rsindex bfc76d442c..aea3486f50 100644--- a/crates/openhuman-core/src/flows/bus/owner.rs+++ b/crates/openhuman-core/src/flows/bus/owner.rs@@ -1,5 +1,5 @@//! Which agent a flow belongs to, for the subscribers that act on a flow-//! named only by id in an event (`FlowScheduleTick`, `FlowRunFinished`).+//! named only by id (a schedule trigger, `FlowRunFinished`).//!//! A flow saved from inside an agent's context lives in that agent's storage//! scope (`crate::storage`). The subscribers run outside any agent, so theydiff --git a/crates/openhuman-core/src/flows/ops/triggers.rs b/crates/openhuman-core/src/flows/ops/triggers.rsindex 5d32f8a848..8c4a2cffdd 100644--- a/crates/openhuman-core/src/flows/ops/triggers.rs+++ b/crates/openhuman-core/src/flows/ops/triggers.rs@@ -4,7 +4,7 @@ use super::*;/// flow's automatic trigger:/// - `schedule` — registers/removes the backing `cron` job/// (`cron::add_flow_schedule_job` / `cron::remove_job`) so-/// `flows::bus::FlowTriggerSubscriber` gets a `FlowScheduleTick` on the+/// `flows::bus::FlowTriggerSubscriber` gets a schedule trigger from the/// configured cadence./// - `app_event` — no enable-time side effect needed: the subscriber matches/// every `ComposioTriggerReceived` against `store::list_enabled_flows` at