Repository navigation
fix(cron): stop replaying old schedule slots after a cron job is edited - #115779
Conversation
Editing a recurring job's schedule made the gateway fire it immediately on the next restart. Startup catch-up compares the new schedule's previous slot against lastRunAtMs, which still belongs to the retired schedule, so a slot that never existed under the old schedule counted as missed. Record when scheduling inputs take effect and replay a missed slot only when it is newer than that. Jobs whose schedule never changed carry no stamp and keep replaying every computed slot, so catch-up is unchanged for them. The missed-slot predicate was duplicated in the runnable check and the backoff-deferral pass; both now share one helper so the bound cannot drift. Fixes openclaw#91944
|
Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 9:43 PM ET / July 30, 2026, 01:43 UTC. ClawSweeper reviewWhat this changesThe PR adds a scheduler-owned schedule-activation timestamp so cron restart catch-up skips a prior slot that belongs only to the schedule replaced by an edit. Merge readinessThis is a focused, proof-backed fix for a real restart-delivery bug. The final revision retains legacy catch-up behavior instead of inferring an activation boundary from unrelated update timestamps, while making the scheduler—not API callers—the owner of the new boundary; it is ready for the assigned maintainer’s normal merge review. Priority: P1 Review scores
Verification
How this fits togetherCron jobs are persisted with their scheduling and run state, then reevaluated when the Gateway starts. The restart catch-up path may run a missed cron slot, including scheduled outbound work, so it must distinguish a genuinely missed current-schedule slot from one synthesized by a later schedule edit. flowchart LR
A[Cron job update] --> B[Scheduler records activation]
B --> C[Persisted cron state]
C --> D[Gateway restart]
D --> E[Missed-slot evaluation]
E --> F[Replay genuine missed slot]
E --> G[Keep future edited schedule]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +33, Tests +245. Total +278 across 9 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the scheduler-owned activation boundary after a current-main merge refresh confirms that pre-activation slots are skipped while genuine post-edit missed slots and all unstamped legacy-job behavior remain unchanged. Do we have a high-confidence way to reproduce the issue? Yes. The added focused test supplies a clear current-main failing path—old schedule run, schedule edit, restart, then a pre-edit current-expression slot—and the PR body independently shows the same behavior with a real Gateway and CLI-driven command job. Is this the best way to solve the issue? Yes. Recording a fact at the scheduler mutation boundary and consuming it in both missed-slot decisions is narrower and safer than inferring schedule activation from AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against 21db50efc72e. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
dc33e0c to
03200c9
Compare
|
Maintainer decision: accept the scheduler-owned activation boundary and its compatibility tradeoff. Edited recurring jobs must not replay a slot from the retired schedule after restart. Pre-upgrade rows without The exact merge-result proof retained the focused restart/backoff regressions, and current |
* origin/main: fix(macos): stop canceled voice wake timers (openclaw#116189) fix(macos): coalesce location permission requests (openclaw#116183) fix(macos): guard remote tunnel restart ownership (openclaw#116172) fix(agents): throw CompactionError when summarization fails (openclaw#115500) fix(test): isolate ACP startup output stream (openclaw#116076) fix(agents): deny all tools when scheduled authority names a removed account (openclaw#115932) fix(test): stop collecting Vydra test helpers (openclaw#116139) fix(discord): preserve webhook deadline errors (openclaw#116155) fix(test): isolate Google embedding batch timeout (openclaw#116161) fix(cron): stop replaying old schedule slots after a cron job is edited (openclaw#115779) fix(plugins): report request timeouts for stalled response bodies (openclaw#116166)
…ed (openclaw#115779) * fix(cron): bound restart catch-up to the active schedule Editing a recurring job's schedule made the gateway fire it immediately on the next restart. Startup catch-up compares the new schedule's previous slot against lastRunAtMs, which still belongs to the retired schedule, so a slot that never existed under the old schedule counted as missed. Record when scheduling inputs take effect and replay a missed slot only when it is newer than that. Jobs whose schedule never changed carry no stamp and keep replaying every computed slot, so catch-up is unchanged for them. The missed-slot predicate was duplicated in the runnable check and the backoff-deferral pass; both now share one helper so the bound cannot drift. Fixes openclaw#91944 * fix(cron): protect schedule activation ownership --------- Co-authored-by: Vincent Koc <[email protected]>
Closes #91944
What Problem This Solves
Fixes an issue where users who edit a recurring cron job's schedule would see that job fire immediately the next time the gateway restarts, instead of only at its new time. A daily job moved from 19:00 to 21:00 fires right after the restart, and then again at 21:00. For scheduled outbound messaging jobs this delivers a message at the wrong time, which is what the linked report describes.
Why This Change Was Made
Startup catch-up decided a slot was "missed" by computing the previous slot of the current schedule and comparing it against
lastRunAtMs, which still belongs to the schedule that was just replaced. A slot that never existed under the old schedule therefore looked overdue forever.The scheduler now records when scheduling inputs take effect (
state.scheduleActivatedAtMs) and replays a missed slot only when that slot is newer than the boundary. The stamp is written in the existingschedulingInputsChangedbranch offinalizeUpdatedJob, the same place that already releasesstartupCatchupAtMs,pacedNextRunAtMs, andforcePreservedNextRunAtMs, so no new notion of "the schedule changed" was introduced. Jobs with no stamp keep replaying every computed slot, so catch-up behaviour is completely unchanged for jobs whose schedule was never edited.The missed-slot predicate was duplicated in the runnable check and in the backoff-deferral pass, so both now share one helper and the bound cannot drift between them.
No SQLite schema change and no migration are involved: cron job state persists as JSON in
state_jsonandstateFromRowalready preserves unknown runtime fields, exactly like the existingstartupCatchupAtMsandpacedNextRunAtMsfields.Legacy rows are intentionally left alone. An earlier revision of this PR also backfilled the boundary during
openclaw doctor --fix, usingupdatedAtMsas the stamp. ClawSweeper correctly rejected that:updatedAtMsadvances for renames, payload edits, and delivery edits, so a legacy job that genuinely missed a slot and was later edited would have had that real catch-up suppressed after upgrade. Per the review's recommended resolution, that commit is dropped and legacy catch-up semantics are preserved exactly as they are today. The residual gap is narrow and self-healing: a job whose schedule was edited before upgrading can still replay once on the first restart after upgrade, after which itslastRunAtMsadvances and the boundary applies normally. Closing that gap needs a trustworthy activation record rather than an inferred one, so it is deliberately out of scope here.Prior art. This is a port of the approach in #92398 by @amersheeny, which built on #92305 by @fsdwen. #92398 was closed by the stale bot after 27 days of inactivity rather than on technical grounds, and ClawSweeper's review of #91944 asks for a scheduler-owned activation boundary. One deliberate divergence: #92398 also read
?? updatedAtMsas a runtime fallback for legacy jobs. This PR has no such fallback in the runtime path, for the same reason the doctor backfill was dropped — and concretely, the existing case atsrc/cron/service.restart-catchup.test.ts:612hasupdatedAtMsequal to the missed slot itself, so a runtime fallback would suppress a legitimate catch-up there.Scope. This fixes the restart-replay mechanism that ClawSweeper identified as the canonical root cause for #91944. It does not address that report's separate suggestion about doctor preflight re-reading
jobs.json.migratedand overwriting SQLite; I could not reproduce that on currentmain.User Impact
Editing a cron job's schedule no longer causes a spurious run on the next gateway restart. Jobs whose schedule is never edited behave exactly as before, and nothing rewrites existing persisted job state on upgrade.
Evidence
Real gateway restart, before and after
Both runs use the same script against a real gateway on an isolated
OPENCLAW_STATE_DIRand a free port, driven entirely through the CLI (cron add,cron edit --cron), with a real command job appending to a file each time it fires. The job really runs on schedule A, schedule B's slot then passes while A is still active, the schedule is edited A→B, and the gateway is stopped and restarted.Before — clean
upstream/mainatc193ffd554:After — this branch:
The
16:50:18line is the reported symptom: the job fires at the moment of the restart rather than at any slot of either schedule.Focused tests and checks
src/cron/service.restart-catchup-schedule-change.test.tsreproduces the same flow in-process: it seeds the job on the old schedule, starts the service, edits the schedule throughcron.update(), stops the service, advances the clock, and starts a second service against the same store. It fails on currentmainand passes with this change.Verified locally on Node 24.18.0:
node scripts/run-vitest.mjs src/cron src/commands/doctor/cron— 168 files, 2056 tests passedpnpm build— succeeded, noINEFFECTIVE_DYNAMIC_IMPORTwarningspnpm check— 21 of 22 steps green, including the max-lines suppression ratchet, the database-first legacy-store guard, and all three typecheck projects. The one failure isformat, onscripts/code-mode-model-matrix.ts, which this branch does not touch; that file is already unformatted onmain(git show upstream/main:scripts/code-mode-model-matrix.tsfailsoxfmt --checkon its own).About the red checks on this PR
The failing shards are
src/tui/tui-pty-local.e2e.test.tsandsrc/cli/help-exit.process.test.ts, plusopenclaw/ci-gate, which only aggregates them. Neither test file imports anything undersrc/cron/**, which is the entire surface this branch touches, and checking out cleanupstream/mainatc193ffd554and runningnode scripts/run-vitest.mjs src/cli/help-exit.process.test.tsreproduces the identical result there: 4 failed, 48 passed. I left them alone rather than folding unrelated fixes into this PR, but I am happy to rebase onto a greenermainif a maintainer prefers.