openclaw - 💡(How to fix) Fix feat(cron): add skip-if-running / exclusive-run option for cron jobs [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#54325Fetched 2026-04-08 01:28:59
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1

Error Message

  • Internal error log: ERR-20260325-DUPLICATE-COMMENTS-CONCURRENT

Root Cause

Root cause: No platform mechanism to ensure a cron job only has one active run at a time.

Fix Action

Workaround

Agents can implement a partial workaround by reading live API state at cycle start to detect concurrent writes — but this is fragile and creates extra API traffic. A platform-level exclusive-run flag is the proper fix.

RAW_BUFFERClick to expand / collapse

Problem

When a cron job takes longer than its schedule interval (e.g., a 30-minute task scheduled every 30 minutes), multiple instances can run concurrently. Each instance reads shared state files before the other has written its updates, causing race conditions.

Observed impact: Two concurrent ClawInstitute engage sub-agents each read heartbeat-state.json at the same time, see consec=0, independently post comments to the same thread, then both write their comment IDs back — creating duplicate/monologue chains that are invisible to either agent's guard checks.

Root cause: No platform mechanism to ensure a cron job only has one active run at a time.

Proposed Solution

Add a per-job exclusive-run option (e.g., exclusive: true or onOverlap: skip | queue | parallel in cron job config):

  • skip (recommended default for long-running agent jobs): If a previous instance is still running when the next fire time arrives, skip the new instance entirely.
  • queue: Queue the new instance to run after the previous completes.
  • parallel (current behavior): Run concurrently (keep as explicit opt-in, not default).

Workaround

Agents can implement a partial workaround by reading live API state at cycle start to detect concurrent writes — but this is fragile and creates extra API traffic. A platform-level exclusive-run flag is the proper fix.

Severity

Medium — affects any long-running cron agent job (hypothesis discovery ~20min, ClawInstitute engage ~8-15min) scheduled on short intervals (every 6h, every 30min).

References

  • Internal error log: ERR-20260325-DUPLICATE-COMMENTS-CONCURRENT
  • Related: existing webhook concurrency guard request #42332

extent analysis

Fix Plan

To address the issue of concurrent cron job instances, we will implement a per-job exclusive-run option. Here are the steps:

  • Add an exclusive property to the cron job configuration with possible values: skip, queue, or parallel.
  • Update the cron job scheduler to check for the exclusive property before running a new instance.
  • If exclusive is set to skip and a previous instance is still running, skip the new instance.
  • If exclusive is set to queue and a previous instance is still running, queue the new instance to run after the previous completes.

Example cron job configuration:

jobs:
  - name: ClawInstitute engage
    schedule: "*/30 * * * *"
    exclusive: skip
    command: "run-claw-institute-engage"

Example scheduler code (in Python):

import schedule
import time
import threading

class CronJobScheduler:
    def __init__(self):
        self.running_jobs = {}

    def run_job(self, job):
        if job['exclusive'] == 'skip' and job['name'] in self.running_jobs:
            print(f"Skipping {job['name']} as it is already running")
            return
        elif job['exclusive'] == 'queue' and job['name'] in self.running_jobs:
            print(f"Queuing {job['name']} to run after previous instance completes")
            self.queue_job(job)
            return

        self.running_jobs[job['name']] = threading.Thread(target=job['command'])
        self.running_jobs[job['name']].start()

    def queue_job(self, job):
        # Implement queuing logic here
        pass

Verification

To verify that the fix worked, schedule a cron job with the exclusive property set to skip or queue and observe that only one instance runs at a time.

Extra Tips

  • Make sure to handle edge cases such as job failures and timeouts.
  • Consider adding logging and monitoring to track cron job instances and detect potential issues.
  • Review existing cron jobs and update their configurations to use the new exclusive property as needed.

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 feat(cron): add skip-if-running / exclusive-run option for cron jobs [1 participants]