Skip to content

fix(cron): keep future jobs running after startup catch-up fails - #159086

Merged
obviyus merged 2 commits into
mainfrom
fix/cron-catchup-rearm-158969
Sep 26, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/cron-catchup-rearm-158969

Conversation

@obviyus

@obviyus obviyus commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #158969. Related: #144144.

What Problem This Solves

Fixes future cron jobs never firing after a startup catch-up job encounters a transient store write failure.

User Impact

Once the write fault clears, future scheduled jobs can run without restarting the Gateway or editing a job. The startup failure remains visible. No configuration, schema, or default changes.

Why This Change Was Made

The startup lifecycle owner now arms scheduling when catch-up rejects, then rethrows the original failure, reporting any secondary arming error separately. Failed-start scheduling stays resumable through Gateway suspension; the lazy proxy delegates readiness to the service after any start attempt. Existing stop, pause, and lifecycle-generation fences remain in force. Normal startup ordering is unchanged; existing run-recovery logic settles the completed catch-up job without replaying it.

Evidence

  • Real CronService.start() with SQLite persistence: a trigger rejects the overdue job's terminal write, startup rejects, and the trigger is removed before a later job becomes due. On the baseline the later event never arrives; with the fix both jobs deliver exactly once. The normal-start control passes on both versions.
  • Wall-clock candidate probe: overdue event at 1536 ms, startup rejects with injected terminal write failure, fault removed, upcoming event at 12018 ms; delivered events are exactly ["overdue", "upcoming"].
  • Focused startup/suspension, lazy Gateway, interval firing, and batch-finalization suites: 62 tests passed. The new three-case regression took 1.38 seconds of test time. Normal startup, terminal-write failure, and a second arming failure all deliver each event once after pause/resume. The suspension regression failed on the first candidate before the lifecycle repair.
  • Scoped Oxlint and touched-file TypeScript language-server diagnostics passed.
  • Fresh pnpm build passed; an isolated Gateway boot reached ready on a non-default loopback port. Full Gateway fault injection was not proven: a preinstalled trigger was correctly rejected by schema admission, and a post-admission preload did not reach the worker-owned write. The discriminating failure/recovery proof above uses the real CronService entry point, not a complete faulted Gateway boot.
  • Final wall-clock suspension probe: startup reports the injected write error, the fault is removed, scheduling is paused/resumed, and the future event arrives at 12026 ms without replaying the overdue event.
  • Required CI passed at 3fef502f8eae6604bbc19a398a91e6a8da917bec with no reruns. The three new regression cases took 1.211 seconds total in the hosted cron shard.

Published-updater compatibility

Package Acceptance run 36262657810 passed the existing published-upgrade-survivor / legacy-operator-state cell: published [email protected] updated to the candidate built from 3fef502f8eae6604bbc19a398a91e6a8da917bec (tarball SHA-256 8b82f19f0bb40525dd512691d12c0bbf71ef1df8c371323fe271e466a973b57f). It retained two CLI-authored cron jobs and their history, verified the original owners after migration, and passed Gateway startup, health, readiness, status, and clean Doctor checks. A second update was already-current with no package mutations or repair.

This cell proves upgrade compatibility with retained cron state. Its jobs are deliberately disabled; it does not inject the startup write fault or prove later scheduled delivery. Faulted-startup/future-fire behavior is proved separately by the real CronService wall-clock runs and the real CronService plus Gateway-proxy regression above. The existing published-driver upgrade harness has no startup write-fault injection hook.

@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@obviyus
obviyus marked this pull request as ready for review September 26, 2026 18:04
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 3:16 PM ET / 19:16 UTC (Revision 3).

ClawSweeper review

What this changes

Cron startup arms future scheduling after catch-up fails, and the lazy Gateway cron wrapper resumes it after suspension; a SQLite-backed regression test covers the flow.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main still skips timer arming when startup catch-up rejects. The proposed repair addresses that path, and the exact-head published-updater run answers the previous review’s compatibility request. I found no blocking patch defect.

Priority: P1
Reviewed head: 3fef502f8eae6604bbc19a398a91e6a8da917bec

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused lifecycle changes have strong real-store recovery proof and exact-head upgrade validation, with no blocking finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The captured before/after terminal trace exercises the real CronService with SQLite and a transient terminal-write fault: the later job fires after the fix. The regression also covers suspension through the lazy Gateway wrapper, while an exact-head published-updater cell checks retained cron state separately. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The captured before/after terminal trace exercises the real CronService with SQLite and a transient terminal-write fault: the later job fires after the fix. The regression also covers suspension through the lazy Gateway wrapper, while an exact-head published-updater cell checks retained cron state separately. No stored-data contract changes.
Evidence reviewed 8 items Current-main defect: Current main awaits catch-up before entering the block that reloads the store and arms the timer; a catch-up rejection skips that block.
Introduced lifecycle repair: The catch-up error is retained and rethrown after an attempt to arm scheduling; the stopped and lifecycle-generation guards remain in place.
Suspension path: After a start attempt, the lazy wrapper delegates scheduling resume to the cron service even if that start rejected.
Findings None None.
Security None None.

How this fits together

The Gateway starts the cron service, which catches up overdue jobs from its SQLite-backed store and arms a timer for future jobs. The lazy Gateway wrapper controls startup and suspension around that service.

flowchart LR
  A[Gateway startup] --> B[Lazy cron wrapper]
  B --> C[Overdue job catch-up]
  C --> D{Catch-up result}
  D --> E[Report startup error]
  D --> F[Arm future timer]
  F --> G[Deliver scheduled jobs]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +9, Tests +110. Total +119 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 30 21 +9
Tests 1 110 0 +110
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 140 21 +119

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #158969
Summary: This PR is the open candidate repair for the canonical startup catch-up defect; the earlier candidate closed unmerged.

Members:

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

Technical review

Best possible solution:

A failed catch-up should remain visible while the cron service keeps future jobs scheduled and can resume them after Gateway suspension.

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

Yes. The related report gives a real CronService and SQLite-trigger reproduction, and current-main source still has the catch-up-before-arm ordering; this read-only review did not rerun it.

Is this the best way to solve the issue?

Yes. The patch repairs the cron lifecycle owner and its Gateway suspension wrapper without adding a competing scheduler, configuration option, or stored-data format.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P1: A transient startup write failure can otherwise leave future scheduled jobs undelivered for the Gateway process lifetime.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The captured before/after terminal trace exercises the real CronService with SQLite and a transient terminal-write fault: the later job fires after the fix. The regression also covers suspension through the lazy Gateway wrapper, while an exact-head published-updater cell checks retained cron state separately. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured before/after terminal trace exercises the real CronService with SQLite and a transient terminal-write fault: the later job fires after the fix. The regression also covers suspension through the lazy Gateway wrapper, while an exact-head published-updater cell checks retained cron state separately. No stored-data contract changes.

Evidence

What I checked:

  • Current-main defect: Current main awaits catch-up before entering the block that reloads the store and arms the timer; a catch-up rejection skips that block. (src/cron/service/ops-lifecycle.ts:246, cafb3a4d1ca2)
  • Introduced lifecycle repair: The catch-up error is retained and rethrown after an attempt to arm scheduling; the stopped and lifecycle-generation guards remain in place. (src/cron/service/ops-lifecycle.ts:251, 3fef502f8eae)
  • Suspension path: After a start attempt, the lazy wrapper delegates scheduling resume to the cron service even if that start rejected. (src/gateway/server-cron-lazy.ts:248, 3fef502f8eae)
  • Regression coverage: The new test injects a terminal SQLite write failure, removes the fault, suspends and resumes scheduling, and checks that the later event is delivered once. (src/cron/service/ops-lifecycle.start-arm.test.ts:79, 3fef502f8eae)
  • Reported real behavior proof: The captured PR body reports a before/after wall-clock run through the real CronService and SQLite store: after the injected write fault clears, the upcoming event fires with this patch. It separately states that a complete faulted Gateway boot was not proven. (3fef502f8eae)
  • Published-updater compatibility: Package Acceptance succeeded at the exact PR head in the published-upgrade-survivor lane. The captured PR body reports retention of existing cron jobs and history; those upgrade-cell jobs were disabled, so delivery is supported by the separate fault-recovery proof. (3fef502f8eae)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (2 earlier review cycles)
  • reviewed 2026-09-26T18:11:40.752Z sha 6233e60 :: blocked before merge. :: [P2] Resume the timer after suspension of a failed start | [P2] Preserve the catch-up error if timer arming also fails
  • reviewed 2026-09-26T18:26:12.576Z sha 3fef502 :: blocked before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Sep 26, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 26, 2026
@obviyus

obviyus commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review. Published-updater compatibility is now verified at the unchanged head by Package Acceptance run 36262657810: [email protected] to candidate, retained cron jobs/history, Gateway readiness and clean Doctor. The body explicitly separates this upgrade cell from the real CronService/Gateway-proxy fault-recovery proof.

@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper assist is taking a look at your question.

I queued a lightweight read-only assist pass. It will post a separate answer comment and will not edit the durable ClawSweeper review comment or trigger close, merge, repair, label, or branch changes.

Request: re-review. Published-updater compatibility is now verified at the unchanged head by Package Acceptance run 36262657810: [email protected] to candidate, retained cron jobs/history, Gateway readiness and clean Doctor. The body explicitly separates this upgrade cell from the real CronService/Gateway-proxy fault-recovery proof.

@clawsweeper

clawsweeper Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper assist: The unchanged head now has published-updater compatibility evidence, but the upgrade cell used disabled jobs, so it does not show scheduled delivery after the update. A full correctness re-review is needed.

Evidence:

  • Package Acceptance run 36262657810 passed at 3fef502f8eae6604bbc19a398a91e6a8da917bec, retaining cron jobs and history with Gateway ready and Doctor clean.
  • The PR body separately documents real CronService fault-recovery runs and says the upgrade cell did not test the startup write fault or later firing. The previous review asked for published-updater evidence that scheduled jobs continue firing.

Suggested next action: Request the full re-review with @clawsweeper review on PR #159086.


Source: #159086 (comment)
Assist reasoning: medium.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Sep 26, 2026
@obviyus
obviyus merged commit 0f5c39b into main Sep 26, 2026
247 of 249 checks passed
@obviyus
obviyus deleted the fix/cron-catchup-rearm-158969 branch September 26, 2026 19:19
@obviyus

obviyus commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 0f5c39b. Startup catch-up errors remain reported while future cron jobs stay scheduled, including after suspension. Real SQLite-trigger before/after proof showed the later job firing once after the fault cleared; 62 focused tests, exact-head CI, and the published 2026.9.4 updater with retained cron state passed. Thanks @yetval for reporting #158969 and the original investigation and repair proposal in #144144.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
…nclaw#159086)

Closes openclaw#158969. Related: openclaw#144144.

## What Problem This Solves

Fixes future cron jobs never firing after a startup catch-up job encounters a transient store write failure.

## User Impact

Once the write fault clears, future scheduled jobs can run without restarting the Gateway or editing a job. The startup failure remains visible. No configuration, schema, or default changes.

## Why This Change Was Made

The startup lifecycle owner now arms scheduling when catch-up rejects, then rethrows the original failure, reporting any secondary arming error separately. Failed-start scheduling stays resumable through Gateway suspension; the lazy proxy delegates readiness to the service after any start attempt. Existing stop, pause, and lifecycle-generation fences remain in force. Normal startup ordering is unchanged; existing run-recovery logic settles the completed catch-up job without replaying it.

## Evidence

- Real `CronService.start()` with SQLite persistence: a trigger rejects the overdue job's terminal write, startup rejects, and the trigger is removed before a later job becomes due. On the baseline the later event never arrives; with the fix both jobs deliver exactly once. The normal-start control passes on both versions.
- Wall-clock candidate probe: overdue event at 1536 ms, startup rejects with `injected terminal write failure`, fault removed, upcoming event at 12018 ms; delivered events are exactly `["overdue", "upcoming"]`.
- Focused startup/suspension, lazy Gateway, interval firing, and batch-finalization suites: 62 tests passed. The new three-case regression took 1.38 seconds of test time. Normal startup, terminal-write failure, and a second arming failure all deliver each event once after pause/resume. The suspension regression failed on the first candidate before the lifecycle repair.
- Scoped Oxlint and touched-file TypeScript language-server diagnostics passed.
- Fresh `pnpm build` passed; an isolated Gateway boot reached ready on a non-default loopback port. Full Gateway fault injection was not proven: a preinstalled trigger was correctly rejected by schema admission, and a post-admission preload did not reach the worker-owned write. The discriminating failure/recovery proof above uses the real CronService entry point, not a complete faulted Gateway boot.
- Final wall-clock suspension probe: startup reports the injected write error, the fault is removed, scheduling is paused/resumed, and the future event arrives at 12026 ms without replaying the overdue event.
- [Required CI](https://github.com/openclaw/openclaw/actions/runs/36262060415) passed at `3fef502f8eae6604bbc19a398a91e6a8da917bec` with no reruns. The three new regression cases took 1.211 seconds total in the hosted cron shard.

### Published-updater compatibility

[Package Acceptance run 36262657810](https://github.com/openclaw/openclaw/actions/runs/36262657810) passed the existing `published-upgrade-survivor` / `legacy-operator-state` cell: published `[email protected]` updated to the candidate built from `3fef502f8eae6604bbc19a398a91e6a8da917bec` (tarball SHA-256 `8b82f19f0bb40525dd512691d12c0bbf71ef1df8c371323fe271e466a973b57f`). It retained two CLI-authored cron jobs and their history, verified the original owners after migration, and passed Gateway startup, health, readiness, status, and clean Doctor checks. A second update was already-current with no package mutations or repair.

This cell proves upgrade compatibility with retained cron state. Its jobs are deliberately disabled; it does not inject the startup write fault or prove later scheduled delivery. Faulted-startup/future-fire behavior is proved separately by the real CronService wall-clock runs and the real CronService plus Gateway-proxy regression above. The existing published-driver upgrade harness has no startup write-fault injection hook.

Co-authored-by: yetval <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

cron: startup catch-up write failure leaves the scheduler unarmed

1 participant