Skip to main content

Module cron

Module cron 

Source
Expand description

Persistent cron scheduler for AgentMux.

Backs each enabled CronJob with a tokio task that sleeps until the next scheduled fire time (its trigger’s next slot, schedule: a cron expression in the job’s time zone, an interval or one time), plus the job’s fixed jitter, delivers the prompt as /agentmux/reactive/inject would — in process since identity M4c-3 (see FireDelivery) — and records the fire in the DB.

Every fire is a run in the run ledger (backend::jobs): its row is inserted before it fires, which for a slot is the lease two schedulers sharing a job need, and only a delivered fire counts toward fire_count (docs/specs/SPEC_JOBS_AND_TEMPLATES_2026_10_24.md §3.2). Cron fires are never held for a stopped agent; what an undelivered fire leaves is the job’s catch-up policy (§5.2): skip, a missed run, or latest, one pending fire this scheduler delivers when the agent is back.

On startup, a latest job whose next scheduled time after last_fired is already in the past fires once as catch-up (FIRE_ONCE_NOW — never replay all missed fires, never cause a cron storm); the slots missed while AgentMux was off are one collapsed skipped row.

See docs/specs/SPEC_CRON_LOOP_ROBUSTNESS_2026_06_25.md §3.2.

Re-exports§

pub use start::ActionOutcome;
pub use start::ActionRunner;

Modules§

expr
Standard 5-field cron (“min hour dom mon dow”, as the Schedule tool documents it) read with the cron crate, which wants a seconds field first and numbers the days of the week 1 = Sunday … 7 = Saturday. In standard cron 0 and 7 are Sunday and 1 is Monday, so the expression is translated here, at parse time only: a job’s stored expression stays the standard one it was written in. Every parse of a job’s expression goes through parse.
schedule
When a job runs: its trigger as a sequence of slots, ms epoch (docs/specs/SPEC_JOBS_AND_TEMPLATES_2026_10_24.md §5.1 “Triggers”).
start
Starting a run once policy lets it (docs/specs/SPEC_JOBS_AND_TEMPLATES_2026_10_24.md §5.1): the job’s action (a message to an agent, a task filed, a worker spawned), and the waiting runs that start when a place frees up.

Structs§

CronScheduler
Fired
How a fire ended.
JobEvent
What a source reports for an event job (CronScheduler::fire_event).

Enums§

FireOutcome
What one fire’s delivery decided, computed once in CronScheduler::fire.
Slot
Which slot a fire is for (§3.1 trigger, scheduled_for_ms).

Type Aliases§

AgentPresence
Whether an agent UID is registered (running) on this instance, so a pending fire is only attempted once its agent is back.
FireDelivery
In-process delivery of a fire: the server’s shared inject path (server::reactive::deliver, on the instance-key tier), given the job’s request and its creator’s UID. Identity M4c-3 (SPEC_AGENT_IDENTITY_CARRIED_NOT_DERIVED_2026_09_23.md §6.5.9): the scheduler is built before AppState, so the server installs this once AppState exists (CronScheduler::install_delivery), as it installs agent-turn delivery. Until then a fire POSTs to the route, as before.