Skip to content

fix(cron): keep a due recurring run when an edit re-saves the same schedule - #96159

Merged
vincentkoc merged 2 commits into
openclaw:mainfrom
yetval:fix/cron-update-drops-due-run
Jun 29, 2026
Merged

vincentkoc merged 2 commits into
openclaw:mainfrom
yetval:fix/cron-update-drops-due-run

Conversation

@yetval

@yetval yetval commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Editing a recurring cron job (every or cron) while one of its slots is already due silently drops that pending run. The control UI and cron edit resubmit the job's schedule on save, and any update that carries schedule (or enabled) advances state.nextRunAtMs to the next future slot without executing the slot that was already due. For an hourly job edited a few seconds after its slot came due, that hour's run never fires; for a daily job, that day's run is lost. For every jobs the same edit also re-phases the cadence anchor to "now", shifting every future fire time.

Root cause: add() and remove() were fixed (#94323) to recompute through recomputeNextRunsForMaintenance, which preserves a past-due nextRunAtMs so the pending run still fires. update() was never converted; it advances unconditionally whenever the patch carries a schedule or enabled field, even when the schedule is unchanged.

src/cron/service/ops.ts (before):

const scheduleChanged = patch.schedule !== undefined;
const enabledChanged = patch.enabled !== undefined;
...
if (scheduleChanged || enabledChanged) {
  if (isJobEnabled(nextJob)) {
    nextJob.state.nextRunAtMs = computeJobNextRunAtMs(nextJob, now);
  }
  ...
}

computeJobNextRunAtMs returns the strictly-future next slot, so a still-due nextRunAtMs <= now is overwritten. The every anchor backfill compounds it: when a re-save omits the internal anchorMs, the backfill mints anchorMs = now, re-phasing the cadence.

Why This Change Was Made

Only advance the next run when the scheduling inputs actually changed, using the existing cronSchedulingInputsEqual helper (the same helper service/store.ts already uses to decide whether stored timer state is still valid).

For the every anchor backfill, inherit the previous cadence anchor only when the interval is unchanged (an idempotent re-save), so the job keeps its existing phase and a due slot survives. A genuine interval change (a different everyMs, which UIs also submit without anchorMs) still anchors to the edit time, exactly as before, so the new cadence starts now; that edit already counts as a scheduling change and recomputes the next run as it always did.

src/cron/service/ops.ts (after):

const previousAnchorMs =
  job.schedule.kind === "every" &&
  job.schedule.everyMs === nextJob.schedule.everyMs &&
  typeof job.schedule.anchorMs === "number" &&
  Number.isFinite(job.schedule.anchorMs)
    ? job.schedule.anchorMs
    : undefined;
...
const schedulingInputsChanged =
  (patch.schedule !== undefined || patch.enabled !== undefined) &&
  !cronSchedulingInputsEqual(job, nextJob);
...
if (schedulingInputsChanged) {
  if (isJobEnabled(nextJob)) {
    nextJob.state.nextRunAtMs = computeJobNextRunAtMs(nextJob, now);
  }
  ...
}

A genuine schedule change (different everyMs, expr, tz, or an enable transition) still recomputes exactly as before, and an every interval change still re-anchors to the edit time; only the unchanged re-save now preserves a due slot and its phase. This is the right boundary: the defect is in the cron service update() op that owns next-run state for CRUD edits, the sibling load-time path (service/store.ts invalidateStaleNextRunOnScheduleChange) already gates on the same identity, and add()/remove() already preserve due slots via maintenance recompute. The fix brings update() to parity and preserves #15905 (genuine edits still recompute).

User Impact

Recurring cron jobs no longer skip a fire when the user edits them during an already-due slot, and every jobs keep their cadence phase across an unchanged re-save instead of drifting to the edit time. A real interval edit still starts the new cadence from the edit time, unchanged from today's behavior. Without this, any save that resubmits the schedule (the normal control-UI behavior) can silently swallow a scheduled run.

Evidence

Drove the real CronService.update() against a real on-disk cron store with an injected clock, on the prior PR head and on the patched tree with identical inputs. The only stub is the isolated-agent job runner (the external execution boundary); the store, schedule math, anchor backfill, and update op are all real.

Two cases, base = 2025-12-13T00:00:00Z:

  • Case A, genuine interval change: add an every: 10s job (anchored at base), then at base+3000 call update(jobId, { schedule: { kind: "every", everyMs: 3_600_000 } }) (UI omits anchorMs).
  • Case B, idempotent re-save: add an every: 10s job, fire it once, advance the clock 50ms past the next due slot, then call update(jobId, { schedule: { kind: "every", everyMs: 10000 } }).
# BEFORE (prior PR head, anchor inherited unconditionally)
A interval-change 10s->1h: anchorMs=base+0,    nextRunAtMs=base+3600000   <- keeps OLD phase, edit-time anchoring lost
B idempotent 10s re-save:  anchorMs=base+0,    nextRunAtMs=base+1820005   dueSlotPreserved=true

# AFTER (this patch, identical inputs)
A interval-change 10s->1h: anchorMs=base+3000, nextRunAtMs=base+3603000   <- re-anchored to edit time (prior semantics restored)
B idempotent 10s re-save:  anchorMs=base+0,    nextRunAtMs=base+1820005   dueSlotPreserved=true

Case A now re-anchors a real interval change to the edit time (base+3000) instead of keeping the old phase, matching the existing update semantics. Case B is unchanged: the due slot's nextRunAtMs is retained and the cadence anchor stays at its original phase, so the pending run still fires.

The idempotent-preserve before/after against pristine main is unchanged from the original PR (main advances the due slot base+1820005 -> base+1830055; this patch keeps base+1820005).

Additional checks: the colocated regression suite now has three cases (every idempotent, every interval-change re-anchor, cron idempotent); the new interval-change test fails on the prior PR head and passes here, and the two preserve-due tests still fail on pristine main and pass with the patch. The add/remove/ops/apply-patch/at-reschedule suites stay green (29 cases across the cron service suites run here). oxlint and oxfmt are clean on the changed files. Not covered: no live gateway or real isolated-agent execution; full project typecheck not run on this box (the one new call mirrors the existing un-cast cronSchedulingInputsEqual(CronJob, CronJob) call in service/store.ts).

@yetval

yetval commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-run

@clawsweeper

clawsweeper Bot commented Jun 23, 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: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper

clawsweeper Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 24, 2026, 12:38 AM ET / 04:38 UTC.

Summary
The PR updates CronService.update() to compare normalized scheduling inputs before recomputing next-run state, preserve the previous every anchor only for unchanged re-saves, and add cron update regression tests.

PR surface: Source +20, Tests +164. Total +184 across 2 files.

Reproducibility: yes. source-reproducible: current main recomputes nextRunAtMs on idempotent schedule patches, and the PR body supplies before/after CronService.update() output against a real on-disk cron store. I did not run local tests in this read-only review.

Review metrics: 1 noteworthy metric.

  • Cron Scheduling Gates: 2 changed. The PR changes both every anchor fallback and update-time next-run recompute gating, which are the two timing decisions maintainers should notice before merge.

Root-cause cluster
Relationship: canonical
Canonical: #96159
Summary: This PR is the current canonical update-path fix; #94323 fixed the same due-slot invariant for add/remove, while #15905 is the adjacent update recompute history.

Members:

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

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Next step before merge

  • No ClawSweeper repair job is needed; the remaining action is normal maintainer review and merge gating.

Security
Cleared: The diff only touches cron scheduling logic and a colocated Vitest regression test; no dependency, workflow, secret, generated, or code-download surface changed.

Review details

Best possible solution:

Land the service-level cron update fix after normal maintainer review and merge gates, keeping add/remove/update aligned on preserving present past-due recurring slots.

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

Yes, source-reproducible: current main recomputes nextRunAtMs on idempotent schedule patches, and the PR body supplies before/after CronService.update() output against a real on-disk cron store. I did not run local tests in this read-only review.

Is this the best way to solve the issue?

Yes. The fix is at the service update boundary that owns CRUD next-run state, reuses the existing schedule identity helper, and now preserves edit-time anchoring for genuine interval changes.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This is a focused cron scheduling bugfix with limited blast radius and direct regression coverage.
  • 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 (live_output): Sufficient: the PR body includes copied before/after live output from real CronService.update() against an on-disk cron store with an injected clock.
  • proof: sufficient: Contributor real behavior proof is sufficient. Sufficient: the PR body includes copied before/after live output from real CronService.update() against an on-disk cron store with an injected clock.
Evidence reviewed

PR surface:

Source +20, Tests +164. Total +184 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 25 5 +20
Tests 1 164 0 +164
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 189 5 +184

What I checked:

Likely related people:

  • yetval: Authored the merged add/remove due-slot preservation work in fix(cron): stop add/remove from dropping a due recurring job's pending run #94323, which this PR explicitly extends to update. (role: adjacent invariant contributor; confidence: high; commits: 8f9da68a562d, c854e4e93f06; files: src/cron/service/ops.ts, src/cron/service.add-recompute-drops-due-every.test.ts, src/cron/service.remove-recompute-drops-due-every.test.ts)
  • echoVic: Authored the original merged update-path next-run recomputation PR referenced by this PR as the behavior boundary to preserve. (role: introduced adjacent update behavior; confidence: high; commits: d6d2e7a5a3be, 80407cbc6a7c; files: src/cron/service/ops.ts, src/cron/service.issue-regressions.test.ts)
  • Takhoffman: Reworked the prior cron update recomputation PR with commits that repaired update next-run handling without a global recompute. (role: adjacent update-path contributor; confidence: high; commits: 92e03598691b, a826fe4daa90, 80407cbc6a7c; files: src/cron/service/ops.ts, src/cron/service.issue-regressions.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jun 24, 2026
yetval added 2 commits June 24, 2026 02:28
…hedule

update() advanced state.nextRunAtMs to the next future slot whenever a
patch carried schedule or enabled, even when the schedule was unchanged,
dropping an already-due run and re-phasing every-job anchors to now. Gate
the advance on cronSchedulingInputsEqual so only a genuine schedule or
enabled change recomputes, and inherit the previous every anchor when a
re-save omits it, matching the add/remove maintenance recompute.
Only inherit the previous cadence anchor for an unchanged-interval every
re-save. A real everyMs change (UI omits anchorMs) now re-anchors to the
edit time, matching the prior update semantics, while idempotent re-saves
still preserve a due slot and phase. Adds a regression test for the
interval-change path.
@yetval
yetval force-pushed the fix/cron-update-drops-due-run branch from f070dc8 to f6d4ecc Compare June 24, 2026 02:28
@yetval

yetval commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 24, 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: the existing ClawSweeper review comment will be edited in place when the review finishes.

@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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jun 24, 2026
@vincentkoc
vincentkoc merged commit e38d64c into openclaw:main Jun 29, 2026
117 of 122 checks passed
Rorqualx pushed a commit to Rorqualx/cortex that referenced this pull request Jun 29, 2026
…hedule (openclaw#96159)

* fix(cron): keep a due recurring run when an edit re-saves the same schedule

update() advanced state.nextRunAtMs to the next future slot whenever a
patch carried schedule or enabled, even when the schedule was unchanged,
dropping an already-due run and re-phasing every-job anchors to now. Gate
the advance on cronSchedulingInputsEqual so only a genuine schedule or
enabled change recomputes, and inherit the previous every anchor when a
re-save omits it, matching the add/remove maintenance recompute.

* fix(cron): re-anchor every-job to edit time on a genuine interval change

Only inherit the previous cadence anchor for an unchanged-interval every
re-save. A real everyMs change (UI omits anchorMs) now re-anchors to the
edit time, matching the prior update semantics, while idempotent re-saves
still preserve a due slot and phase. Adds a regression test for the
interval-change path.

(cherry picked from commit e38d64c)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 30, 2026
…hedule (openclaw#96159)

* fix(cron): keep a due recurring run when an edit re-saves the same schedule

update() advanced state.nextRunAtMs to the next future slot whenever a
patch carried schedule or enabled, even when the schedule was unchanged,
dropping an already-due run and re-phasing every-job anchors to now. Gate
the advance on cronSchedulingInputsEqual so only a genuine schedule or
enabled change recomputes, and inherit the previous every anchor when a
re-save omits it, matching the add/remove maintenance recompute.

* fix(cron): re-anchor every-job to edit time on a genuine interval change

Only inherit the previous cadence anchor for an unchanged-interval every
re-save. A real everyMs change (UI omits anchorMs) now re-anchors to the
edit time, matching the prior update semantics, while idempotent re-saves
still preserve a due slot and phase. Adds a regression test for the
interval-change path.
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 1, 2026
…hedule (openclaw#96159)

* fix(cron): keep a due recurring run when an edit re-saves the same schedule

update() advanced state.nextRunAtMs to the next future slot whenever a
patch carried schedule or enabled, even when the schedule was unchanged,
dropping an already-due run and re-phasing every-job anchors to now. Gate
the advance on cronSchedulingInputsEqual so only a genuine schedule or
enabled change recomputes, and inherit the previous every anchor when a
re-save omits it, matching the add/remove maintenance recompute.

* fix(cron): re-anchor every-job to edit time on a genuine interval change

Only inherit the previous cadence anchor for an unchanged-interval every
re-save. A real everyMs change (UI omits anchorMs) now re-anchors to the
edit time, matching the prior update semantics, while idempotent re-saves
still preserve a due slot and phase. Adds a regression test for the
interval-change path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. 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.

2 participants