Cron Architecture and Lifecycle
The scheduler operates as a centralized loop within thepalyrad daemon, monitoring the JournalStore for jobs that have reached their next_run_at_unix_ms threshold.
Core Scheduler Loop
Thespawn_scheduler_loop function initializes the background orchestration. It runs at a default idle interval of 15 seconds [crates/palyra-daemon/src/cron.rs#42-42](http://crates/palyra-daemon/src/cron.rs#42-42). During each tick, it performs the following:
- Job Polling: Fetches a batch of due jobs (up to 64) from the SQLite journal
[crates/palyra-daemon/src/cron.rs#43-43](http://crates/palyra-daemon/src/cron.rs#43-43). - Concurrency Evaluation: Checks the
CronConcurrencyPolicy(Forbid, Replace, or QueueOne) to determine if a new run can start if a previous one is still active[crates/palyra-daemon/src/journal.rs#132-136](http://crates/palyra-daemon/src/journal.rs#132-136). - Misfire Handling: Applies
CronMisfirePolicy(Skip or CatchUp) if the system was offline during a scheduled trigger[crates/palyra-daemon/src/journal.rs#160-164](http://crates/palyra-daemon/src/journal.rs#160-164). - Run Dispatch: Spawns a
RunStateMachinefor the job’s prompt using a system principal[crates/palyra-daemon/src/cron.rs#55-55](http://crates/palyra-daemon/src/cron.rs#55-55).
Cron Schedule Types
Palyra supports three primary scheduling mechanisms defined inCronScheduleType [crates/palyra-daemon/src/journal.rs#104-108](http://crates/palyra-daemon/src/journal.rs#104-108):
| Type | Description | Implementation Detail |
|---|---|---|
Cron | Standard 5-field cron expression. | Parsed via CronMatcher [crates/palyra-daemon/src/cron.rs#129-137](http://crates/palyra-daemon/src/cron.rs#129-137). |
Every | Fixed interval (e.g., every 1 hour). | Calculated using interval_ms [crates/palyra-daemon/src/cron.rs#124-124](http://crates/palyra-daemon/src/cron.rs#124-124). |
At | One-off execution at a specific timestamp. | Uses RFC3339 timestamps [crates/palyra-daemon/src/cron.rs#125-125](http://crates/palyra-daemon/src/cron.rs#125-125). |
Natural Language Space to Code Entity Space: Scheduling
This diagram maps the user-facing “Routine” concepts to the underlying Cron implementation. Title: Routine to Cron Mapping Sources:[crates/palyra-daemon/src/cron.rs#139-156](http://crates/palyra-daemon/src/cron.rs#139-156), [crates/palyra-daemon/src/journal.rs#250-280](http://crates/palyra-daemon/src/journal.rs#250-280), [apps/web/src/console/sections/routinesHelpers.ts#12-44](http://apps/web/src/console/sections/routinesHelpers.ts#12-44).
System Maintenance Ticks
Beyond user-defined jobs, the scheduler manages critical internal maintenance tasks to ensure the health of theJournalStore and RAG (Retrieval-Augmented Generation) capabilities.
Memory Maintenance and Retention
The daemon executes aMemoryMaintenanceRequest every 5 minutes [crates/palyra-daemon/src/cron.rs#56-56](http://crates/palyra-daemon/src/cron.rs#56-56). This task enforces the MemoryRetentionPolicy:
- TTL Expiry: Deletes memory items that have exceeded their time-to-live.
- Capacity Culling: If
max_entriesormax_bytesare exceeded, the system purges the oldest items to maintain the configured budget[crates/palyra-common/src/daemon_config_schema.rs#162-167](http://crates/palyra-common/src/daemon_config_schema.rs#162-167).
Embeddings Backfill
To support hybrid search, the system must ensure all memory items have vector embeddings. TheMEMORY_EMBEDDINGS_BACKFILL_INTERVAL (10 minutes) triggers a process that:
- Identifies memory items missing embeddings for the current
MemoryEmbeddingProviderversion[crates/palyra-daemon/src/cron.rs#57-57](http://crates/palyra-daemon/src/cron.rs#57-57). - Batches items (default 64) for the LLM embedding model
[crates/palyra-daemon/src/cron.rs#58-58](http://crates/palyra-daemon/src/cron.rs#58-58). - Updates the
JournalStorewith the generated vectors[crates/palyra-daemon/src/gateway.rs#64-66](http://crates/palyra-daemon/src/gateway.rs#64-66).
Periodic Skill Reaudit
Security is maintained through thePeriodicSkillReaudit task. By default, every 6 hours, the system re-scans installed skills [crates/palyra-daemon/src/cron.rs#54-54](http://crates/palyra-daemon/src/cron.rs#54-54).
- Trust Verification: Checks
SkillArtifactsignatures against theSkillTrustStore[crates/palyra-daemon/src/cron.rs#18-18](http://crates/palyra-daemon/src/cron.rs#18-18). - Quarantine: If a skill fails the re-audit (e.g., due to a changed policy or tampered file), it is marked as
Quarantineand disabled from execution[crates/palyra-daemon/src/journal.rs#70-70](http://crates/palyra-daemon/src/journal.rs#70-70).
Background Queue and Delegated Sub-runs
Palyra utilizes a background queue for “delegated” tasks where an agent spawns sub-processes or long-running tool executions that should not block the main orchestrator tape.Data Flow: Background Task Execution
This diagram illustrates how a task moves from an LLM proposal to background execution. Title: Background Task Delegation Flow Sources:[crates/palyra-daemon/src/gateway.rs#77-81](http://crates/palyra-daemon/src/gateway.rs#77-81), [crates/palyra-daemon/src/cron.rs#35-36](http://crates/palyra-daemon/src/cron.rs#35-36), [crates/palyra-daemon/src/journal.rs#63-63](http://crates/palyra-daemon/src/journal.rs#63-63).
Routine Registry
Routines are a higher-level abstraction over Cron jobs, stored indefinitions.json within the routines directory [crates/palyra-daemon/src/routines.rs#22-23](http://crates/palyra-daemon/src/routines.rs#22-23).
- Trigger Kinds: Includes
Schedule,Hook,Webhook,SystemEvent, andManual[crates/palyra-daemon/src/routines.rs#35-41](http://crates/palyra-daemon/src/routines.rs#35-41). - Delivery Config: Determines where the output of a background task is sent (e.g.,
SameChannel,SpecificChannel, orLogsOnly)[crates/palyra-daemon/src/routines.rs#69-74](http://crates/palyra-daemon/src/routines.rs#69-74). - Quiet Hours: Prevents background tasks from sending notifications during specific windows, configured via
start_minute_of_dayandend_minute_of_day[crates/palyra-daemon/src/routines.rs#167-172](http://crates/palyra-daemon/src/routines.rs#167-172).
CLI and API Management
Operators manage the Cron subsystem via thepalyra cron command group and the Web Console’s “Cron” section.
Key Management Commands
palyra cron add: Creates a new scheduled job with specific retry and jitter parameters[crates/palyra-cli/src/commands/cron.rs#51-67](http://crates/palyra-cli/src/commands/cron.rs#51-67).palyra cron run-now: Manually triggers a job regardless of its next scheduled time[crates/palyra-cli/src/commands/cron.rs#166-167](http://crates/palyra-cli/src/commands/cron.rs#166-167).palyra cron status: Provides a summary of active jobs, their last outcome, and upcoming runs[crates/palyra-cli/src/commands/cron.rs#23-34](http://crates/palyra-cli/src/commands/cron.rs#23-34).
Jitter and Retries
To prevent “thundering herd” problems where multiple jobs trigger simultaneously, the system supportsjitter_ms (up to 60,000ms) [crates/palyra-daemon/src/gateway.rs#106-106](http://crates/palyra-daemon/src/gateway.rs#106-106). Failed jobs are retried based on the CronRetryPolicy, which defines max_attempts and an exponential backoff_ms [crates/palyra-daemon/src/journal.rs#226-229](http://crates/palyra-daemon/src/journal.rs#226-229).
Sources:
crates/palyra-daemon/src/cron.rscrates/palyra-daemon/src/journal.rscrates/palyra-daemon/src/gateway.rscrates/palyra-daemon/src/routines.rscrates/palyra-cli/src/commands/cron.rscrates/palyra-common/src/daemon_config_schema.rsapps/web/src/console/sections/routinesHelpers.ts