Cron Jobs
Automated memory maintenance — daily transitions, stale pruning, and weekly consolidation
The MemoryCronService (apps/api/src/memory/memory-cron.service.ts) runs scheduled maintenance tasks using @nestjs/schedule.
Schedule Overview
| Job | Schedule | What it does |
|---|---|---|
| Daily file transitions | 0 3 * * * (03:00 UTC daily) | Move old daily files: active → warm → archived |
| Stale memory pruning | 0 4 * * * (04:00 UTC daily) | Mark inactive task memories as completed |
| Memory consolidation | 0 5 * * 0 (05:00 UTC Sundays) | Cluster and merge similar memories |
Daily File Transitions (03:00 UTC)
Moves daily memory files through the pipeline/lifecycle status chain:
active (0-7 days) → warm (7-30 days) → archived (30+ days)Logic:
- Files older than 7 days:
active → warm - Files older than 30 days:
warm → archived
Only active files are included in pipeline/context-assembly.
Stale Memory Pruning (04:00 UTC)
Targets task-type agent memories that are likely outdated:
UPDATE agent_memories
SET status = 'completed'
WHERE memory_type = 'task'
AND status = 'active'
AND created_at < now() - interval '7 days'
AND last_accessed_at < now() - interval '7 days'Tasks that haven't been created or accessed in 7 days are assumed complete.
Weekly Consolidation (Sundays 05:00 UTC)
The most complex maintenance job:
- Find candidates — Agents with >20 active memories
- Cluster — Group memories with cosine similarity ≥0.80
- Filter — Only clusters of 3+ memories
- Consolidate — LLM summarizes each cluster into one memory (see pipeline/extraction)
- Replace — Old memories marked
consolidated, new memory inserted with boosted importance
The consolidated memory gets importance = min(max_cluster_importance + 0.1, 1.0).
Startup Self-Healing
The service implements OnModuleInit to run catch-up tasks on server startup:
async onModuleInit() {
// Run daily transitions (catch missed 03:00 runs)
await this.dailyFileService.transitionDailyFiles();
// Run stale pruning (catch missed 04:00 runs)
await this.memoryService.pruneStaleMemories();
}This handles cases where the server was down during scheduled cron times (e.g., deployments, crashes).
Related Pages
- pipeline/lifecycle — Status transitions managed by these crons
- pipeline/scoring — Similarity thresholds used in consolidation
- pipeline/extraction —
consolidateMemories()LLM call - operations/configuration — Threshold values and intervals