Skip to content

feat(cron): optionally skip missed recurring jobs at startup - #135071

Merged
steipete merged 2 commits into
mainfrom
steipete/cron-skip-missed-jobs
Sep 1, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/cron-skip-missed-jobs

Conversation

@steipete

@steipete steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

After Gateway downtime, recurring automations can run stale reminders or digests during startup catch-up, producing unwanted messages and model calls. Catch-up limits only pace the stale work; they do not let an operator opt out.

Why This Change Was Made

Add the approved cron.skipMissedJobs option, defaulting to false. Startup schedule preparation fast-forwards runnable recurring jobs with the existing scheduler helper, commits the authoritative runtime rows, and excludes those jobs from catch-up. The durable update is essential: an empty plan alone would let the first regular scheduler tick replay the expired slot. The change uses the existing row-scoped SQLite transaction and respects active-run ownership.

Discovery source: NetEase Youdao's LobsterAI patch stack (github.com/netease-youdao/LobsterAI). The implementation follows current main's runtime ownership and persistence architecture, not the older patch structure.

User Impact

With cron.skipMissedJobs: true, missed cron/every occurrences are dropped in favor of the next future occurrence. This avoids stale work at the cost of intentionally not catching up. One-shot at jobs keep their catch-up semantics. Unset/false preserves the existing default. Types, validation, Settings help/labels, and docs describe the option. No storage schema or migration changes.

Evidence

The seven targeted test files passed (74 tests), and the edited file passed a final 5-test rerun after a callback-variable lint correction. pnpm check:changed exited 0 without skip flags. Final autoreview is scoped-clean at P0. Regression coverage includes empty and mixed startup plans, durable future timestamps for cron/every, history-only missed cron, unchanged future schedules and run history, overdue one-shot execution, and no replay on the first regular tick. Existing restart/backoff/concurrency tests cover the unchanged default and sibling ownership paths. Full Gateway/channel live proof is not claimed; the tests use the real cron startup owner, SQLite store, and first regular tick with mocked execution callbacks.

Commands:

pnpm check:changed
OPENCLAW_VITEST_FS_MODULE_CACHE=0 pnpm test \
  src/cron/service.startup-overflow-clobber.test.ts \
  src/cron/service.restart-catchup.test.ts \
  src/cron/service.restart-catchup-schedule-change.test.ts \
  src/cron/service.restart-catchup-subsecond.test.ts \
  src/cron/service/timer-catchup-concurrency.test.ts \
  src/config/zod-schema.cron-triggers.test.ts \
  src/config/schema.help.quality.test.ts
OPENCLAW_VITEST_FS_MODULE_CACHE=0 pnpm test src/cron/service.startup-overflow-clobber.test.ts

The initial environment lacked executable links and later failed collection on zod/v4; the permitted pnpm install repaired dependencies. The first full check found one test-variable shadowing issue, which was corrected and revalidated. No checks or assertions were weakened. Pre-fix regression failure was verified by base/diff reasoning, as allowed by the worker contract; the initial pre-fix executions stalled before assertions.

@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review September 1, 2026 09:54
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Sep 1, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 1, 2026
@clawsweeper

clawsweeper Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 7:41 AM ET / 11:41 UTC.

ClawSweeper review

What this changes

This PR adds an optional cron.skipMissedJobs setting that advances overdue recurring schedules at Gateway startup while retaining default and one-shot catch-up behavior.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open for maintainer handling: current main still uses normal startup catch-up, while this maintainer-authored, protected PR adds the reviewed opt-in behavior with no blocking defect found.

Priority: P2
Reviewed head: ecb4c6ee154eea93636feac6ecace7bf3036d82a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary implementation with aligned config/docs and no blocking review finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its latest comment nevertheless reports an isolated built-Gateway restart showing durable non-execution when enabled and preserved catch-up when disabled.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its latest comment nevertheless reports an isolated built-Gateway restart showing durable non-execution when enabled and preserved catch-up when disabled.
Evidence reviewed 7 items Current-main behavior: Current main still imports the runnable-job collector and invokes the former startup backoff helper; it contains no skipMissedJobs behavior, so the central requested capability remains necessary.
Startup owner and persistence boundary: The introduced startup collector checks runnable and active-run state, recomputes only opted-in recurring schedules, and commits changed canonical rows before returning the catch-up plan.
Caller and durable row contract: Gateway cron startup calls runMissedJobs after recovery, while the shared row transaction rereads authoritative SQLite rows under the write lock and only then publishes committed runtime rows.
Findings None None.
Security None None.

How this fits together

The Gateway cron service reads durable automation schedules at startup, determines which overdue jobs should run, and persists schedule state before ordinary timer ticks can deliver work. This change lets an operator choose to advance missed recurring work instead of executing it after downtime.

flowchart LR
  A[Stored automation schedules] --> B[Gateway cron startup]
  B --> C[Startup catch-up evaluation]
  C --> D{Skip missed recurring enabled?}
  D -->|Yes| E[Persist next future occurrence]
  D -->|No| F[Reserve catch-up work]
  E --> G[Regular timer tick]
  F --> G
  G --> H[Automation delivery]
Loading

Before merge

  • Complete next step (P2) - This protected, maintainer-authored PR already contains the reviewed implementation; it needs normal maintainer merge handling rather than a repair job.
Agent review details

Security

None.

PR surface

Source +47, Tests +85, Docs +3, Generated 0. Total +135 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 5 73 26 +47
Tests 2 86 1 +85
Docs 2 4 1 +3
Config 0 0 0 0
Generated 2 3 3 0
Other 0 0 0 0
Total 11 166 31 +135

Review metrics

Metric Value Why it matters
Configuration surface 1 optional cron setting added The new setting is strict-schema validated, documented, and defaults to preserving existing catch-up behavior.
Production versus test delta production +47 net, tests +85 net, docs +3 net, generated artifacts 0 net The production growth implements the new persisted startup policy and is accompanied by focused boundary coverage.

Technical review

Best possible solution:

Land the documented opt-in at the cron startup owner, retaining false/unset catch-up and one-shot semantics as covered by the branch.

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

Yes: the startup call chain and durable-row boundary establish a focused scenario with an overdue recurring job and an enabled option; the supplied comment also reports that isolated Gateway restart scenario.

Is this the best way to solve the issue?

Yes: placing the decision in startup catch-up and persisting the recomputed schedule is the narrow owner-boundary solution, preventing the first normal timer tick from replaying the skipped occurrence.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded, opt-in improvement to recurring automation recovery after Gateway downtime.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its latest comment nevertheless reports an isolated built-Gateway restart showing durable non-execution when enabled and preserved catch-up when disabled.

Evidence

What I checked:

  • Current-main behavior: Current main still imports the runnable-job collector and invokes the former startup backoff helper; it contains no skipMissedJobs behavior, so the central requested capability remains necessary. (src/cron/service/timer-catchup.ts:40, 1855fe0f4e48)
  • Startup owner and persistence boundary: The introduced startup collector checks runnable and active-run state, recomputes only opted-in recurring schedules, and commits changed canonical rows before returning the catch-up plan. (src/cron/service/timer-catchup.ts:42, ecb4c6ee154e)
  • Caller and durable row contract: Gateway cron startup calls runMissedJobs after recovery, while the shared row transaction rereads authoritative SQLite rows under the write lock and only then publishes committed runtime rows. (src/cron/service/ops-lifecycle.ts:187, ecb4c6ee154e)
  • Configuration contract: The optional boolean is accepted by the strict root schema and is represented in the public type, field help, labels, generated baseline, and both relevant configuration references. (src/config/zod-schema.root-shape.ts:338, ecb4c6ee154e)
  • Behavioral regression coverage: The new table-driven test covers overdue cron and every schedules, unchanged future schedules and history, preserved one-shot catch-up, and verifies the first ordinary tick cannot replay skipped work. (src/cron/service.startup-overflow-clobber.test.ts:65, ecb4c6ee154e)
  • Reported real restart result: The latest PR comment describes isolated built-Gateway restart runs showing no execution and a persisted future timestamp with the option enabled, then catch-up with it disabled. (ecb4c6ee154e)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: 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-01T10:07:51.312Z sha d541a3a :: found issues before merge. :: [P1] Refresh the tracked configuration baseline
  • reviewed 2026-09-01T11:04:28.017Z sha ecb4c6e :: needs maintainer review before merge. :: none

@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Config-surface approval note: the cron.skipMissedJobs option was explicitly approved by the maintainer (@steipete) in the operator chat directing this adoption campaign ("adopt all of these", covering the reviewed proposal that named this exact option). Tracked config baseline artifacts are now refreshed per the ClawSweeper finding.

Add cron.skipMissedJobs (default false). Recompute and commit missed
recurring schedules in the startup owner before returning the catch-up
plan, so the first regular timer tick cannot replay stale occurrences.
Keep one-shot catch-up, future schedules, and active-run ownership intact.
Align config validation, help, labels, docs, and persistence regressions.

Discovery source: NetEase Youdao's LobsterAI patch stack
(https://github.com/netease-youdao/LobsterAI).
@steipete
steipete force-pushed the steipete/cron-skip-missed-jobs branch from ab07d73 to ecb4c6e Compare September 1, 2026 10:41
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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 1, 2026
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Live proof (real gateway restarts from this branch's built dist, isolated OPENCLAW_STATE_DIR, own port; openclaw cron add --every 90s --system-event ... via gateway RPC):

  • Phase 1: job created; nextRunAtMs ~90s out.
  • Phase 2 (cron.skipMissedJobs: true, gateway down 200s so the slot elapsed): after restart the job did NOT execute, lastRunAtMs stayed empty, and the persisted nextRunAtMs was advanced into the future — i.e. the first regular tick cannot replay the missed slot (the reference-patch correctness point, proven against the durable store, not just the in-memory plan).
  • Phase 3 control (skipMissedJobs: false, another slot elapsed while down): after restart the job DID run (lastRunAtMs set) — the flag is causal; default catch-up behavior intact.

Note: the cron: skipped missed recurring jobs after restart info log did not appear on stdout at default console log level; the skip decision itself is proven by store state + non-execution. Boundary tests in the PR additionally pin the log and receipts.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 1, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete merged commit d789919 into main Sep 1, 2026
274 checks passed
@steipete
steipete deleted the steipete/cron-skip-missed-jobs branch September 1, 2026 22:06
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 2, 2026
…w#135071)

* feat(cron): optionally skip missed recurring jobs at startup

Add cron.skipMissedJobs (default false). Recompute and commit missed
recurring schedules in the startup owner before returning the catch-up
plan, so the first regular timer tick cannot replay stale occurrences.
Keep one-shot catch-up, future schedules, and active-run ownership intact.
Align config validation, help, labels, docs, and persistence regressions.

Discovery source: NetEase Youdao's LobsterAI patch stack
(https://github.com/netease-youdao/LobsterAI).

* docs(config): refresh generated config baseline for cron.skipMissedJobs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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.

1 participant