Repository navigation
fix(cron): deliver failure alerts only after persistence - #118200
Conversation
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.
|
Codex review: needs real behavior proof before merge. Reviewed August 2, 2026, 5:01 PM ET / 21:01 UTC. ClawSweeper reviewWhat this changesMoves cron failure-alert delivery to a post-persistence notification queue so operators only receive alerts for cron outcomes that were durably stored. Merge readinessKeep this PR open for normal maintainer merge review. Current main still emits cron failure alerts during outcome mutation before Priority: P2 Review scores
Verification
How this fits togetherThe 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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +25, Tests +235. Total +260 across 17 files. View PR surface stats
Review metricsNone. Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest 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 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
* 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)
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.
* 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)
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
lastFailureAlertAtMsrecording 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, andpostPersistNotificationsvocabulary 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 andincludeSkippedalerts, 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 manualautomations run --waitfailures:lastFailureAlertAtMsrecorded 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.mode: "webhook", loopback listener): structured log showscron: failure alert webhook blocked by SSRF guardfor 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 -con 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.