openclaw - 💡(How to fix) Fix [Bug]: memory-core managed dreaming cron job lost after gateway restart (not auto-restored) [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#63449Fetched 2026-04-09 07:53:36
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Root Cause

English: The memory-core plugin registers a managed cron job for the dreaming (short-term memory promotion) feature via econcileShortTermDreamingCronJob(). However, when the gateway exits abnormally (crash, kill, power loss), the jobs.json file can become corrupted or truncated to an empty state. Upon restart, the cron store loads the empty jobs.json without validating its integrity and without restoring from the existing jobs.json.bak backup. The memory-core plugin's reconcile logic never runs because the cron service appears to be unavailable or incomplete during the gateway:startup hook execution.

Fix Action

Fix / Workaround

Workaround / 临时解决方案

RAW_BUFFERClick to expand / collapse

Bug Description / 问题描述

English: The memory-core plugin registers a managed cron job for the dreaming (short-term memory promotion) feature via econcileShortTermDreamingCronJob(). However, when the gateway exits abnormally (crash, kill, power loss), the jobs.json file can become corrupted or truncated to an empty state. Upon restart, the cron store loads the empty jobs.json without validating its integrity and without restoring from the existing jobs.json.bak backup. The memory-core plugin's reconcile logic never runs because the cron service appears to be unavailable or incomplete during the gateway:startup hook execution.

中文: memory-core 插件通过 econcileShortTermDreamingCronJob() 注册了一个托管的 dreaming(短期记忆晋升)cron job。然而,当 gateway 异常退出(崩溃、被 kill、掉电)时,jobs.json 文件可能损坏或被截断为空文件。重启后,cron store 加载空的 jobs.json 时不验证其完整性,也不会从现有的 jobs.json.bak 备份恢复。由于在 gateway:startup 钩子执行时 cron 服务可能尚未就绪,memory-core 插件的协调逻辑无法运行。

Reproduction Steps / 复现步骤

  1. Enable plugins.entries.memory-core.config.dreaming.enabled: true in openclaw.json
  2. Wait for the managed dreaming cron job to be registered (check jobs.json)
  3. Simulate abnormal gateway exit: askkill /F /IM node.exe or power loss
  4. Observe that jobs.json is now empty or corrupted
  5. Restart gateway
  6. Run openclaw cron list — the dreaming job is missing
  7. The DREAMS.md file is never created, and short-term memories are never promoted to MEMORY.md

Root Cause Analysis / 根因分析

English: The bug is in the cron store implementation (store-CZHRy7S3.js):

  1. loadCronStore() treats an empty/corrupted jobs.json as a valid empty state ({version:1, jobs:[]}) without integrity validation
  2. saveCronStore() skips backup creation when previous === null (file doesn't exist or is unreadable) AND the current store state equals the empty JSON
  3. No automatic restoration from jobs.json.bak is implemented
  4. The econcileShortTermDreamingCronJob() function relies on the cron service being fully initialized during gateway:startup, but the cron service may not be ready at that point

中文: Bug 位于 cron store 实现(store-CZHRy7S3.js):

  1. loadCronStore() 将空的/损坏的 jobs.json 视为有效的空状态({version:1, jobs:[]}),不进行完整性验证
  2. saveCronStore() 在 previous === null(文件不存在或无法读取)且当前存储状态等于空 JSON 时,跳过备份创建
  3. 没有实现从 jobs.json.bak 自动恢复的机制

econcileShortTermDreamingCronJob() 函数依赖 cron 服务在 gateway:startup 期间完全初始化,但此时 cron 服务可能尚未就绪

Impact / 影响

  • Memory consolidation completely broken: Short-term memories in memory/YYYY-MM-DD.md are never promoted to MEMORY.md
  • Dreaming feature non-functional: The DREAMS.md file is never created
  • User trust affected: Users who enabled this feature believe it\'s working, but it silently fails
  • Difficult to diagnose: No warning logs when the job is lost after restart

Suggested Fix / 建议修复

  1. Integrity check on load: Validate that jobs.json is not truncated or corrupted before treating it as valid
  2. Auto-restore from backup: When jobs.json is empty/missing but jobs.json.bak exists, restore from backup
  3. Startup retry logic: If cron.list() returns empty during gateway:startup, retry after a delay
  4. Health check: Add a openclaw cron doctor command to validate job persistence

Environment / 环境

  • OpenClaw version: 2026.4.8
  • OS: Windows_NT (Windows 11)
  • Gateway mode: local
  • Config path: D:\OpenClawData\.openclaw

Files Involved / 相关文件

  • dist/store-CZHRy7S3.js — cron store implementation
  • dist/dreaming-looUjKfS.js — memory-core dreaming reconciliation
  • dist/agent-runner.runtime-BEglkhP6.js — cron service integration

Workaround / 临时解决方案

Manually recreate the job using openclaw cron add after each gateway restart, or use jobs.json.bak to restore the job definition manually.

extent analysis

TL;DR

Implement integrity checks and auto-restore from backup for the jobs.json file to prevent data loss and ensure the cron service is fully initialized before relying on it.

Guidance

  • Validate the integrity of jobs.json before treating it as a valid state to prevent empty or corrupted files from causing issues.
  • Implement auto-restore from jobs.json.bak when the primary file is empty or missing to ensure data persistence.
  • Introduce startup retry logic for the cron service to handle cases where it's not fully initialized during gateway:startup.
  • Consider adding a health check command, such as openclaw cron doctor, to validate job persistence and detect potential issues.

Example

// Example of integrity check and auto-restore in loadCronStore()
function loadCronStore() {
  const jobsJson = readJsonFile('jobs.json');
  if (jobsJson && jobsJson.version === 1 && Array.isArray(jobsJson.jobs)) {
    // Valid state, proceed
  } else if (fileExists('jobs.json.bak')) {
    // Restore from backup if primary file is invalid or missing
    const backupJson = readJsonFile('jobs.json.bak');
    writeJsonFile('jobs.json', backupJson);
  } else {
    // Handle error or initialize with default state
  }
}

Notes

The provided fix suggestions assume that the jobs.json file's structure and the backup mechanism are correctly implemented. Additional logging and error handling may be necessary to ensure the robustness of the solution.

Recommendation

Apply the suggested fixes, including integrity checks, auto-restore from backup, and startup retry logic, to ensure the cron service's reliability and data persistence. This approach addresses the root causes of the issue and provides a more robust solution than a temporary workaround.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING