Skip to content

feat(cron): auto-disable repeatedly failing recurring jobs - #118113

Merged
steipete merged 1 commit into
mainfrom
codex/cron-auto-disable-failures
Aug 2, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/cron-auto-disable-failures

Conversation

@steipete

@steipete steipete commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Recurring automations could fail forever on the default configuration without a visible terminal outcome. Failure alerts are opt-in, so a permanently broken job could continue consuming scheduler work while only accumulating state.consecutiveErrors.

This completes the existing cron auto-disable family by stopping time-based recurring jobs after 10 consecutive execution failures, recording the reason durably, and notifying the owning agent with a recovery command.

Fixes #118089

Why This Change Was Made

The scheduler already records the authoritative consecutive-error streak at run completion, so this change uses that O(1) state instead of reading retained run history. A shared auto-disable owner now records state.autoDisabled with a closed reason (consecutive-failures or schedule-errors), timestamp, and count. The field stays in state_json; there is no SQLite DDL, schema-version bump, mirrored column, config option, or protocol-version change.

Notifications are queued while state mutates and drained only after the corresponding durable write succeeds. That contract now covers scheduled completion, manual due completion, and startup recovery. The recurring threshold check remains after schedule-ownership and force-preserve gates, so stale, removed, and out-of-band force runs cannot disable the durable schedule. Manual enable clears the auto-disable record plus both execution and schedule-error streaks.

Source verification found three details beyond the initial issue sketch:

  • Restart-interrupted runs increment consecutiveErrors in startup-run-repair.ts, not timer-outcomes.ts, so startup recovery also uses the canonical policy and post-persist notification queue.
  • The prior schedule-error notification did not carry deliveryContext or a re-enable hint; both schedule and run-failure reasons now share the same owning-agent notifier.
  • Cron job state is a closed Gateway response schema. autoDisabled was added as report-only state and intentionally omitted from writable patch/input schemas.

One-shot completion/exhaustion, trigger.once, and stream-source restart exhaustion remain separate. They represent completion or a different lifecycle owner, not the recurring time-schedule failure streak addressed here.

Production/UI/schema delta is +339/-46 lines (net +293), with +558 test lines and +2 docs lines. The production growth is the named capability plus its persistence, protocol, recovery, notification, and operator-visibility ownership boundaries.

User Impact

  • every and cron jobs auto-disable after 10 consecutive execution failures; successful runs reset the streak.
  • Schedule-computation auto-disable now records the same structured reason (schedule-errors).
  • The owner receives an unconditional post-persist system event containing job name/id, failure count, last-error snippet, and openclaw automations enable <id>.
  • automations list --all, automations show, JSON output, and openclaw doctor expose why a job was auto-disabled.
  • Re-enabling starts cleanly with failure counters reset instead of immediately retripping.

Evidence

Focused Vitest proof:

  • node scripts/run-vitest.mjs src/cron/service/timer.regression.test.ts — 62 passed
  • node scripts/run-vitest.mjs src/cron/service/timer.batch-finalization.test.ts — 24 passed
  • node scripts/run-vitest.mjs src/cron/service/ops.test.ts — 51 passed
  • node scripts/run-vitest.mjs src/cron/service/jobs.schedule-error-isolation.test.ts — 8 passed
  • node scripts/run-vitest.mjs src/cron/store.test.ts — 51 passed
  • node scripts/run-vitest.mjs src/commands/doctor/cron/index.test.ts — 62 passed
  • node scripts/run-vitest.mjs src/cli/cron-cli/shared.test.ts — 66 passed
  • node scripts/run-vitest.mjs packages/gateway-protocol/src/cron-validators.test.ts — 26 passed
  • node scripts/run-vitest.mjs src/cron/service/startup-run-repair.auto-disable.test.ts — 1 passed
  • node scripts/run-vitest.mjs src/cron/service.restart-catchup.test.ts — 26 passed
  • node scripts/run-vitest.mjs src/cron/service.runs-one-shot-main-job-disables-it.test.ts — 18 passed

Broader proof:

  • OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 OPENCLAW_CHANGED_LANES_RAW_SYNC=1 OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree node scripts/check-changed.mjs --base 1704ea59182 --timed — passed all core/core-test/UI/docs formatting, typecheck, lint, dead-code, architecture, database-first, and import-cycle lanes. The normal Crabbox route was unavailable due to the installed broker/provider state, so trusted-source policy used the local fallback against the immutable branch base.
  • OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree pnpm build — passed; final build completed in 3m11.7s, including package surfaces and Control UI.
  • .agents/skills/autoreview/scripts/autoreview --mode local ... — clean, no accepted/actionable findings (Codex gpt-5.6-sol, high reasoning).

Source-blind built-CLI/Gateway probing observed a real scheduled command failure, durable consecutiveErrors: 1, and the 30-second error backoff. The remaining threshold clauses were intentionally marked blocked because public schedule edits and --due runs could not bypass that backoff; the validator did not use force runs, source inspection, or direct SQLite mutation to manufacture ten scheduled outcomes.


Built CLI/Gateway live proof (dist build, ephemeral gateway, isolated state dir, port 19872)

Full threshold → persisted disable → owner notification → re-enable loop, run against the built dist:

  1. Streak accumulation: failing command job (exit 7), 10 consecutive manual automations run --wait failures → consecutiveErrors: 10, job still enabled. (Manual runs do not own the schedule slot, so they feed the streak but do not trip the disable — the trip is reserved for scheduler-owned outcomes.)
  2. Scheduled acceleration is blocked by design: after the streak, error backoff floors nextRunAtMs to +60m (DEFAULT_ERROR_BACKOFF_SCHEDULE_MS cap), and a cron.update state patch cannot backdate it — so the trip was exercised through the other scheduler-owned failure path:
  3. Restart interruption (11th consecutive failure): started a sleep 120 run, kill -9 the gateway mid-run, restarted. Startup repair marked the run failed and tripped the threshold:
    { "enabled": false, "ce": 11,
      "autoDisabled": { "reason": "consecutive-failures", "atMs": 1785696282658, "consecutiveErrors": 11 } }
    Structured log: cron: marking interrupted running job failed on startup → cron: auto-disabled interrupted job after consecutive run failures (consecutiveErrors: 11).
  4. CLI surface: automations list renders the new status decoration: disabled (11x).
  5. Owner notification delivered post-persist: found verbatim in the owning agent's session transcript:

    Automation "proof-fail" (caf09457-…) was auto-disabled after 11 consecutive run failures.
    Last error: cron: job interrupted by gateway restart
    Fix the underlying cause, then run openclaw automations enable caf09457-… to re-enable it.

  6. Manual re-enable reset: automations enable → { "enabled": true, "consecutiveErrors": 0, "autoDisabled": null }.

Ephemeral gateway + test job deleted after the run; no operator state touched.

Refs #118089

Release note: recurring automations now auto-disable after 10 consecutive run failures, record the reason, and notify their owning agent.
@steipete
steipete marked this pull request as ready for review August 2, 2026 18:24
@steipete
steipete requested a review from a team as a code owner August 2, 2026 18:24
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes commands Command implementations size: L maintainer Maintainer-authored PR labels Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 2:29 PM ET / 18:29 UTC.

ClawSweeper review

What this changes

The PR automatically disables repeatedly failing cron and every jobs after ten execution failures, records a durable reason, notifies the owning agent after persistence, and exposes that state through CLI, Doctor, Gateway, and UI types.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 5 items remain

This PR remains necessary: current main can accumulate recurring-job execution errors and only surfaces chronic enabled jobs through Doctor; it does not durably auto-disable a time-based recurring job after a run-failure threshold. The patch follows the scheduler’s existing auto-disable pattern and has no discrete correctness finding, but its new default stop condition and persisted/public state contract need maintainer product confirmation and terminal real-behavior proof before merge. Likely related people: steipete (high confidence), based on the current cron implementation history and this PR.

Priority: P1
Reviewed head: a1bbdbd7800aa8d9656c72329d8701a086514540
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch has a coherent owner-boundary design and focused coverage, but its real runtime proof stops before the new terminal transition and recovery behavior.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The PR body reports focused tests, checks, a build, and a source-blind built CLI/Gateway probe for one error, but it does not show the newly added terminal threshold disable and recovery behavior in a real setup. Add a redacted CLI/Gateway transcript or recording showing the persisted disabled state, owner notification, and re-enable reset. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The PR body reports focused tests, checks, a build, and a source-blind built CLI/Gateway probe for one error, but it does not show the newly added terminal threshold disable and recovery behavior in a real setup. Add a redacted CLI/Gateway transcript or recording showing the persisted disabled state, owner notification, and re-enable reset. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current-main behavior: Current main increments state.consecutiveErrors for error results and resets it after a successful result, but its recurring-error path proceeds to retry/backoff rather than recording a terminal auto-disable state.
Existing sibling policy: Current main already auto-disables jobs after three schedule-computation errors, including a deferred notification path; the PR consolidates this with the new run-failure transition instead of adding an unrelated scheduler mechanism.
PR owner-boundary implementation: The branch introduces one shared auto-disable owner, applies it only after schedule-ownership and force-preserve gates, and queues notifications until the relevant persistence paths complete.
Findings None None.
Security None None.

How this fits together

Cron schedules run agent, command, and system-event jobs, then persist completion state and schedule the next occurrence. This change turns the existing consecutive-error counter into a scheduler-owned terminal state, which is then shown to the operator and delivered to the owning agent as a recovery event.

flowchart LR
  Schedule[Recurring schedule] --> Run[Job execution]
  Run --> Outcome[Persist run outcome]
  Outcome --> Streak[Update consecutive errors]
  Streak --> Threshold{Failure threshold reached?}
  Threshold -->|No| Retry[Backoff and next run]
  Threshold -->|Yes| Disable[Disable and record reason]
  Disable --> Notify[Post-persist owner notification]
  Disable --> Operator[CLI, Doctor, Gateway, UI]
Loading

Decision needed

Question Recommendation
Should OpenClaw’s default recurring-job policy stop an existing cron or every automation after ten consecutive execution failures, with manual re-enable as the recovery path? Adopt the fixed safety backstop: Accept ten consecutive execution failures as the default terminal condition, provided the PR adds terminal-path runtime proof and keeps the documented manual recovery command.

Why: The patch is technically coherent, but choosing a fixed terminal default changes whether existing operator workflows continue retrying or intentionally stop after persistent failures.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The PR body reports focused tests, checks, a build, and a source-blind built CLI/Gateway probe for one error, but it does not show the newly added terminal threshold disable and recovery behavior in a real setup. Add a redacted CLI/Gateway transcript or recording showing the persisted disabled state, owner notification, and re-enable reset. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - Existing recurring jobs that currently retry indefinitely will stop after ten consecutive execution failures; that is an intentional availability and upgrade behavior change, so the fixed threshold and recovery contract need maintainer acceptance.
  • Resolve merge risk (P1) - state.autoDisabled is persisted in job state and added to the closed Gateway response schema, so its report-only client contract should be treated as a compatibility commitment once released.
  • Resolve merge risk (P1) - The supplied real probe demonstrates one failing scheduled command and durable error counting, but not the new threshold disable, owner notification, and manual recovery flow in a built runtime.
Agent review details

Security

None.

PR surface

Source +293, Tests +558, Docs +2. Total +853 across 23 files.

View PR surface stats
Area Files Added Removed Net
Source 13 339 46 +293
Tests 9 558 0 +558
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 23 899 46 +853

Review metrics

Metric Value Why it matters
Persisted public cron state 1 report-only state field added autoDisabled is persisted in cron state and returned through a closed Gateway response schema, making the new operator-visible contract relevant to upgrade review.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor/cron/index.test.ts, migration/backfill/repair: src/commands/doctor/cron/index.ts, migration/backfill/repair: src/cron/service/startup-run-repair.auto-disable.test.ts, migration/backfill/repair: src/cron/service/startup-run-repair.ts, serialized state: src/cron/service/ops-lifecycle.ts, serialized state: src/cron/service/ops.test.ts, and 3 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #118089
Summary: This PR is the linked candidate implementation for the recurring-job silent-failure report.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Prove and retain the safety backstop (recommended)
    Before merge, attach redacted built CLI/Gateway evidence for threshold disable, post-persist notification, and re-enable reset, then merge with the fixed default threshold as an intentional contract.
  2. Accept the operator stop condition
    Maintainers may merge with the existing focused tests if they explicitly accept that existing recurring jobs will stop rather than retry after the fixed threshold.
  3. Pause the default behavior change
    Keep the current backoff-only behavior if maintainers do not want an unconditional scheduler stop policy for existing recurring jobs.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Add redacted built CLI/Gateway proof for the tenth failure disabling a recurring job, post-persist owner notification, and `automations enable` resetting the recorded state.

Technical review

Best possible solution:

Keep one scheduler-owned, post-persist auto-disable transition; explicitly accept the fixed default threshold for existing recurring jobs and add redacted built CLI/Gateway proof that a threshold breach disables the persisted job, sends the recovery event, and cleanly resets on automations enable.

Do we have a high-confidence way to reproduce the issue?

Yes, source reproducible: current main persists a recurring job’s consecutive execution-error streak yet does not use it to terminate the recurring schedule. The PR body also reports a real built CLI/Gateway probe for the first failure, while focused tests cover the threshold transition.

Is this the best way to solve the issue?

Yes, conditionally: the branch places the transition at the authoritative outcome and startup-repair owners, preserves stale/forced-run boundaries, and shares the existing schedule-error auto-disable mechanism. The remaining choice is whether the fixed default threshold is the desired product policy for existing jobs.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d02101d7ceb6.

Labels

Label changes:

  • add P1: The patch addresses a default recurring automation workflow that can repeatedly fail without an operator-visible terminal outcome.
  • add merge-risk: 🚨 compatibility: The branch adds a durable, closed-schema cron state field consumed through Gateway, CLI, Doctor, and UI types.
  • add merge-risk: 🚨 availability: After merge, existing recurring jobs that reach ten consecutive execution failures stop running until an operator re-enables them.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body reports focused tests, checks, a build, and a source-blind built CLI/Gateway probe for one error, but it does not show the newly added terminal threshold disable and recovery behavior in a real setup. Add a redacted CLI/Gateway transcript or recording showing the persisted disabled state, owner notification, and re-enable reset. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P1: The patch addresses a default recurring automation workflow that can repeatedly fail without an operator-visible terminal outcome.
  • merge-risk: 🚨 compatibility: The branch adds a durable, closed-schema cron state field consumed through Gateway, CLI, Doctor, and UI types.
  • merge-risk: 🚨 availability: After merge, existing recurring jobs that reach ten consecutive execution failures stop running until an operator re-enables them.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body reports focused tests, checks, a build, and a source-blind built CLI/Gateway probe for one error, but it does not show the newly added terminal threshold disable and recovery behavior in a real setup. Add a redacted CLI/Gateway transcript or recording showing the persisted disabled state, owner notification, and re-enable reset. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current-main behavior: Current main increments state.consecutiveErrors for error results and resets it after a successful result, but its recurring-error path proceeds to retry/backoff rather than recording a terminal auto-disable state. (src/cron/service/timer-outcomes.ts:130, d02101d7ceb6)
  • Existing sibling policy: Current main already auto-disables jobs after three schedule-computation errors, including a deferred notification path; the PR consolidates this with the new run-failure transition instead of adding an unrelated scheduler mechanism. (src/cron/service/jobs-scheduling.ts:355, d02101d7ceb6)
  • PR owner-boundary implementation: The branch introduces one shared auto-disable owner, applies it only after schedule-ownership and force-preserve gates, and queues notifications until the relevant persistence paths complete. (src/cron/service/auto-disable.ts:1, a1bbdbd7800a)
  • Persisted and public state contract: The branch adds one report-only autoDisabled state field to the closed Gateway cron response schema while excluding it from writable runtime state patches; re-enabling clears the record and both error streaks. (packages/gateway-protocol/src/schema/cron.ts:430, a1bbdbd7800a)
  • History and current-main provenance: The current cron service files and the immediately preceding current-main implementation commit are attributed to Peter Steinberger, corresponding to steipete; the PR is a direct child of its own base and current main does not contain the new helper or state field. (src/cron/service/timer-outcomes.ts:1, 19aad4ac2a40)
  • Repository policy: Full root policy and the applicable UI guide were read. The branch uses the repository’s canonical record guard in Doctor, adds no config option or SQLite schema bump, and its UI change is a type declaration rather than a live bundle or localization change. (AGENTS.md:1, d02101d7ceb6)

Likely related people:

  • steipete: Peter Steinberger authored the current-main commit that introduced the cron scheduling, outcome, and state surfaces involved here, and authored this follow-up branch. (role: current cron feature owner and recent area contributor; confidence: high; commits: 19aad4ac2a40, a1bbdbd7800a; files: src/cron/service/timer-outcomes.ts, src/cron/service/jobs-scheduling.ts, src/cron/service/startup-run-repair.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Attach redacted built CLI/Gateway evidence for threshold disable, post-persist owner notification, and manual re-enable reset.
  • Confirm maintainer acceptance of stopping existing recurring jobs after the fixed failure threshold.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 08d0952 into main Aug 2, 2026
194 of 208 checks passed
@steipete
steipete deleted the codex/cron-auto-disable-failures branch August 2, 2026 18:51
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
…118113)

Refs openclaw#118089

Release note: recurring automations now auto-disable after 10 consecutive run failures, record the reason, and notify their owning agent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Auto-disable recurring cron jobs after consecutive run failures, with recorded reason and owner notification

1 participant