OpenClaw / OpenClaw Core
Merged upstreamMaintenanceMerged Aug 9, 2026

Remove deleted cron job sessions

Fixed OpenClaw cron removal so deleted isolated cron jobs also clean up their reusable base sessions and no longer appear as ghost entries in session-management surfaces.

openclaw/openclaw · #119520

Problem

Deleting a cron job removed its cron definition but left the agent:<agent>:cron:<jobId> session record behind. Operators could still see deleted jobs in the Control UI session dropdown even though the job itself was gone.

Approach

Ran session cleanup after durable cron-definition removal through the canonical session lifecycle mutation, added guarded cleanup for exact active-run markers, and fenced same-ID replacement across sibling CronService instances sharing the same cron store.

Impact and scope

  • Removes ghost cron sessions from the session store and Control UI after isolated/current jobs are deleted.
  • Preserves active runs, shared main sessions, unrelated jobs, and per-run history governed by cron retention.
  • Prevents same-ID recreation races by making replacement wait for the previous job's asynchronous session cleanup to finish.

Validation

  • Added a dedicated remove-session-cleanup suite covering isolated sessions, active markers, replacement fencing, sibling services, and session reaper behavior.
  • Documented real CLI/gateway proof against isolated SQLite state showing the cron job and base session were both gone after removal.
  • Merged with 7 focused cron/session test files and 138 passing tests documented on the PR.