openclaw - 💡(How to fix) Fix Feature Request: Cron job lifecycle hooks (preCreate / postCreate / onFailure) [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#70285Fetched 2026-04-23 07:26:43
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Add configurable lifecycle hooks for cron job operations, enabling teams to enforce creation standards, auto-register jobs in tracking systems, and handle failures programmatically.

Root Cause

Add configurable lifecycle hooks for cron job operations, enabling teams to enforce creation standards, auto-register jobs in tracking systems, and handle failures programmatically.

Code Example

{
  "cron": {
    "hooks": {
      "preCreate": "python3 /path/to/validate-cron.py",
      "postCreate": "python3 /path/to/register-manifest.py",
      "onFailure": "python3 /path/to/handle-failure.py"
    }
  }
}

---

#!/usr/bin/env python3
import json, sys, os

job = json.load(sys.stdin)
payload = job.get("payload", {})
errors = []

# Require explicit model
if not payload.get("model"):
    errors.append("Model must be explicitly pinned (no default)")

# Require timeout
if not payload.get("timeoutSeconds"):
    errors.append("Timeout must be configured")

# Require backing script for agentTurn jobs
if payload.get("kind") == "agentTurn":
    msg = payload.get("message", "")
    if "python3" not in msg and ".py" not in msg:
        errors.append("Job must reference a backing script")

if errors:
    print("\n".join(errors), file=sys.stderr)
    sys.exit(1)
RAW_BUFFERClick to expand / collapse

Summary

Add configurable lifecycle hooks for cron job operations, enabling teams to enforce creation standards, auto-register jobs in tracking systems, and handle failures programmatically.

Motivation

We manage 60 cron jobs across 19 agents. After a series of reliability issues, we built a hardening standard (cron-ops skill) that requires every job to have:

  • A backing script (not pure LLM generation)
  • An explicitly pinned model
  • A properly sized timeout
  • Failure alerting
  • Registration in a manifest file

The problem: Skills are guidance, not gates. The agent can (and did) bypass the standard by calling openclaw cron add directly. We caught it the same day we built the standard — the agent created a new job and skipped 2 of 8 required steps.

Currently the only enforcement is a daily audit script that catches violations after the fact. A pre-create hook would catch them before the job goes live.

Proposed Feature

A hooks configuration under cron in openclaw.json:

{
  "cron": {
    "hooks": {
      "preCreate": "python3 /path/to/validate-cron.py",
      "postCreate": "python3 /path/to/register-manifest.py",
      "onFailure": "python3 /path/to/handle-failure.py"
    }
  }
}

Hook Behavior

preCreate:

  • Runs before cron add creates the job
  • Receives the proposed job config as JSON on stdin
  • If exit code ≠ 0, creation is blocked
  • stderr is returned to the agent as the rejection reason
  • Example: validate that a backing script exists, model is pinned, timeout is set

postCreate:

  • Runs after successful job creation
  • Receives the created job config (with ID) as JSON on stdin
  • Non-blocking — failures are logged but don't roll back the job
  • Example: auto-register in a manifest file, set up failure alerting

onFailure:

  • Runs when a job hits N consecutive failures (configurable threshold)
  • Receives the job config + failure details as JSON on stdin
  • Example: auto-disable the job, send an escalation alert, open a GitHub issue

Example preCreate Validator

#!/usr/bin/env python3
import json, sys, os

job = json.load(sys.stdin)
payload = job.get("payload", {})
errors = []

# Require explicit model
if not payload.get("model"):
    errors.append("Model must be explicitly pinned (no default)")

# Require timeout
if not payload.get("timeoutSeconds"):
    errors.append("Timeout must be configured")

# Require backing script for agentTurn jobs
if payload.get("kind") == "agentTurn":
    msg = payload.get("message", "")
    if "python3" not in msg and ".py" not in msg:
        errors.append("Job must reference a backing script")

if errors:
    print("\n".join(errors), file=sys.stderr)
    sys.exit(1)

Additional Context

  • We currently work around this with a wrapper script (ops/cron-create.py) but agents can bypass it
  • The cron add CLI doesn't support --failure-alert flags — we have to create then immediately cron edit, which is another gap where enforcement falls through
  • Our full audit tooling and standards are open source: jayh4wk/openclaw-skills

Impact

This would benefit any team running OpenClaw at scale with multiple agents creating cron jobs. The hook pattern is unopinionated — it doesn't force any specific standard, just provides the enforcement point.


Submitted by (@jayh4wk)

extent analysis

TL;DR

Implement a hooks configuration in openclaw.json to enforce cron job creation standards and handle failures programmatically.

Guidance

  • Introduce a preCreate hook to validate proposed job configurations before creation, blocking the process if standards are not met.
  • Implement a postCreate hook to auto-register jobs in a manifest file and set up failure alerting after successful job creation.
  • Develop an onFailure hook to handle consecutive job failures, such as auto-disabling the job or sending escalation alerts.
  • Update the cron add CLI to support the new hook configuration and ensure agents cannot bypass the standards.

Example

The provided preCreate validator script can be used as a starting point for implementing the validation logic:

#!/usr/bin/env python3
import json, sys, os

job = json.load(sys.stdin)
payload = job.get("payload", {})
errors = []

# Require explicit model
if not payload.get("model"):
    errors.append("Model must be explicitly pinned (no default)")

# Require timeout
if not payload.get("timeoutSeconds"):
    errors.append("Timeout must be configured")

# Require backing script for agentTurn jobs
if payload.get("kind") == "agentTurn":
    msg = payload.get("message", "")
    if "python3" not in msg and ".py" not in msg:
        errors.append("Job must reference a backing script")

if errors:
    print("\n".join(errors), file=sys.stderr)
    sys.exit(1)

Notes

The proposed feature relies on the openclaw.json configuration file and the cron CLI. Ensure that the hooks configuration is properly integrated with the existing cron functionality.

Recommendation

Apply the proposed hooks configuration to enforce cron job creation standards and handle failures programmatically, as it provides a flexible and unopinionated way to implement custom validation and automation logic.

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 Feature Request: Cron job lifecycle hooks (preCreate / postCreate / onFailure) [1 participants]