Skip to content

fix(cron): honor failure alert thresholds - #126483

Merged
steipete merged 3 commits into
mainfrom
steipete/pensive-kalam-d40546
Aug 20, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/pensive-kalam-d40546

Conversation

@steipete

@steipete steipete commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where a failing automation could send ⚠️ Automation "name" failed after every run even when failureAlert.after, cooldownMs, or failureAlert: false should have suppressed it. A 60-second monitor produced 21 messages during the reported incident.

Why This Change Was Made

Cron finalization is now the single owner of execution-failure, required-delivery-failure, threshold, cooldown, route, recovery, and auto-disable notification decisions. Gateway code only transports scheduler-authorized alerts and completion webhooks. Explicit failure destinations remain route overrides; operator opt-outs and best-effort semantics are honored without duplicate policy.

The ownership split became possible when repeated failure alerts (commit 4637b90 / #24789, 2026-03-01, code author @0xbrak) and per-run failure destinations (#31059, 2026-03-02, author Evgeny Zislis) remained separate owners. The Gateway dispatcher was later split into its own module by 85148f3 on 2026-04-27 by Peter Steinberger. This is provenance, not an assignment of blame.

User Impact

Operators get one comprehensible failure-alert policy instead of per-run floods plus separate threshold alerts. Route-backed jobs default to an alert after two consecutive failures with a one-hour cooldown; per-job/global tuning, disablement, skipped-run opt-in, delivery-only failures, and auto-disable recovery remain visible and deterministic.

Evidence

  • Pre-fix boundary regression: expected one request but observed 23 (21 failed runs plus two failureAlert: false runs).
  • Post-fix real CronService→Gateway HTTP boundary: 21 failed runs yield exactly one failed 2 times request; the disabled job yields none; all 21 durable history rows remain.
  • node scripts/run-vitest.mjs src/cron/cron-delivery-outcomes.e2e.test.ts --reporter=verbose — 1 file, 6 tests passed.
  • node scripts/run-vitest.mjs src/cron/delivery-plan.test.ts src/cron/delivery.failure-notify.test.ts src/cron/delivery.test.ts src/cron/service.delivery-plan.test.ts src/cron/service.failure-alert.test.ts src/cron/service/failure-alerts.account-routing.test.ts src/cron/service/failure-alerts.persistence.test.ts src/cron/service.persists-delivered-status.test.ts src/cron/service/ops.test.ts src/cron/service/run-recovery.test.ts src/cron/service/startup-run-repair.auto-disable.test.ts src/cron/service/timer.regression.test.ts --reporter=verbose — 12 files, 270 tests passed.
  • node scripts/run-vitest.mjs src/gateway/server-cron-notifications.presentation.test.ts src/gateway/server-cron-notifications.test.ts src/gateway/server-cron.test.ts src/gateway/server.cron.test.ts src/gateway/server-methods/cron.validation.test.ts --reporter=dot — 5 files, 322 tests passed.
  • node scripts/run-vitest.mjs src/cron/service/timer.timeout-watchdog.test.ts -t 're-arms the pre-execution watchdog when before_agent_reply does not claim' --reporter=verbose — 1 focused test passed; the exact alternate-route thread-isolation fact is asserted.
  • pnpm prompt:snapshots:check — current (7 files).
  • pnpm check:docs — passed formatting, Markdown/MDX, glossary, 6,524 internal links, and 1,180 validated config examples.
  • git diff --name-only -z 4970ed235782782ef2373aeebfae266be48a78a1...HEAD | xargs -0 node scripts/check-changed.mjs --base 4970ed235782782ef2373aeebfae266be48a78a1 --head HEAD -- — passed all selected core, core-test, docs, and tooling gates.
  • AGENTS_HOME="$HOME/.claude" "$HOME/.claude/skills/autoreview/scripts/autoreview" --mode branch --base origin/main — clean, no accepted/actionable findings.
  • Production: +392/−523 (net −131). Tests: +651/−937. Prompt snapshots/test support: +15/−15. Docs: +32/−14.

Live Discord proof was intentionally not repeated because the defect is notification flooding. The local SSRF-guarded HTTP receiver exercises the real scheduler/Gateway transport boundary without sending external channel traffic.

AI-assisted: implemented and verified with Codex; no agent transcript is included.

Per-run Gateway announcements bypassed threshold, cooldown, and opt-out policy. Make the scheduler the sole owner of failure notification decisions.
Keep trusted failure detail proof on the scheduler-authorized transport and remove the obsolete Gateway event-context handoff after the ownership consolidation.
@clawsweeper

clawsweeper Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Aug 19, 2026
@steipete
steipete marked this pull request as ready for review August 19, 2026 23:50
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 20, 2026
@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 19, 2026, 8:05 PM ET / August 20, 2026, 00:05 UTC.

ClawSweeper review

What this changes

Moves cron failure-alert decisions into the scheduler so thresholds, cooldowns, opt-out, and configured routes are applied consistently before Gateway transport.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open: current main still sends routed cron failures through Gateway before scheduler threshold, cooldown, and opt-out policy can apply. The PR correctly moves that decision to the scheduler; maintainers need only accept its intentional upgrade-visible alert cadence change.

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

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The patch centralizes policy at the persisted-outcome owner and has strong boundary coverage; only the intentional upgrade behavior needs acceptance.
Proof confidence 🦞 diamond lobster (5/6) Not applicable: This maintainer-authored PR includes a production-boundary E2E scenario, so the external-contributor proof gate does not apply.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR includes a production-boundary E2E scenario, so the external-contributor proof gate does not apply.
Evidence reviewed 5 items Current main bypasses policy: Current main dispatches execution and delivery failures from Gateway, while scheduler alert resolution contains the threshold/cooldown and opt-in policy; this leaves routed failures outside that policy.
Scheduler owns the repaired decision: The PR records the outcome, applies failure-alert policy, and defers only the authorized transport to Gateway.
Boundary regression coverage: The E2E test drives CronService through the Gateway webhook path, verifies 21 failures produce one thresholded alert, verifies opt-out suppresses alerts, and retains all run history.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/cron/cron-delivery-outcomes.e2e.test.ts --reporter=verbose

Result: FAIL (partial) — step 2 expect_output applies threshold and cooldown once before transporting execution failure alerts: expected terminal output was not visible within 30 seconds: "applies threshold and cooldown once before transporting execution failure alerts"

node scripts/run-vitest.mjs src/cron/cron-delivery-outcomes.e2e.test.ts --reporter=verbose
runner@runnervm76f27:/tmp/clawsweeper-live-proof-126483-FllRmB/target$ node scripts/run-vitest.mjs src/cron/cron-delivery-outcomes.e2e.test.ts --reporter=verbos
e
[test] starting test/vitest/vitest.e2e.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126483-FllRmB/target

node scripts/run-vitest.mjs src/cron/cron-delivery-outcomes.e2e.test.ts --reporter=verbose
[openclaw] Building TypeScript (dist is stale: missing_private_qa_dist - private QA dist entry missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/11 finished in 3.4s
[tsdown-build] invocation 2/11 finished in 14.7s



































Assertions:

  • FAIL expect_output: applies threshold and cooldown once before transporting execution failure alerts

How this fits together

Cron jobs record outcomes in the scheduler, which decides whether a failure warrants an alert before Gateway delivers it to a channel or webhook. The decision affects notifications while preserving run history.

flowchart LR
  A[Cron job run] --> B[Scheduler outcome record]
  B --> C[Failure-alert policy]
  C --> D{Threshold and cooldown met?}
  D -->|Yes| E[Gateway delivery]
  D -->|No| F[Recorded run history]
  E --> G[Channel or webhook alert]
Loading

Decision needed

Question Recommendation
Should existing route-backed cron jobs adopt the scheduler’s default two-failure, one-hour-cooldown policy when this PR lands? Adopt scheduler policy: Use scheduler threshold, cooldown, and opt-out rules for all failure routes, including existing inherited routes.

Why: The behavior is intentional and documented, but it changes notification cadence for already configured jobs.

Before merge

  • Resolve merge risk (P1) - Existing route-backed jobs intentionally change from per-run Gateway alerts to the scheduler’s default two-failure, one-hour-cooldown policy; global alert disablement will also suppress inherited routes.
  • Complete next step (P2) - Human confirmation is needed for the intended cadence change to existing configured failure routes; this maintainer PR is not a repair-dispatch candidate.
Agent review details

Security

None.

PR surface

Source -131, Tests -286, Docs +18. Total -399 across 35 files.

View PR surface stats
Area Files Added Removed Net
Source 13 392 523 -131
Tests 19 666 952 -286
Docs 3 32 14 +18
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 35 1090 1489 -399

Review metrics

Metric Value Why it matters
Production versus test delta production +392/-523 (net -131); tests +651/-937; docs +32/-14 The ownership consolidation is net-negative in production while adding focused scheduler and Gateway boundary coverage.
Alert default changed 1 changed default Route-backed failures move to scheduler-owned threshold and cooldown behavior for existing operators.

Stored data model

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

Merge-risk options

Maintainer options:

  1. Confirm the notification policy change (recommended)
    Merge after accepting that existing route-backed jobs now use scheduler thresholds, cooldowns, and opt-out behavior.
  2. Preserve legacy cadence
    Pause for a compatibility design if every failure must continue to alert for existing route-backed jobs.

Technical review

Best possible solution:

Land the scheduler-owned policy after explicitly accepting the documented notification-cadence change for existing configured routes.

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

Yes: source establishes that current Gateway dispatches routed failures individually, and the PR boundary test demonstrates the scheduler-gated replacement path.

Is this the best way to solve the issue?

Yes, subject to accepting the upgrade-visible cadence: the scheduler owns persisted outcomes and is the only layer able to apply threshold, cooldown, and opt-out uniformly.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The current bypass can repeatedly flood configured failure-notification routes during recurring cron failures.
  • add merge-risk: 🚨 compatibility: Existing route-backed jobs receive intentionally different alert cadence and opt-out behavior after upgrade.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR includes a production-boundary E2E scenario, so the external-contributor proof gate does not apply.

Label justifications:

  • P1: The current bypass can repeatedly flood configured failure-notification routes during recurring cron failures.
  • merge-risk: 🚨 compatibility: Existing route-backed jobs receive intentionally different alert cadence and opt-out behavior after upgrade.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR includes a production-boundary E2E scenario, so the external-contributor proof gate does not apply.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/cron/cron-delivery-outcomes.e2e.test.ts --reporter=verbose.

What I checked:

Likely related people:

  • steipete: Recent history and the PR head cover the scheduler and Gateway failure-alert owner boundary. (role: recent area contributor; confidence: high; commits: fa08c45e0ed1, a1db88b2c556; files: src/cron/service/failure-alerts.ts, src/gateway/server-cron-notifications.ts)
  • 0xbrak: The PR discussion identifies earlier failure-destination work; local historical expansion was unavailable because promisor objects required unreachable network access. (role: earlier related feature contributor; confidence: medium; commits: 4637b90c070; files: src/cron/service/failure-alerts.ts)

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

Copy link
Copy Markdown
Contributor Author

Land-ready proof for fa08c45e0ed19c795e86b45beb365c39f679fee4.

Behavior proof:

  • node scripts/run-vitest.mjs src/cron/cron-delivery-outcomes.e2e.test.ts --reporter=verbose — 6/6 passed. The real CronService→Gateway SSRF-guarded HTTP boundary turns 21 failed runs into exactly one failed 2 times alert, suppresses the failureAlert: false job, and retains all 21 durable history rows.
  • node scripts/run-vitest.mjs src/cron/delivery-plan.test.ts src/cron/delivery.failure-notify.test.ts src/cron/delivery.test.ts src/cron/service.delivery-plan.test.ts src/cron/service.failure-alert.test.ts src/cron/service/failure-alerts.account-routing.test.ts src/cron/service/failure-alerts.persistence.test.ts src/cron/service.persists-delivered-status.test.ts src/cron/service/ops.test.ts src/cron/service/run-recovery.test.ts src/cron/service/startup-run-repair.auto-disable.test.ts src/cron/service/timer.regression.test.ts --reporter=verbose — 270/270 passed.
  • node scripts/run-vitest.mjs src/gateway/server-cron-notifications.presentation.test.ts src/gateway/server-cron-notifications.test.ts src/gateway/server-cron.test.ts src/gateway/server.cron.test.ts src/gateway/server-methods/cron.validation.test.ts --reporter=dot — 322/322 passed.
  • node scripts/run-vitest.mjs src/cron/service/timer.timeout-watchdog.test.ts -t 're-arms the pre-execution watchdog when before_agent_reply does not claim' --reporter=verbose — 1/1 passed and requires inheritSessionThread: false for the alternate failure route.

Gates and review:

  • pnpm prompt:snapshots:check — current (7 files).
  • pnpm check:docs — passed formatting, Markdown/MDX, glossary, 6,524 internal links, and 1,180 validated config examples.
  • Frozen-base changed gate passed all selected core, core-test, docs, and tooling checks: git diff --name-only -z 4970ed235782782ef2373aeebfae266be48a78a1...HEAD | xargs -0 node scripts/check-changed.mjs --base 4970ed235782782ef2373aeebfae266be48a78a1 --head HEAD --.
  • Fresh branch autoreview completed clean with no accepted/actionable findings after the final CI correction.
  • Exact-head pull-request CI run 32315408482 is green. The prior run found one stale strict watchdog expectation; fa08c45e0ed strengthened it to assert alternate-route thread isolation.
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 126483 passed at the exact head in hosted_exact_or_recent_parent mode at 2026-08-20 00:24 UTC. It reused exact-head hosted CI, so no separate remote Testbox lease was allocated.

ClawSweeper handling:

  • The completed exact-head review reported no actionable code or security findings and rated the implementation/proof 5/6.
  • Maintainer owner decision: accept the intentional upgrade-visible change for existing route-backed jobs. The scheduler's default two-failure threshold, one-hour cooldown, and opt-out semantics now apply uniformly; preserving per-run legacy cadence would preserve the flooding bug.
  • The review's 30-second live-proof wrapper timed out while the one-time stale dist build was still progressing. The same exact command completed locally with 6/6 passing, and exact-head CI is green.
  • No schema/version/data-model migration is introduced. Existing persisted alert fields keep their shape; only the lifecycle owner that writes and replays them changes.

Diff accounting: production +392/−523 (net −131); tests +651/−937; prompt snapshots/test support +15/−15; docs +32/−14.

Live Discord proof was intentionally not repeated because the defect is notification flooding. The local guarded HTTP receiver exercises the real scheduler/Gateway transport boundary without sending external channel traffic.

@steipete
steipete merged commit 177828a into main Aug 20, 2026
233 of 234 checks passed
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete
steipete deleted the steipete/pensive-kalam-d40546 branch August 20, 2026 00:25
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 20, 2026
* fix(cron): honor failure alert thresholds

Per-run Gateway announcements bypassed threshold, cooldown, and opt-out policy. Make the scheduler the sole owner of failure notification decisions.

* fix(cron): preserve safe failure details

Keep trusted failure detail proof on the scheduler-authorized transport and remove the obsolete Gateway event-context handoff after the ownership consolidation.

* test(cron): assert alternate failure route isolation
Rorqualx pushed a commit to Rorqualx/cortex that referenced this pull request Aug 21, 2026
Re-integrate upstream/main (base a3ca846 → tip 784a228, 266 commits) into the
cortex fork. Conflict resolution + keystone reconciliation summary in
RESYNC_LEDGER.md.

Foundation (lead-owned): MCP fence ENHANCE (fence sanitized publicValue + fix a
latent _meta-leak), openshell buildRemoteCommand union-trap → adopt upstream
extraction, cron completion-announce grafted onto upstream openclaw#126483 failure-
threshold rewrite, memory-core prompt-section KEEP-OURS, ui/package.json union.

Gateway/protocol second pass (split-brain repair): grafted upstream's GitHub-
identity schemas; re-grafted 37 dropped methods (openclaw#118232) + placement scopes +
handler wiring; method-scope drift (config.schema/fs.listDir/worktrees.create,
sessions.groups.*, skills.forge.*); embedded-agent type extensions;
agentHarnessStructuredInput SDK export; resolved-v1 provenance;
AgentToolResult<unknown>; cron-trigger-filter; exec-approval; copyImage icon.

GitHub-identity (adopt fully): core adopted + working; UI ported to ui/src/ui
(compiles + unit-tested); app-shell live-wire + runExternalMutation + visual
verification are the documented land-time step.

Agent-loop (merge + restore fork features): restored the fork's tool mutation-
tracking + recovery cluster (20 files) to fork-main; grafted upstream's clean
before-tool-call owner-arg change; deferred upstream intentionalTermination
hardening as a follow-up.

UI divergence: fork owns ui/src/ui; upstream's ui/src/pages restructure not
adopted (184 files kept-deleted). i18n kept-ours (fork en.ts superset).

Verification: tsgo core/extensions/test:ui/test:packages = 0 (zero new errors;
core:test/extensions:test residuals proven identical to fork-main baseline).
Behavior: cron, mcp, memory-core, agent-loop mutation-recovery green (merge
regressions fixed). Pending land-time: Linux build + behavior proof + autoreview
+ GitHub-identity UI wiring/visual.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XL 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.

1 participant