JournalStore and SQLite Persistence
TheJournalStore is the central coordinator for all database operations. It manages a SQLite connection (typically via rusqlite) and provides an abstraction for interacting with specialized tables like journal_events, memory_items, and orchestrator_sessions.
Append-Only Journal Log
Thejournal_events table serves as an immutable, append-only ledger of every significant action taken by the daemon crates/palyra-daemon/src/journal.rs#63-71.
- Integrity Hash Chain: Every event contains a
hashfield. This hash is calculated by combining the event’s payload with the hash of the previous event crates/palyra-daemon/src/gateway.rs#114-115. This creates a cryptographic chain that prevents tampering with historical logs. - Event Types: The log captures model provider interactions, tool executions, approval decisions, and session state transitions.
- Redaction: To protect sensitive information (API keys, passwords), the journaler automatically redacts values associated with keys like
secret,token, orapi_keybefore persisting them to the database crates/palyra-daemon/src/journal.rs#29-45.
Data Flow: Journal Append
- A subsystem (e.g.,
GatewayRuntimeState) issues aJournalAppendRequestcrates/palyra-daemon/src/gateway.rs#63-71. - The
JournalStoreretrieves the hash of the most recent event. - A new SHA-256 hash is computed for the current entry.
- The entry is inserted into the
journal_eventstable within a transaction.
Memory System and Vector Search
The Memory System provides long-term semantic storage for agents. It allows the daemon to “remember” facts across different sessions by embedding text into vector space.Memory Items
AMemoryItem represents a discrete unit of knowledge crates/palyra-daemon/src/journal.rs#64-66.
- Metadata: Includes
principal,channel, andtagsto scope retrieval. - TTL: Items can have an expiration timestamp (
expires_at_unix_ms) for transient memory crates/palyra-daemon/src/gateway/runtime.rs#72-82.
MemoryEmbeddingProvider
TheMemoryEmbeddingProvider trait defines how text is converted into vectors crates/palyra-daemon/src/journal.rs#64-68.
- HashMemoryEmbeddingProvider: A default implementation that uses a deterministic hashing algorithm to generate embeddings, suitable for basic similarity without external LLM dependencies crates/palyra-daemon/src/journal.rs#71-100.
- Vector Search: Retrieval uses a
MemorySearchRequestwhich specifies a query string and atop_klimit (max 64) crates/palyra-daemon/src/gateway.rs#116-117. The system performs a similarity search against thememory_itemstable.
Auto-Inject and Maintenance
- Auto-Inject: When enabled, the system automatically searches memory for relevant context based on the current user prompt and injects the results into the LLM context crates/palyra-daemon/src/gateway/runtime.rs#72-82.
- Vacuum/Maintenance: A background process (
run_memory_maintenance_now) performs periodic cleanup, removing expired items and optimizing the SQLite database crates/palyra-daemon/src/transport/http/handlers/console/memory.rs#130-142.
Cron and Scheduled Routines
The Cron system allows for the execution of recurring tasks (“Routines”).CronJob Configuration
ACronJobRecord defines the schedule and the prompt to be executed crates/palyra-daemon/src/journal.rs#232-248.
- Schedule Types: Supports standard
Cronexpressions,Every(intervals), andAt(one-time execution) crates/palyra-daemon/src/journal.rs#104-108. - Concurrency Policy: Defines behavior if a job is triggered while a previous instance is still running:
Forbid,Replace, orQueueOnecrates/palyra-daemon/src/journal.rs#132-136. - Misfire Policy: Determines how to handle missed executions (e.g., if the daemon was offline):
SkiporCatchUpcrates/palyra-daemon/src/journal.rs#160-164.
Execution Lifecycle
- The
CronServiceImplmonitors thenext_run_at_unix_msfor all enabled jobs crates/palyra-daemon/src/gateway.rs#41-44. - When a job is due, a
CronRunRecordis created with statusAcceptedcrates/palyra-daemon/src/journal.rs#185-192. - The task is dispatched via the
GatewayServiceloopback. - Upon completion, the
CronRunFinalizeRequestupdates the status toSucceededorFailedand schedules the next run crates/palyra-daemon/src/journal.rs#61-63.
Summary of Constraints and Limits
The system enforces several hard limits to ensure stability and prevent resource exhaustion:| Constraint | Value | Source |
|---|---|---|
| Max Recent Events | 100 | crates/palyra-daemon/src/gateway.rs#89 |
| Max Memory Item Size | 16 KB | crates/palyra-daemon/src/gateway.rs#118 |
| Max Memory Search Top K | 64 | crates/palyra-daemon/src/gateway.rs#117 |
| Max Cron Job Name | 128 Bytes | crates/palyra-daemon/src/gateway.rs#104 |
| Max Cron Prompt Size | 16 KB | crates/palyra-daemon/src/gateway.rs#105 |
| Journal Write Latency Budget | 25 ms | crates/palyra-daemon/src/gateway.rs#92 |