Skip to main content
The Scheduler subsystem in palyrad is responsible for the lifecycle of deferred and recurring operations. It manages three primary categories of work: user-defined Routines (high-level automations), system CronJobs (low-level scheduled tasks), and Background Maintenance (memory vacuuming, embedding backfills, and security re-audits).

Scheduler Architecture

The scheduler operates as a long-running loop spawned during daemon initialization. It utilizes a “poll-and-sleep” model to identify due tasks while maintaining high concurrency for task execution.

The Scheduler Loop

The core logic resides in spawn_scheduler_loop, which monitors the JournalStore for jobs whose next_run_at_unix_ms has passed crates/palyra-daemon/src/cron.rs#42-46. It processes due jobs in batches (up to 64) to prevent head-of-line blocking crates/palyra-daemon/src/cron.rs#43.

Scheduler Data Flow

The following diagram illustrates how the spawn_scheduler_loop interacts with the JournalStore and the GatewayRuntimeState to execute tasks. Scheduler Execution Flow Sources: crates/palyra-daemon/src/cron.rs#42-100, crates/palyra-daemon/src/journal.rs#34-40

Routines vs. CronJobs

While both represent scheduled work, they exist at different layers of the system.
FeatureCronJob (CronJobRecord)Routine (RoutineMetadataRecord)
DefinitionLow-level execution primitive.High-level user automation.
Storagecron_jobs table in SQLite.definitions.json in routines/ dir.
TriggersTime-based (Cron, Every, At).Schedule, Hook, Webhook, Manual.
ComplexitySimple task metadata.Includes quiet hours, delivery modes, and templates.
Principalsystem:cron or system:daemon.User principal (e.g., user:admin).

Routine Lifecycle

Routines are managed via the routines.rs module and synchronized into CronJobRecords when their trigger is time-based crates/palyra-daemon/src/transport/http/handlers/console/routines.rs#160-162. Routine to Cron Mapping Sources: crates/palyra-daemon/src/routines.rs#188-203, crates/palyra-daemon/src/cron.rs#85-91, crates/palyra-daemon/src/transport/http/handlers/console/routines.rs#160-170

Execution Policies

The scheduler enforces strict policies to handle missed executions and overlapping runs.

Misfire Policies

Defined in CronMisfirePolicy crates/palyra-daemon/src/journal.rs#35:
  • Skip: If a job is missed (e.g., daemon was offline), skip the missed window and schedule the next occurrence.
  • Catch Up: Execute one run immediately to represent the missed window, then resume normal schedule.

Concurrency Policies

Defined in CronConcurrencyPolicy crates/palyra-daemon/src/journal.rs#35:
  • Forbid: If a previous instance of the same job is still Running, do not start a new one.
  • Replace: Kill the existing Running instance and start a fresh one.
  • Queue One: Allow one pending run to wait for the current one to finish.
Sources: crates/palyra-daemon/src/cron.rs#158-174, crates/palyra-daemon/src/journal.rs#35-38

Background Maintenance Tasks

The daemon runs several internal routines to maintain system health and security. These are hardcoded intervals within the cron.rs module.

Memory Maintenance

Security Re-Audit

To ensure installed skills remain compliant with evolving policies, the scheduler performs a periodic re-audit of skill artifacts.

Task Summary Table

Task NameIntervalImplementationPurpose
Scheduler Loop15sspawn_scheduler_loopDispatches due CronJobs/Routines.
Memory Vacuum5mMEMORY_MAINTENANCE_INTERVALEnforces retention/TTL policies.
Embeddings Backfill10mMEMORY_EMBEDDINGS_BACKFILL_BATCH_SIZEGenerates vectors for RAG.
Skill Re-audit6hDEFAULT_SKILL_REAUDIT_INTERVALRe-verifies Wasm skill security.
Sources: crates/palyra-daemon/src/cron.rs#42-58, crates/palyra-daemon/src/model_provider.rs#25-27, crates/palyra-common/src/daemon_config_schema.rs#145-151