@gmdeep

Cron Semaphore

Serializes cron job execution in OpenClaw to prevent concurrent runs and session contention

当前版本
v1.0.0
bundle-plugin社区source-linked

Cron Semaphore — OpenClaw Plugin

Prevents concurrent cron job execution in OpenClaw. When two cron jobs are scheduled at the same time, one runs and the others wait their turn — no more session corruption errors from jobs stepping on each other.

Why

OpenClaw fires each cron job independently. If two jobs land on the same minute (e.g. 0 18 * * 0), both spawn isolated agent runs simultaneously. Those runs share the same agent runtime, and their embedded sessions can collide — producing EmbeddedAttemptSessionTakeoverError or mysterious timeouts as they fight over session files.

This plugin serializes those runs. Only one cron job runs at a time. The rest are cleanly skipped with a message and retry on their next scheduled interval.

How it works

  1. A cron job starts → before_agent_run hook fires.
  2. Plugin checks a lock file in the workspace directory.
  3. No lock? Acquire it and let the job through.
  4. Lock exists from another job? Block this run with a clean message.
  5. Job finishes → agent_end hook fires → lock is released.
  6. Stale locks (crash recovery) are auto-cleared after 10 minutes or on Gateway restart.

Install

openclaw plugins install clawhub:cron-semaphore

Or from the repo:

git clone https://github.com/GMDEEP/cron-semaphore.git
cd cron-semaphore
openclaw plugins install --link .

Configure

The plugin activates on startup. For it to intercept conversation hooks, you must enable conversation access in your OpenClaw config:

{
  plugins: {
    entries: {
      "cron-semaphore": {
        config: {
          // (optional) Override stale lock timeout in ms. Default: 600000 (10 min)
          staleTimeoutMs: 600000
        },
        hooks: {
          // Required — the before_agent_run hook is a conversation hook
          allowConversationAccess: true
        }
      }
    }
  }
}

Config options

OptionTypeDefaultDescription
staleTimeoutMsinteger600000Milliseconds before a lock is considered stale
lockFilePathstringautoCustom path for lock file (defaults to workspace)

Lock file

The plugin writes .cron-semaphore-lock.json in the workspace directory. It contains:

{
  "jobId": "a6914b45-b21c-4e5e-87d0-63fa976a04ed",
  "jobName": "a6914b45...",
  "acquiredAt": 1780883000000,
  "lastHeartbeat": 1780883005000
}

If a job crashes without releasing the lock, it auto-expires after the stale timeout (10 minutes by default). Gateway restart also cleans stale locks.

License

MIT

源码与版本

源码仓库

GMDEEP/cron-semaphore

打开仓库

源码提交

b8b59525c9fa45b4b7177441d23fa272b352e5df

查看提交

安装命令

openclaw plugins install clawhub:cron-semaphore

元数据

  • 包名: cron-semaphore
  • 创建时间: 2026/06/08
  • 更新时间: 2026/06/08
  • 执行代码:
  • 源码标签: main

兼容性

  • 构建于 OpenClaw: 2026.5.22
  • 插件 API 范围: >=2026.3.13
  • 标签: concurrency, cron, latest, semaphore
  • 文件数: 5