Skip to content

fix(cron): deliver failure alerts only after persistence - #118200

Merged
steipete merged 1 commit into
mainfrom
codex/cron-alert-post-persist
Aug 2, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/cron-alert-post-persist

Conversation

@steipete

@steipete steipete commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #118187

AI-assisted with Codex. I reviewed the implementation and validation results.

What Problem This Solves

Fixes an issue where cron failure alerts could reach operators before the failed run outcome was durably stored. If that store write then failed, OpenClaw rolled back the run state and alert cooldown while the alert had already escaped, allowing premature and potentially duplicate alerts.

Why This Change Was Made

Failure-alert policy resolution, threshold/cooldown checks, and lastFailureAlertAtMs recording now stay inside the run-outcome mutation. Actual announce, webhook, system-event, and heartbeat delivery is queued with a by-value job/route snapshot and drained only after persistence succeeds. Record-only startup replay remains delivery-free.

The existing auto-disable-specific deferred plumbing is renamed to the generic DeferredCronNotifications, deferredNotifications, and postPersistNotifications vocabulary because it now owns both alert families. The researched issue context said the list already reached every completion caller, but current source had three gaps: external stream failures, invalid persisted manual-run skips, and removed-job finalization. This change threads the generic queue through all three so error and opted-in skipped alerts share the same durability boundary.

Alert thresholds, cooldown duration, text, routing, account/topic inheritance, best-effort and failure-destination suppression, and opt-in behavior are unchanged.

User Impact

Cron failure alerts now describe only run outcomes that survived persistence. A failed cron store write sends no alert and restores the prior cooldown state; after a successful write, the persisted cooldown still suppresses repeated delivery as before.

Evidence

  • pnpm install — passed; lockfile unchanged and workspace dependencies installed.
  • node scripts/run-vitest.mjs src/cron/service/failure-alerts.persistence.test.ts src/cron/service.failure-alert.test.ts src/cron/service/failure-alerts.account-routing.test.ts src/cron/store/failure-alert-codec.test.ts src/cron/service/timer.batch-finalization.test.ts src/cron/service/timer.regression.test.ts src/cron/service/ops.test.ts src/cron/service/startup-run-repair.auto-disable.test.ts src/cron/service.stream-validation.test.ts — 9 files passed, 202 tests passed.
  • env OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 node scripts/check-changed.mjs — passed all selected core/core-test formatting, guards, production/test typechecks, lint, dead-code, boundary, database, and import-cycle lanes. The normal wrapper first attempted Testbox, but the configured Crabbox provider doctor was unavailable, so trusted-source validation used the repository-documented local fallback.
  • git diff --check — passed.
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted --prompt 'Review scope: GitHub issue #118187. Preserve all cron failure-alert semantics while moving delivery post-persist; verify all production completion paths, rollback/cooldown atomicity, by-value routing capture, record-only replay, and the complete DeferredCronNotifications rename. Treat unrelated changes as out of scope.' --stream-engine-output — clean; no accepted/actionable findings.

The new boundary coverage proves strict [persist, alert] order for error and includeSkipped alerts, no delivery plus cooldown rollback on persist failure, and persisted cooldown dedupe after a successful write. Existing auto-disable ordering and rollback coverage remains green.


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

Global config cron.failureAlert: { enabled: true, after: 2, cooldownMs: 3600000 }, failing command job (exit N), three consecutive manual automations run --wait failures:

  • Announce mode (no channel configured): alert decision fired at run 2 — lastFailureAlertAtMs recorded on the job and stable through run 3 (cooldown suppression live); the delivery outcome was recorded as a fact (lastFailureNotificationDelivered: false, status: "not-delivered") instead of vanishing.
  • Webhook mode (mode: "webhook", loopback listener): structured log shows cron: failure alert webhook blocked by SSRF guard for the job — stamped by the deferred post-persist delivery closure executing after run finalization (the guard sits inside the delivery path). Exactly 1 alert attempt across 3 failures (grep -c on the structured log): decision once at run 2, cooldown-suppressed at run 3. Loopback rejection is the guard working as designed; delivery success ordering is owned by the persistence tests ([persist, alert], delivered-once, rollback-no-delivery).

Ephemeral gateway, listener, and proof jobs deleted after the run; no operator state touched.

Fixes #118187. Failure-alert cooldown state now commits with the run outcome before any alert delivery, preventing premature or duplicate notifications after a failed cron store write. Release note: cron failure alerts no longer fire for rolled-back run outcomes.
@steipete
steipete marked this pull request as ready for review August 2, 2026 20:56
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. 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, 5:01 PM ET / 21:01 UTC.

ClawSweeper review

What this changes

Moves cron failure-alert delivery to a post-persistence notification queue so operators only receive alerts for cron outcomes that were durably stored.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this PR open for normal maintainer merge review. Current main still emits cron failure alerts during outcome mutation before persistOrRestore completes; this branch moves delivery behind the durable-write boundary while preserving cooldown state atomically, and the source review found no discrete correctness defect in the patch.

Priority: P2
Reviewed head: 2c1a8d00c291c4b4e02b222dcb41360f18b7bf5a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused, source-consistent repair with targeted rollback and ordering coverage; it needs only normal current-base CI completion before merge.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-labeled cron repair with focused persistence-boundary regression coverage in the PR body; the external-contributor real-behavior-proof gate is not applicable.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-labeled cron repair with focused persistence-boundary regression coverage in the PR body; the external-contributor real-behavior-proof gate is not applicable.
Evidence reviewed 6 items Current-main defect: Current main calls maybeEmitFailureAlert from applyJobResult while the enclosing outcome finalizer persists later, so the alert can escape before a failed write triggers rollback.
Current-main persistence boundary: persistOrRestore restores the cron-store snapshot on a failed write and only drains deferred notifications after successful persistence, establishing the appropriate owner boundary for this repair.
Patch repair path: The branch records lastFailureAlertAtMs during mutation, snapshots the job and resolved route for delivery, and appends the actual notification only to the deferred queue.
Findings None None.
Security None None.

How this fits together

The cron service finalizes completed and manual runs by updating job state, recording failure-alert cooldowns, and persisting the cron store. Those finalized outcomes can then notify operators through configured alerts, system events, webhooks, or heartbeat requests.

flowchart LR
  A[Cron run outcome] --> B[Update job outcome state]
  B --> C[Resolve alert and record cooldown]
  C --> D[Persist cron store]
  D --> E[Drain post-persist notifications]
  E --> F[Alert routes and system events]
Loading

Before merge

  • Add real behavior proof - Not applicable: This is a maintainer-labeled cron repair with focused persistence-boundary regression coverage in the PR body; the external-contributor real-behavior-proof gate is not applicable.
  • Resolve merge risk (P1) - GitHub reports the branch as behind current main; refresh the merge result and complete the pending CI checks before landing so the full cron lifecycle is validated against the current base.
Agent review details

Security

None.

PR surface

Source +25, Tests +235. Total +260 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 13 118 93 +25
Tests 4 254 19 +235
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 372 112 +260

Review metrics

None.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/cron/service/startup-run-repair.ts, unknown-data-model-change: src/cron/service/startup-run-repair.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #118187
Summary: This PR is the concrete candidate fix for the canonical report about failure alerts escaping before the cron outcome is durable.

Members:

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

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land one canonical persist-before-notify flow: decide and record cron alert cooldowns inside the outcome mutation, persist that state, then deliver the captured notification only after the write succeeds.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land one canonical persist-before-notify flow: decide and record cron alert cooldowns inside the outcome mutation, persist that state, then deliver the captured notification only after the write succeeds.

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

Yes, from source: current main invokes failure-alert delivery during applyJobResult, while the owning finalization path persists afterward and rolls state back when that write fails. The proposed regression test directly exercises the durable-write failure window, although this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. Reusing the existing post-persist notification drain repairs the violated owner boundary without changing alert policy, routing, configuration, or cooldown semantics; the by-value snapshot also prevents later mutation from altering the queued alert.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: The patch fixes an opt-in cron notification correctness defect that can otherwise produce premature or duplicate operator alerts.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer-labeled cron repair with focused persistence-boundary regression coverage in the PR body; the external-contributor real-behavior-proof gate is not applicable.

Label justifications:

  • P2: The patch fixes an opt-in cron notification correctness defect that can otherwise produce premature or duplicate operator alerts.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer-labeled cron repair with focused persistence-boundary regression coverage in the PR body; the external-contributor real-behavior-proof gate is not applicable.

Evidence

What I checked:

  • Current-main defect: Current main calls maybeEmitFailureAlert from applyJobResult while the enclosing outcome finalizer persists later, so the alert can escape before a failed write triggers rollback. (src/cron/service/timer-outcomes.ts:146, b35b8e286df0)
  • Current-main persistence boundary: persistOrRestore restores the cron-store snapshot on a failed write and only drains deferred notifications after successful persistence, establishing the appropriate owner boundary for this repair. (src/cron/service/store.ts:310, b35b8e286df0)
  • Patch repair path: The branch records lastFailureAlertAtMs during mutation, snapshots the job and resolved route for delivery, and appends the actual notification only to the deferred queue. (src/cron/service/failure-alerts.ts:261, 2c1a8d00c291)
  • Sibling completion coverage: The branch passes the generic deferred queue through stored-run finalization, removed-job finalization, manual-run completion, startup recovery, external stream failures, invalid persisted manual-run skips, and scheduling maintenance before using the common post-persist drain. (src/cron/service/timer-outcome-finalization.ts:134, 2c1a8d00c291)
  • History provenance: The adjacent durable-notification mechanism was introduced by the earlier cron auto-disable change, which is reachable from current main; this PR generalizes that same mechanism to failure alerts. (src/cron/service/store.ts:329, 08d0952df24a)
  • Validation supplied by author: The PR body reports focused persistence, routing, finalization, startup-repair, stream-validation, and regression coverage, including persistence-failure rollback and cooldown-deduplication cases; GitHub’s remaining checks should still complete on the current merge head. (src/cron/service/failure-alerts.persistence.test.ts:1, 2c1a8d00c291)

Likely related people:

  • steipete: Peter Steinberger authored the preceding cron auto-disable durability mechanism and has the strongest central-file history in the cron alert, outcome, and persistence paths. (role: feature owner and recent area contributor; confidence: high; commits: 08d0952df24a, d45e024dcabf, fc44e18e5e7d; files: src/cron/service/failure-alerts.ts, src/cron/service/timer-outcomes.ts, src/cron/service/store.ts)
  • Vincent Koc: Current-main blame attributes the existing failure-alert implementation and cooldown logic to the nearby cron work introduced in commit 1704ea5918. (role: recent adjacent contributor; confidence: medium; commits: 1704ea591820; files: src/cron/service/failure-alerts.ts)

Rank-up moves

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

  • Rebase or refresh the merge result against current main and let the pending required checks finish.

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 0fb28af into main Aug 2, 2026
183 of 199 checks passed
@steipete
steipete deleted the codex/cron-alert-post-persist branch August 2, 2026 21:08
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 2, 2026
* origin/main:
  feat(gateway): track event-loop degradation persistence and add concurrency benchmark (#118193)
  fix(config): preserve secret ownership when configuration rows move (#118149)
  fix(cron): deliver failure alerts after persistence (#118200)
  chore(lint): clear 172 lint:all baseline violations in five batches (#118098)
  perf(gateway): remove streaming hot-path rescans (#118192)
  test(gateway): use in-memory task registry (#118191)
  test(macos): fix three races in the bounded process suites (#118196)
  refactor(migrate-hermes): consolidate test fixtures (#118182)
  test(android): share Wear transport fixtures (#118177)
  test(ui): deduplicate control UI e2e setup (#118180)
  fix(plugins): unblock prerelease validation (#118103)
  test(cli): reduce redundant process launches (#118141)
  test(gateway): compact terminal observer fixtures (#118179)
  fix(agents): make requested threads sidebar-visible (#118073)
  test(plugins): canonicalize native resolver fixtures (#118174)
  test: deduplicate agent runner fixtures (#118176)
  refactor(policy): consolidate doctor test fixtures (#118173)
  fix(plugins): remove disabled channel plugin configuration on uninstall (#118127)
  refactor(matrix): consolidate monitor test fixtures (#118175)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
Fixes openclaw#118187. Failure-alert cooldown state now commits with the run outcome before any alert delivery, preventing premature or duplicate notifications after a failed cron store write. Release note: cron failure alerts no longer fire for rolled-back run outcomes.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 3, 2026
* origin/main:
  feat(gateway): track event-loop degradation persistence and add concurrency benchmark (openclaw#118193)
  fix(config): preserve secret ownership when configuration rows move (openclaw#118149)
  fix(cron): deliver failure alerts after persistence (openclaw#118200)
  chore(lint): clear 172 lint:all baseline violations in five batches (openclaw#118098)
  perf(gateway): remove streaming hot-path rescans (openclaw#118192)
  test(gateway): use in-memory task registry (openclaw#118191)
  test(macos): fix three races in the bounded process suites (openclaw#118196)
  refactor(migrate-hermes): consolidate test fixtures (openclaw#118182)
  test(android): share Wear transport fixtures (openclaw#118177)
  test(ui): deduplicate control UI e2e setup (openclaw#118180)
  fix(plugins): unblock prerelease validation (openclaw#118103)
  test(cli): reduce redundant process launches (openclaw#118141)
  test(gateway): compact terminal observer fixtures (openclaw#118179)
  fix(agents): make requested threads sidebar-visible (openclaw#118073)
  test(plugins): canonicalize native resolver fixtures (openclaw#118174)
  test: deduplicate agent runner fixtures (openclaw#118176)
  refactor(policy): consolidate doctor test fixtures (openclaw#118173)
  fix(plugins): remove disabled channel plugin configuration on uninstall (openclaw#118127)
  refactor(matrix): consolidate monitor test fixtures (openclaw#118175)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Cron failure alerts fire before the run outcome is durable (pre-persist delivery, cooldown rollback)

1 participant