openclaw - 💡(How to fix) Fix [Bug] Cron tasks marked as lost after gateway restart — activeJobIds not persisted

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…

Error Message

  1. Task is marked as `lost` with error: "backing session missing"

Root Cause

The active job tracking mechanism uses an in-memory `Set` (`activeJobIds`) that is not persisted across restarts.

Code flow:

  1. When a cron job starts running, markCronJobActive(jobId) adds the job ID to a memory-only Set
  2. Gateway restarts → the Set is cleared
  3. After the sweeper grace period (5 minutes), isCronJobActive() returns `false`
  4. Task is marked as `lost` with error: "backing session missing"

Key files:

  • `task-registry.maintenance-D1dTWf8y.js` — `CRON_ACTIVE_JOB_STATE_KEY` singleton stores only in-memory `activeJobIds` Set
  • `server.impl-BbJvXoPb.js` — calls `markCronJobActive`/clearCronJobActive but state is never persisted

Fix Action

Workaround

None — this is a design gap in the persistence layer.

RAW_BUFFERClick to expand / collapse

Bug Description

Cron tasks that are currently running are incorrectly marked as `lost` after a Gateway restart.

Root Cause

The active job tracking mechanism uses an in-memory `Set` (`activeJobIds`) that is not persisted across restarts.

Code flow:

  1. When a cron job starts running, markCronJobActive(jobId) adds the job ID to a memory-only Set
  2. Gateway restarts → the Set is cleared
  3. After the sweeper grace period (5 minutes), isCronJobActive() returns `false`
  4. Task is marked as `lost` with error: "backing session missing"

Key files:

  • `task-registry.maintenance-D1dTWf8y.js` — `CRON_ACTIVE_JOB_STATE_KEY` singleton stores only in-memory `activeJobIds` Set
  • `server.impl-BbJvXoPb.js` — calls `markCronJobActive`/clearCronJobActive but state is never persisted

Impact

  • Any long-running cron task (>5 min) will be marked `lost` if Gateway restarts during execution
  • `cron restart gateway` workflow breaks running jobs
  • Config changes requiring Gateway restart disrupt in-flight tasks

Proposed Fix

Persist `activeJobIds` to the cron store file (`~/.openclaw/cron/jobs.json`).

Implementation approach:

  1. Store shape change — add `activeJobIds: string[]` field to the cron store JSON: ```json { "version": 1, "jobs": [...], "activeJobIds": ["job-id-1", "job-id-2"] } ```

  2. In `server.impl-BbJvXoPb.js`:

    • `markCronJobActive(jobId)` → push to `state.store.activeJobIds` + `persist(state)`
    • `clearCronJobActive(jobId)` → filter from `state.store.activeJobIds` + `persist(state)`
    • `ensureLoaded()` → on startup, for any job with `job.state.runningAtMs` set, call `markCronJobActive(job.id)` to rebuild the in-memory Set
  3. In `store-0nH_zmSJ.js`:

    • `loadCronStore()` → load and hydrate `activeJobIds` from file
    • `saveCronStore()` → persist `activeJobIds` alongside jobs

This approach leverages the existing `persist()` mechanism and the already-persisted `job.state.runningAtMs` field to determine which jobs were running at restart time.

Workaround

None — this is a design gap in the persistence layer.

Environment

  • OpenClaw version: 2026.4.2+
  • Gateway running as launchd/systemd service
  • Any cron job with execution time > 5 minutes

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

openclaw - 💡(How to fix) Fix [Bug] Cron tasks marked as lost after gateway restart — activeJobIds not persisted