System Architecture
The automation subsystem consists of three primary layers: the Routine Registry (storing metadata and policy), the Cron Scheduler (managing the clock and misfires), and the Gateway Runtime (executing the actual agent runs).Automation Component Map
The following diagram maps high-level automation concepts to their implementation entities in the codebase. Title: Routine and Scheduler Entity Map Sources: crates/palyra-daemon/src/cron.rs#1-13, crates/palyra-daemon/src/routines.rs#1-10, crates/palyra-daemon/src/application/tool_runtime/routines.rs#1-10The Scheduler Loop
Thespawn_scheduler_loop is the heart of Palyra’s time-based automation. It operates on a 15-second idle sleep interval crates/palyra-daemon/src/cron.rs#75-75 and performs several critical tasks:
- Due Tick Scanning: Identifies
CronJobRecordentries wherenext_run_at_unix_msis in the past. - Misfire Recovery: Applies policies (Skip/CatchUp) for ticks missed during daemon downtime.
- Maintenance Tasks: Hosts periodic re-audits of skills, memory maintenance, and embedding backfills crates/palyra-daemon/src/cron.rs#7-13.
Scheduler Data Flow
Title: Scheduler Loop Logic (spawn_scheduler_loop) Sources: crates/palyra-daemon/src/cron.rs#3-13, crates/palyra-daemon/src/cron.rs#75-80Misfire and Concurrency Policies
Palyra provides granular control over how the scheduler handles missed windows and overlapping runs.Misfire Policies (CronMisfirePolicy)
- Skip: The default policy. If the daemon was offline during a scheduled tick, it simply calculates the next future tick and moves on crates/palyra-daemon/src/cron.rs#62-62, crates/palyra-cli/src/args/cron.rs#89-90.
- CatchUp: Attempts to run missed ticks. To prevent “thundering herds,” catch-up is capped at 3 runs crates/palyra-daemon/src/cron.rs#79-79, and outages older than 24 hours are routed to operator review crates/palyra-daemon/src/cron.rs#80-80.
Concurrency Policies (CronConcurrencyPolicy)
When a new run is triggered while a previous instance of the same routine is still active:
| Policy | Behavior |
|---|---|
| Forbid | The new run is skipped entirely. Default for most routines crates/palyra-cli/src/args/cron.rs#83-84. |
| QueueOne | One new run is queued to start immediately after the current one finishes. |
| Replace | The currently running instance is cancelled, and the new one starts immediately. |
Routine Execution Constraints
Routines are more than just cron jobs; they wrap execution with safety and delivery logic.Approval Modes
Routines support threeRoutineApprovalMode levels crates/palyra-daemon/src/routines.rs#46-46:
- None: Run immediately when triggered.
- BeforeEnable: The routine is created in a
Disabledstate and requires a one-time operator approval to be enabled crates/palyra-cli/src/args/cron.rs#124-124. - BeforeFirstRun: Requires approval specifically for the first execution after creation or modification.
Quiet Hours
TheRoutineQuietHours configuration allows operators to define windows (e.g., 22:00 to 07:00) during which a routine will not fire, regardless of the trigger crates/palyra-daemon/src/routines.rs#49-49. Ticks occurring during quiet hours are treated as misfires and follow the configured MisfirePolicy.
Stable Jitter
To prevent multiple routines from firing at the exact same second (e.g., “every hour” tasks all hitting at 00:00:00), Palyra uses Stable Jitter. The jitter is derived from a hash of the routine ID and its schedule, ensuring that while the offset is random, it remains consistent across daemon restarts crates/palyra-daemon/src/cron.rs#10-13.The palyra.routines Tool Interface
The daemon exposes routine management to agents through two specialized tools:palyra.routines.query: Allows listing routines, checking run logs, and previewing upcoming schedules crates/palyra-daemon/src/application/tool_runtime/routines.rs#3-4.palyra.routines.control: Allows agents to create, pause, resume, or delete routines crates/palyra-daemon/src/application/tool_runtime/routines.rs#4-5.
Tool Implementation Details
The tool executor (execute_routines_tool) ensures that agents cannot bypass security policies. For example, if an agent tries to create a routine with an “Every 1 second” interval, the system enforces a minimum interval of 30 seconds crates/palyra-daemon/src/application/tool_runtime/routines.rs#58-58.
Sources: crates/palyra-daemon/src/application/tool_runtime/routines.rs#1-10, crates/palyra-daemon/src/application/tool_runtime/routines.rs#80-113
CLI Interface
Thepalyra cron and palyra routines commands provide the primary operator interface for automation.
| Command | Purpose |
|---|---|
palyra cron add | Creates a schedule-triggered routine using cron, at, or every syntax crates/palyra-cli/src/args/cron.rs#54-70. |
palyra routines upsert | The unified command for all trigger types (webhook, file-watch, etc.) crates/palyra-cli/src/args/routines.rs#54-55. |
palyra cron status | Displays a dashboard of upcoming runs and recent outcomes crates/palyra-cli/src/args/cron.rs#15-28. |
palyra routines logs | Shows the execution history for a specific routine crates/palyra-cli/src/args/routines.rs#124-133. |
Schedule Preview
Thepalyra routines schedule-preview command allows testing natural language or cron strings against the CronMatcher to see exactly when they will fire in a given timezone crates/palyra-cli/src/args/routines.rs#161-167.
Sources: crates/palyra-cli/src/commands/cron.rs#1-5, crates/palyra-cli/src/args/cron.rs#1-12, crates/palyra-cli/src/args/routines.rs#1-15