Repository navigation
Conversation
A failed startup catch-up left the cron scheduler permanently unarmed: start() called runMissedJobs before the block that recomputes schedules and calls armTimer, so a rejected catch-up skipped the arm entirely and state.timer stayed null with stopped and schedulingPaused both false. The Gateway logged the failure, did not retry, and no scheduled job ran again for the life of the process. Fence the catch-up call so the existing recompute and armTimer block still runs, then rethrow the original catch-up error so the caller still records a failed start. A secondary arm failure is logged and never masks the catch-up error, and the startup log line reports a warning instead of cron: started when the arm followed a failed catch-up. This matches the scheduled-tick path, which already re-arms in a finally.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 11:03 AM ET / 15:03 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR lets cron arm its scheduling timer after startup catch-up fails, preserves the original error, and adds regression coverage. Merge readiness✅ Ready for maintainer review This remains a useful, focused fix: current main and the latest release retain the failure path, and the supplied production-scheduler trace demonstrates recovery. No blocking patch defects were found. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw's cron service loads persisted jobs when the Gateway starts, catches up missed runs, and arms timers for future work. Those timers dispatch scheduled jobs through the existing execution and persistence owners. flowchart TD
A[Gateway startup] --> B[Load persisted jobs]
B --> C[Catch up missed runs]
C --> D[Success or captured failure]
D --> E[Check lifecycle and arm timer]
E --> F[Future scheduled jobs]
D --> G[Return original startup error]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +24, Tests +106. Total +130 across 2 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep scheduler liveness independent of catch-up success within the existing lifecycle owner, while preserving failure reporting and stop/pause safeguards. Do we have a high-confidence way to reproduce the issue? Yes: current source exposes the failure by rejecting a startup catch-up terminal write before timer arming. The contributor supplies a matching before/after runtime trace; this review did not execute it. Is this the best way to solve the issue? Yes: the patch repairs the startup lifecycle owner and reuses existing scheduling operations without swallowing storage errors or adding competing recovery policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 81a4c771eff6. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Closing this implementation PR at the author's request and moving the unresolved defect to #158969: #158969 The follow-up report records a fresh check on main The candidate at |
…9086) 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](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]>
…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]>
Summary
One transient store failure during restart catch-up permanently disables the cron scheduler for the life of the Gateway process.
CronService.start()runs startup catch-up before it arms the scheduling timer.runMissedJobsdeliberately rejects when a startup outcome's terminal store write fails (a locked or failing SQLite write, a disk error, a finalization error). That rejection escapesstart()beforearmTimeris ever reached, sostate.timerstaysnullwhilestate.stoppedandstate.schedulingPausedare bothfalse. The Gateway catches the rejection, logscron: failed to start: ...and does not retry, and it also skipsreconcileExitWatchers/reconcileStreamWatchers. The Gateway then comes up looking healthy while no scheduled job ever fires again.cron listandcron statusstill show the jobs and their next run times. Only a cron mutation that happens to callarmTimer(add, update, enable, a manual run) or a full Gateway restart brings scheduling back.Reachability on main: Gateway boot ->
src/gateway/server-runtime-services.ts:68params.cronState.cron.start()->src/gateway/server-cron-lazy.ts:162->src/cron/service.ts:68lifecycleOps.start(this.state)->src/cron/service/ops-lifecycle.ts:187.The sibling scheduled-tick path already guarantees the opposite:
onAdmittedTimerinsrc/cron/service/timer-scheduler.ts:589re-arms inside afinally, so a tick that throws still leaves the scheduler armed.resumeSchedulingcannot heal the startup case either, because it early-returns on!state.schedulerStarted(src/cron/service/ops-lifecycle.ts:238).Related prior attempt: #68112 described the same root cause and was closed by ClawSweeper as stalled without real behavior proof. That patch was much wider (86 changed lines in the old
ops.tsplus 78 intimer.ts, including an unrelated zombie-marker detector). This one is confined to the arm boundary and carries the proof.Root cause
src/cron/service/ops-lifecycle.ts:187-212(before):runMissedJobsthrows fromsrc/cron/service/timer-catchup.ts:290and:296when a startup outcome cannot be finalized; the maintainers' ownsrc/cron/service/timer.batch-finalization.test.ts:815pins that reject contract. Because the call is unfenced, the entire recompute plusarmTimerplusresumeForeignReceiptMonitorblock is skipped. Startup catch-up already clearedstate.startupCatchupin its ownfinally, so nothing else is holding the timer down: the scheduler is simply never armed.Fix
src/cron/service/ops-lifecycle.ts(after):A failed catch-up is held, the existing arm block runs unchanged, and the original catch-up error is then rethrown so the caller still sees the failure. The arm block keeps its own
state.stoppedguard, andarmTimerindependently refuses to arm whenstate.stopped,state.schedulingPaused, orstate.startupCatchupis set, so a start that was superseded bystop()still arms nothing. A secondary arm failure is logged and never masks the catch-up error, and the success path keeps propagating an arm error as before. The startup log line is downgraded to a warning when the arm happened after a failed catch-up, socron: startednever claims a clean start.Why this is the right boundary
start()inops-lifecycle.tsis the owner of "the scheduler is armed after startup".runMissedJobsowns catch-up execution and its reject contract, and it is unchanged: it still releases reservations, still preserves overflow wake times, and still throws. Fixing this insidetimer-catchup.tswould mean swallowing a real store failure at the wrong layer.onAdmittedTimer(src/cron/service/timer-scheduler.ts:586-592) already re-arms in afinallyafter a throwing tick. Startup was the only entry point that could leave the timer down, and it is now the same shape.recomputeUnownedCronSchedules(state, { recomputeExpired: true })the success path performs, and the same maintenanceonAdmittedTimerperforms on its next tick. It makes the failure path converge one tick sooner instead of relying on the minute watchdog.schedulerStartedis deliberately left alone.CronService.startOnce(src/cron/service.ts:66-73) owns that flag and only sets it afterstart()resolves; the catch-up error still propagates, so a failed start is still recorded as a failed start andserver-cron-lazy.tsstill setsunderlyingStarted = false. Setting it totruefrom inside a rejected start would tellensureLoadedForRead(src/cron/service/ops-shared.ts:64) to stop doing read repair and would contradict the caller's own failure record. Timer-armed-while-schedulerStarted-is-false is already a state main produces:reconcileForeignRunReceiptscallsarmTimeratops-lifecycle.ts:115from the foreign-receipt monitor during start.resumeSchedulingstill early-returns on!schedulerStarted, unchanged. A suspension cycle after a failed start therefore still needs the Gateway's own retry, whichserver-cron-lazy.tsperforms (it callsresumeScheduling()and thenstart()again on the next resolve). Changing that gate is a separate lifecycle decision and is out of scope here.stop()is the only writer oflifecycleGenerationand it setsstate.stopped = truein the same call, so a superseded start cannot arm a live timer, and the timer callback keeps its own generation check attimer-scheduler.ts:148-162.cron: startedinfo line.Verification
node scripts/run-vitest.mjs src/cron/service/ops-lifecycle.start-arm.test.ts- 2 passed with the patch. The first case drives the realstart()over a real SQLite cron store with a one-shotAFTER UPDATE ON cron_jobstrigger that rejects the terminal write (the technique the maintainers use intimer.batch-finalization.test.ts), and asserts thatstart()still rejects whilestate.timeris armed. The second case pins the sibling contract on the scheduled-tick path.origin/main(17f74b9976) before the patch existed FAILS atexpect(state.timer).not.toBeNull()withAssertionError: expected null not to be null, and passes with the patch applied.src/cron/service/timer.batch-finalization.test.ts,src/cron/service/ops.regression.test.ts,src/cron/service/run-recovery.lifecycle.test.tsandsrc/cron/service/timer.regression.test.tswere started but could not complete on this host, which ran out of memory and disk during the runs. CI covers them. The change does not touchrunMissedJobs,armTimer, or any store/recovery helper, and the success path keeps the same call order and the samecron: startedlog line.oxfmt) and typechecking (tsgo) are delegated to CI.Real behavior proof
Behavior addressed: after a single transient cron store write failure during restart catch-up, the Gateway comes up healthy but no scheduled cron job ever fires again for the life of the process.
Real environment tested: the real production
CronServicefromsrc/cron/service.tsdriven throughcron.start()(the exact call the Gateway makes atsrc/gateway/server-cron-lazy.ts:162), over a real on-disk SQLite state database and a real cron job store, with real wall-clock timers, on pristine main17f74b9976and on the patched tree with identical inputs. Nothing in the scheduler, store, or timer was stubbed; the one external seam forced was the SQLite write itself, via a one-shotAFTER UPDATE ON cron_jobstrigger that raisesdisk I/O error while writing cron_jobson the first terminal write, standing in for a real failing or locked disk.Exact steps or command run after this patch: seed two enabled jobs into a fresh store (one already overdue by 30s, one becoming due 30s later), install the one-shot failing trigger on the overdue job's terminal write, call
await cron.start(), then observe the live scheduler for 70s and record every wake the service actually delivered.Evidence after fix:
Observed result after fix: the scheduling timer that was left
nullon main is now armed after the same failed catch-up, and the job scheduled for 30s later actually fired at 30169 ms instead of never firing, while the caller still receives the identicalcron: failed to startfailure.What was not tested: this drives
CronService.start()directly rather than booting a full Gateway process, so the surroundingserver-runtime-services.tserror logging and the skippedreconcileExitWatchers/reconcileStreamWatcherscalls were read from source rather than observed live. The forced failure is a SQLite trigger raising on the terminal write rather than genuinely exhausted disk or a genuinely locked database file, and only the startup catch-up finalization failure was exercised, not every errorrunMissedJobscan surface.