Skip to content

v2026.6.5: Cron doctor preflight overwrites API-updated schedules with stale legacy JSON data #91944

Closed

Description

@suifatt7799-oss

Version: 2026.6.5

Summary:
After upgrading to 2026.6.5, a cron job that had its schedule updated via the cron.update API was triggered at the wrong time on gateway restart — based on the old schedule stored in a legacy JSON file, not the updated SQLite record.

Steps to reproduce:

  1. Have a cron job previously migrated from legacy JSON store to SQLite (.migrated file remains on disk as migration artifact)
  2. Update the job's schedule via the cron.update API (e.g., 18 15 10 * * → 18 15 11 * *)
  3. Confirm the update is reflected in SQLite (cron_jobs table shows new schedule, updated next_run_at_ms)
  4. Upgrade gateway to v2026.6.5 → gateway restarts, doctor preflight runs
  5. Doctor preflight reads the legacy jobs.json.migrated file which still contains the OLD schedule
  6. Migration overwrites (or re-evaluates based on) the old schedule in SQLite
  7. Cron engine on startup detects the job as "missed" (old schedule date has already passed) and fires it immediately after a 120s deferral

Log evidence from /tmp/openclaw/openclaw-YYYY-MM-DD.log:

cron: staggering missed jobs to prevent gateway overload  { totalMissed: 1 }
cron: deferring missed agent jobs until after gateway startup  { count: 1, delayMs: 120000 }

The legacy JSON file had the old schedule; the SQLite had the new one. The doctor migration picked the stale version.

Root cause:
The doctor preflight cron migration reads from legacy JSON stores without checking whether the corresponding SQLite record already has newer data (e.g., by comparing cron_jobs.updated_at against the JSON file's mtime, or checking if the SQLite record exists at all for a given job ID).

Suggested fix:

  • Before migrating a job from a legacy JSON store, check if the job ID already exists in the cron_jobs SQLite table
  • If it exists and cron_jobs.updated_at > source_file.mtime, skip the migration for that job
  • Or alternatively: treat .migrated files as truly done and never re-read them during doctor preflight

Impact:
For users who have updated cron schedules via the API after the initial JSON→SQLite migration, upgrading to 2026.6.5 can cause cron jobs to fire unexpectedly at the wrong time based on stale schedule data. This is particularly dangerous for scheduled outbound messaging jobs.

Activity

  1. clawsweeper commented on Jun 10, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 21, 2026, 3:01 PM ET / 19:01 UTC.

    Summary
    Keep open: current main and v2026.6.9 still lack a scheduler-owned activation boundary for cron restart catch-up, and the live closing PR at #92398 is still open and conflicting rather than merged.

    Reproducibility: yes. Current main is source-reproducible: cron.update moves nextRunAtMs without recording schedule activation, and restart catch-up replays a previous cron slot solely because it is newer than lastRunAtMs.

    Root-cause cluster
    Relationship: canonical
    Canonical: #91944
    Summary: This issue is the canonical report for the API-updated cron schedule restart replay bug; the active closing PR is the candidate fix and older unmerged attempts are superseded.

    Members:

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

    Next step
    A live closing PR already owns the implementation path, so ClawSweeper should not create another fix PR for this issue.

    Review details

    Best possible solution:

    Review and land #92398, or replace it with an equivalent scheduler-owned activation boundary plus doctor migration that preserves the same upgrade behavior.

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

    Yes. Current main is source-reproducible: cron.update moves nextRunAtMs without recording schedule activation, and restart catch-up replays a previous cron slot solely because it is newer than lastRunAtMs.

    Is this the best way to solve the issue?

    Yes, with maintainer acceptance required. The linked PR’s scheduler-owned activation boundary plus doctor backfill is the best current fix shape I found, but it changes persisted cron state and conservative upgrade replay behavior.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • Until the linked fix lands, restart catch-up can still infer a missed cron slot from a schedule that was not active when that slot occurred.
    • The candidate fix changes persisted cron state and upgrade replay semantics, so maintainers still need to accept the migration boundary before closing the issue.

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

    Label changes

    Label changes:

    • add clawsweeper:fix-shape-clear: Current issue advisory state selects this label.
    • add clawsweeper:needs-maintainer-review: Current issue advisory state selects this label.

    Label justifications:

    • P1: The issue describes a real user-facing cron regression that can send scheduled outbound work at the wrong time after a schedule update and restart.
    • impact:message-loss: The reported cron job was scheduled outbound messaging, and the bug controls whether a message job is sent, skipped, or deferred after restart.
    • impact:session-state: The affected behavior is persisted cron scheduler state drifting from the schedule last selected through the API.
    Evidence reviewed

    Acceptance criteria:

    What I checked:

    • Root policy read: Root AGENTS.md was read fully; its state/storage and doctor-migration guidance applies because this issue concerns persisted cron state and upgrade behavior. (AGENTS.md:1, edd1d3319cce)
    • Vision fit: VISION.md lists bug fixes and stability as current project priorities, matching this core scheduler regression. (VISION.md:12, edd1d3319cce)
    • Current main lacks activation-boundary replay guard: Current main still computes the current cron expression's previous slot and returns true when previousRunAtMs is greater than lastRunAtMs, with no schedule activation timestamp check. (src/cron/service/timer.ts:1495, edd1d3319cce)
    • Current update path lacks activation state: cron.update detects schedule/enabled changes, recomputes nextRunAtMs, and records updatedAtMs, but does not persist a scheduler-owned scheduleActivatedAtMs field. (src/cron/service/ops.ts:542, edd1d3319cce)
    • Current CronJobState has no activation field: CronJobState has nextRunAtMs and lastRunAtMs but no scheduleActivatedAtMs or scheduleUpdatedAtMs field on current main. (src/cron/types.ts:283, edd1d3319cce)
    • Latest release still affected: v2026.6.9 still has the unbounded previousRunAtMs > lastRunAtMs predicate and no activation timestamp field in CronJobState. (src/cron/service/timer.ts:1512, c645ec4555c0)

    Likely related people:

    • Takhoffman: Authored prior restart catch-up and stale-run replay commits that established the implicated previousRunAtMs/lastRunAtMs behavior. (role: feature-history contributor; confidence: high; commits: 79d00ae39860, 28dc2e8a400c, cc5dad81bc70; files: src/cron/service/timer.ts, src/cron/service.restart-catchup.test.ts)
    • steipete: Carried adjacent cron startup catch-up and persistence churn around the same timer and store surfaces. (role: adjacent area contributor; confidence: high; commits: 96d17f3cb191, e86b38f09d85, 9267e694f7e7; files: src/cron/service/timer.ts, src/cron/service.restart-catchup.test.ts, src/cron/store.ts)
    • vincentkoc: Recently refactored cron dispatch/timer code and authored the candidate PR's doctor migration and activation ownership commits. (role: recent area contributor and likely follow-up owner; confidence: high; commits: 1c9053802a98, ebe7550596f4, 989cc7b44604; files: src/cron/service/timer.ts, src/cron/service/ops.ts, src/commands/doctor/cron/schedule-activation-migration.ts)
    • amersheeny: Authored the active closing PR and its initial schedule replay boundary commits for this issue. (role: candidate fix author; confidence: medium; commits: f28244c95918, edfe8a758e58, 5a33f2136b78; files: src/cron/service/timer.ts, src/cron/service/ops.ts, packages/gateway-protocol/src/schema/cron.ts)
    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.
  2. added
    P1High-priority user-facing bug, regression, or broken workflow.
    impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.
    issue-rating: 🦪 silver shellfishThin issue quality; more reproduction proof or environment detail is needed.
    on Jun 10, 2026
  3. suifatt7799-oss commented on Jun 10, 2026

    @suifatt7799-oss
    Author

    Additional evidence from the reporter, sanitized for privacy:

    Timeline (all times local, UTC+8)

    Time Event
    Day 1, ~22:30 cron.update API call: changed schedule from 18 15 10 * * → 18 15 11 * * (same tz). Response confirmed nextRunAtMs advanced by exactly 86400000ms (1 day).
    Day 2, ~20:30 openclaw update to v2026.6.5. Gateway receives SIGTERM, shuts down.
    Day 2, ~20:31 Gateway auto-restarts via launchd. Agent model shows current version.
    Day 2, ~20:32 Second SIGTERM received (72s after first restart). Gateway shuts down again.
    Day 2, ~20:33 Gateway starts a second time. This is where the missed-job detection fires.
    Day 2, ~20:35 The cron job executes (120s deferral from 20:33 startup).

    Key log entries (from /tmp/openclaw/openclaw-YYYY-MM-DD.log)

    The critical entries appear during the second startup at ~20:33:

    cron: staggering missed jobs to prevent gateway overload
      { immediateCount: 0, deferredCount: 1, totalMissed: 1 }
    
    cron: deferring missed agent jobs until after gateway startup
      { count: 1, jobIds: ["<JOB_ID>"], delayMs: 120000 }
    
    cron: started
      { enabled: true, jobs: 7, nextWakeAtMs: <TIMESTAMP_MATCHING_STARTUP+120S> }
    

    Additional observations

    • Double restart during upgrade: The gateway went through two start-stop cycles in quick succession (start at 20:31 → SIGTERM at 20:32 → start at 20:33). The missed-job detection only appeared on the second start. Could the first start have altered scheduler state that the second start interpreted as missed?
    • The job's schedule was correct in SQLite both before and after the incident (confirmed via sqlite3 query). The nextRunAtMs had been correctly advanced by the API update.
    • The actual execution time did not match either the old schedule (day 10, 15:18) or the new schedule (day 11, 15:18) — it fired at ~20:35, which is exactly 120s after the second gateway startup.
    • No active jobs.json exists in the cron directory — only .migrated archives and run logs. The cron engine startup log references storePath: ".../cron/jobs.json" but that file is absent.
    • The affected job is an isolated agentTurn with timeoutSeconds: 900, delivery via Telegram announce.

    Mitigation applied

    The reporter has a state-file mechanism that prevents duplicate execution within the same month, so the unintended run caused no data loss. The job's schedule remains correct in SQLite and will skip all items on the next legitimate trigger.

    Happy to provide any additional sanitized data that would help narrow this down.

  4. added
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    and removed
    issue-rating: 🦪 silver shellfishThin issue quality; more reproduction proof or environment detail is needed.
    on Jun 15, 2026
  5. 1 remaining item

  6. added
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    on Jun 15, 2026
  7. added
    clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.
    and removed
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.
    on Jun 19, 2026
  8. added a commit that references this issue on Jun 23, 2026
    b4120c6
  9. added 2 commits that reference this issue on Jul 29, 2026
    03200c9
  10. added a commit that references this issue on Jul 30, 2026
    82af1bf
  11. added a commit that references this issue on Jul 30, 2026
    ddb36af
  12. locked as resolved and limited conversation to collaborators on Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions