Skip to content

fix(cron): on-exit watcher retries transient failures instead of silently dropping the watch - #120023

Merged
steipete merged 3 commits into
mainfrom
steipete/cron-exit-watcher-retry
Aug 7, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/cron-exit-watcher-retry

Conversation

@steipete

@steipete steipete commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where a cron on-exit job could silently never fire: if the process supervisor failed while spawning the watcher child or run.wait() rejected (supervisor restart, transient resource error), the watcher slot was released with only a warn log. No state was recorded on the job, no retry happened, and the operator saw a job that just never triggered — the worst bug class per repo doctrine (action ends with no visible outcome and no recorded reason).

Why This Change Was Made

The watcher is the lifecycle owner of the watch, so the repair lives there: spawn and wait failures now route through a scheduleRetry path that records lastError/consecutiveErrors on the job state (persisted through the gateway cron service via cron.update) and re-arms the watch with bounded backoff (1s → 5s → 30s → 5m). Cancellation clears any pending retry timer so hot-reload/removal semantics are unchanged. Fail-closed behavior on unknown exit outcomes is preserved — retries never fire the job.

User Impact

on-exit cron jobs survive transient supervisor failures instead of silently dying, and openclaw cron state shows the failure reason while retrying.

Evidence

  • node scripts/run-vitest.mjs src/gateway/cron-exit-watchers — 17 tests pass, including two new regression tests: wait-rejection retries with recorded state and no fire; spawn-failure retries then stops cleanly on cancel.
  • node scripts/run-vitest.mjs src/gateway/server-cron — 64 tests pass with the updateWatcherState wiring.
  • Codex autoreview (gpt-5.6-sol, high) over the change bundle: clean, no actionable findings.

@steipete
steipete marked this pull request as ready for review August 6, 2026 19:00
@steipete steipete closed this Aug 6, 2026
@steipete steipete reopened this Aug 6, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 6, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 6, 2026
@clawsweeper

clawsweeper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 7, 2026, 4:49 AM ET / 08:49 UTC.

ClawSweeper review

What this changes

The PR adds bounded retries and recorded error state when an on-exit cron watcher cannot spawn or wait for its supervised process.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this maintainer PR open: its retry design addresses the silent watcher drop, but the new cron-state bridge still converts every durable write failure into a stale-watcher no-op.

Priority: P2
Reviewed head: 8d5dce06604bcc25109393b4eadd5418770d4740

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The retry repair is well-scoped, but one concrete persistence-boundary blocker remains.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the reported focused tests remain useful supplemental evidence.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the reported focused tests remain useful supplemental evidence.
Evidence reviewed 4 items PR-head persistence catch: The new state-update bridge catches every rejection from the cron update and returns undefined, so it cannot distinguish stale identity from a failed durable write.
Cron update contract: The precondition runs before persistUpdatedJob; a persistence failure can therefore reject after identity validation has passed.
Watcher outcome: The watcher logs failed state persistence only when updateWatcherState rejects; swallowing the service rejection lets retry continue without that operator-visible failure.
Findings 1 actionable finding [P2] Preserve watcher-state persistence errors
Security None None.

How this fits together

Gateway cron creates an on-exit watcher for a process and fires the job after a known exit. The watcher records failure state through the cron service before retrying, so the service boundary must distinguish a replaced job from failed persistence.

flowchart LR
  Job[On-exit cron job] --> Watcher[Gateway process watcher]
  Watcher --> Supervisor[Process supervisor]
  Supervisor --> Outcome[Exit or transient failure]
  Outcome --> State[Cron service state update]
  State --> Retry[Backoff retry]
  Outcome --> Fire[Fire cron job]
Loading

Before merge

  • Preserve watcher-state persistence errors (P2) - This bare catch treats every updateWithPrecondition rejection as a replaced watcher. A durable write can fail after the identity predicate passes, so the watcher neither records nor logs that failure and still schedules a retry. Return a distinct stale result or catch only a typed stale error, then add a Gateway-boundary regression for a post-predicate persistence rejection.
  • Resolve merge risk (P1) - Merging as written can hide a real cron-store persistence failure while continuing retries, recreating an on-exit job path without recorded operator-visible failure state.
  • Complete next step (P2) - A narrow, mechanical service-boundary repair can resolve the remaining P2 finding without changing product direction.

Findings

  • [P2] Preserve watcher-state persistence errors — src/gateway/server-cron.ts:1172-1175
Agent review details

Security

None.

PR surface

Source +79, Tests +48. Total +127 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 93 14 +79
Tests 1 51 3 +48
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 144 17 +127

Review metrics

Metric Value Why it matters
Production versus test delta production +93/-14, tests +51/-3 The added lifecycle behavior is bounded and justified by the retry owner boundary, but the new tests do not exercise a durable Gateway cron write failure.

Merge-risk options

Maintainer options:

  1. Preserve durable update failures (recommended)
    Catch only a typed stale-identity outcome and let genuine cron-store update failures reject so the watcher logs them before retrying.

Technical review

Best possible solution:

Represent stale watcher replacement distinctly at the cron-service boundary, rethrow all other update failures, and prove both outcomes through the Gateway service boundary.

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

Yes, from source: make cron persistence reject after the update precondition succeeds; the current catch returns a stale-like no-op instead of allowing the watcher to log the write failure.

Is this the best way to solve the issue?

No. Retrying at the watcher is the right owner boundary, but stale identity needs a typed result or narrow catch; a blanket catch at the service boundary hides unrelated durable failures.

Full review comments:

  • [P2] Preserve watcher-state persistence errors — src/gateway/server-cron.ts:1172-1175
    This bare catch treats every updateWithPrecondition rejection as a replaced watcher. A durable write can fail after the identity predicate passes, so the watcher neither records nor logs that failure and still schedules a retry. Return a distinct stale result or catch only a typed stale error, then add a Gateway-boundary regression for a post-predicate persistence rejection.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: The defect is a localized Gateway cron lifecycle failure that can leave an on-exit job retrying without accurate failure reporting.
  • merge-risk: 🚨 availability: The broad catch can suppress a cron-store failure and make a scheduled on-exit action remain unavailable without its promised recorded state.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the reported focused tests remain useful supplemental evidence.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/gateway/server-cron.
  • [P1] node scripts/run-vitest.mjs src/gateway/cron-exit-watchers.

What I checked:

Likely related people:

  • Cameron Beeley: History identifies this contributor with the commit that introduced on-exit cron behavior; shallow history prevents stronger ownership attribution. (role: feature introducer; confidence: medium; commits: 68bfa42b9bfc; files: src/gateway/cron-exit-watchers.ts)

Rank-up moves

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

  • Preserve non-stale cron update failures instead of swallowing them.
  • Add a Gateway/service-boundary regression covering both stale replacement and post-predicate durable-write rejection.

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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-08-07T01:33:49.962Z sha 28ac833 :: needs changes before merge. :: [P1] Guard watcher failure writes against replaced cron jobs
  • reviewed 2026-08-07T06:34:57.978Z sha 3777db8 :: needs changes before merge. :: [P2] Preserve durable watcher-state write failures
  • reviewed 2026-08-07T06:52:42.896Z sha 3777db8 :: found issues before merge. :: [P2] Preserve durable watcher-state write failures

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 7, 2026
@steipete

steipete commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

A transient supervisor failure while arming or waiting on an on-exit watch
previously dropped the watch with only a log line: the job would never fire
and nothing recorded why. Failures now persist lastError/consecutiveErrors on
job state via the gateway cron service and re-arm with bounded backoff
(1s/5s/30s/5m); cancel clears any pending retry timer.
ClawSweeper P1: an old watcher's failure write could land on a job that was
edited or converted to a different schedule, pushing the replacement into
failure backoff or auto-disable. Watcher-state persistence now uses the same
identity precondition as persistCompletion (enabled, on-exit, updatedAtMs
match) and treats a mismatch as a no-op.
@steipete
steipete force-pushed the steipete/cron-exit-watcher-retry branch from 3777db8 to 8d5dce0 Compare August 7, 2026 08:22
@steipete
steipete merged commit 44a5c40 into main Aug 7, 2026
529 of 535 checks passed
@steipete
steipete deleted the steipete/cron-exit-watcher-retry branch August 7, 2026 10:56
@steipete

steipete commented Aug 7, 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 8, 2026
…ntly dropping the watch (openclaw#120023)

* fix(cron): retry on-exit watcher spawn/wait failures with backoff

A transient supervisor failure while arming or waiting on an on-exit watch
previously dropped the watch with only a log line: the job would never fire
and nothing recorded why. Failures now persist lastError/consecutiveErrors on
job state via the gateway cron service and re-arm with bounded backoff
(1s/5s/30s/5m); cancel clears any pending retry timer.

* chore: re-fire CI

* fix(cron): guard watcher-state writes against replaced on-exit jobs

ClawSweeper P1: an old watcher's failure write could land on a job that was
edited or converted to a different schedule, pushing the replacement into
failure backoff or auto-disable. Watcher-state persistence now uses the same
identity precondition as persistCompletion (enabled, on-exit, updatedAtMs
match) and treats a mismatch as a no-op.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant