Skip to content

fix(cron): avoid Doctor backups for unchanged one-shot jobs - #168938

Merged
steipete merged 1 commit into
openclaw:mainfrom
harshitgupta31415:harshitgupta31415/canonical-one-shot-doctor-backups-168838
Oct 11, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
harshitgupta31415:harshitgupta31415/canonical-one-shot-doctor-backups-168838

Conversation

@harshitgupta31415

@harshitgupta31415 harshitgupta31415 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #168838. Credit to @WG-Mojo for the report.

Doctor marks an already canonical one-shot timestamp as mutated and enters the cron backup/save path even though the job is unchanged.

Why This Change Was Made

Keep the mutation decision in normalizeStoredCronJobs: rewrite only a noncanonical timestamp or a schedule that still contains atMs. The existing guarded backup/save flow stays intact for genuine repairs. Timestamp precedence, exported function signatures, configuration, dependencies, and storage schemas remain unchanged.

Production delta: +1/-1, net zero. Focused test growth: +37 lines.

User Impact

Canonical one-shot jobs no longer cause redundant Doctor cron backups. Legacy normalization and malformed-row recovery retain their existing protection.

Evidence

Head: c8931dc0ab1073537372a7c91512dbc81292e800.
Regression base: e0f1692a6e19f8383c00c0693531dc9a84c47bea.
Stable CLI: 2026.10.1, release commit e178c39e9aae3fa440735217f9aef9574f286677.

  • Red regression: the canonical-job test emits Saved pre-repair cron backup and Cron store normalized on the base.
  • Green at committed head: four selected canonical/legacy regression cases pass, including the real SQLite backup-directory case. All 36 normalizer cases passed in the broader precommit run of the identical patch.
  • Actual CLI red/green: installed stable Doctor creates one cron backup while stored jobs and settings stay unchanged. Candidate Doctor creates zero cron backups for the canonical profile, preserves stored jobs/settings, and completes successfully.
  • Stable data compatibility: the restored stable snapshot loads through candidate Doctor with supported job definitions/state and settings preserved, SQLite integrity ok, and schema version 20 unchanged. Actual candidate Gateway cron.get confirms the user-created job's ID, name, disabled flag, payload, creation time, session target, and scheduled instant.
  • Genuine repair: an invalid schedule produces a verified pre-repair backup and a complete SQLite quarantine record, including the original payload.
  • CLI commands, terminal output, and fixture limitations.
  • Changed-file formatting, focused core lint, and git diff --check passed. The exact-head hosted CI gate passed before this evidence update.

Local baseline limitations were reproduced on a clean base: the full core typecheck fails at src/cli/gateway-cli/run-loop-startup.test-support.ts:380 with TS2353 for the existing runtime argument; two existing SQLite-rehearsal symlink tests fail with Windows EPERM; the changed-file gate falsely reports Windows SQLite inventory growth (tracked in #168935 and repaired separately by #168956). Checks after that gate failure and full core-test typechecking were not counted as passing.

The broad upgrade fixture initially expected a generated Workshop review job to survive; current base intentionally retires it in src/cron/store/load.kernel.ts:24. The supported heartbeat and user job remain. An initial malformed-row assertion also expected an invalid atMs-only SQLite definition to stay active; the existing contract quarantines it with a verified backup. Those failed assertions are disclosed in the proof comment. Installer self-replacement and live-channel delivery were outside these checks.

@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added the commands Command implementations label Oct 11, 2026
@harshitgupta31415
harshitgupta31415 marked this pull request as ready for review October 11, 2026 06:25
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR prevents unchanged canonical one-shot schedules from triggering Doctor cron backups and saves.

Example: Doctor repairs an otherwise canonical stored job with schedule.at="2026-04-01T10:00:00.000Z" and no atMs.

  • Before: Normalization reports a mutation and enters the SQLite backup/save path.
  • After: Normalization reports no mutation and leaves the job and backup directory unchanged.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch is focused and appears correct with useful regression coverage, but supplied harness results do not satisfy the required shipped-behavior and upgrade proof gates.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Doctor creates unnecessary shared-state recovery copies for unchanged canonical one-shot jobs.
Reason: The patch corrects an existing mutation contract with no new option, default, schema, or ownership policy.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this PR narrowly fixes a current Doctor defect and preserves genuine repair protection; no introduced correctness or security defect was found.

Priority: P2
Reviewed head: c8931dc0ab1073537372a7c91512dbc81292e800

Before merge

  • Add real behavior proof - The supplied evidence exercises normalizeStoredCronJobs and applyLegacyCronStoreRepair through tests with real isolated SQLite, rather than the shipped Doctor CLI; provide redacted terminal output or logs showing canonical jobs produce no cron backup and genuine repairs retain backup protection, plus a v2026.10.1-to-candidate upgrade preserving settings and data. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Supply real Doctor CLI evidence for the no-op and genuine-repair controls, including a latest-stable upgrade that preserves settings and persisted jobs.
Agent review details

How this fits together

Doctor reads persisted cron definitions, normalizes supported legacy fields, and uses the mutation result to decide whether to back up and rewrite the shared SQLite store.

flowchart TD
  A[Doctor CLI or update] --> B[Load cron repair state]
  B --> C[Normalize stored jobs]
  C --> D{Actual repair needed}
  D -->|No| E[Return unchanged]
  D -->|Yes| F[Verified SQLite backup]
  F --> G[Guarded cron save]
Loading

Technical review

Best possible solution:

Keep the mutation correction in the existing normalizer while retaining the existing backup and save guards for genuine repairs.

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

Current-main source deterministically marks an identical canonical timestamp mutated and feeds that result into Doctor's backup/save decision; the contributor reports a matching failing-base regression, but this review ran no target code.

Is this the best way to solve the issue?

The guard fixes the incorrect mutation signal at its producer without duplicating comparison policy in the backup owner or changing timestamp precedence.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against c7a7539cf40d.

Provenance checked

  • One-shot timestamp normalization keeps the original intent (4385e57: The changed condition dates to safe handling of invalid legacy atMs; the unconditional mutation assignment predates that change.)
  • Doctor-owned persisted repair and backups keeps the original intent (fix(cron): keep legacy repair in Doctor #160448: Normalize persisted jobs only through backed-up Doctor repair while preserving ownership and concurrent-write checks.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 4385e57 adds src/commands/doctor-cron-store-migration.ts:427 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4385e57dce92; files: src/commands/doctor-cron-store-migration.ts)
  • Yuval Dinodia: Raw commit ebfccca adds src/commands/doctor/cron/legacy-repair.test.ts:121 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: ebfcccacf67d; files: src/commands/doctor/cron/legacy-repair.test.ts)

PR surface

Source 0, Tests +37. Total +37 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 1 1 0
Tests 2 37 0 +37
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 38 1 +37

Review metrics

Metric Value Why it matters
Production versus test LOC Production +1/-1; tests +37/-0 The production change is minimal; added coverage protects SQLite backup behavior and distinct legacy timestamp cases.

Root-cause cluster

Relationship: same_root_cause
Canonical: #168838
Summary: This PR directly repairs the canonical report's false timestamp mutation signal.

Members:

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

Labels

Label changes:

  • add P2: Avoidable shared-database backups consume storage and repair I/O, with no established data loss or blocked core workflow.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: Avoidable shared-database backups consume storage and repair I/O, with no established data loss or blocked core workflow.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 11, 2026, 2:32 AM ET / 06:32 UTC.

@steipete
steipete merged commit 1bd9966 into openclaw:main Oct 11, 2026
193 of 194 checks passed
@harshitgupta31415

Copy link
Copy Markdown
Contributor Author

Doctor CLI and stable-profile proof

Candidate: c8931dc0ab1073537372a7c91512dbc81292e800.
Installed stable: 2026.10.1, release commit e178c39e9aae3fa440735217f9aef9574f286677 (confirmed by the installed CLI).

The stable Gateway created the disabled one-shot job through openclaw cron add. All runs used an isolated profile and port 21581; update Doctor used the existing external-service policy.

Commands:

node <installed-stable>/openclaw.mjs doctor --fix --non-interactive --no-workspace-suggestions
node scripts/run-node.mjs doctor --fix --non-interactive --no-workspace-suggestions
node scripts/run-node.mjs cron get <stable-created-id> --port 21581 --json

Recorded results:

Stable Doctor: exit 0; cron backups +1; settings unchanged; stored jobs unchanged.
Candidate Doctor, canonical profile: exit 0; cron backups +0; settings unchanged; stored jobs unchanged; SQLite integrity ok.
Candidate Doctor, restored stable snapshot: exit 0; cron backups +0; settings unchanged; supported job definitions and state preserved; SQLite integrity ok; schema version remains 20.
Malformed-row repair: exit 0; cron backups +1; invalid schedule preserved in SQLite quarantine; verified backup retains the original row and payload.
Candidate Gateway cron.get: user job ID, name, disabled flag, payload, creation time, session target, and scheduled instant match the stable-created job.

Terminal lines from the actual repair control:

Cron store issues detected
- 1 malformed cron row will be quarantined in SQLite
Saved pre-repair cron backup: <isolated-state>/state/openclaw.sqlite.doctor-cron-....bak
Cron store normalized at <isolated-state>/cron/jobs.json.
Doctor complete.

The canonical candidate runs contain Doctor complete. and no Saved pre-repair cron backup or Cron store normalized line.

Two proof details are explicit:

  • The initial broad fixture expected all three stable-created rows to remain. Current base intentionally retires the autogenerated Workshop review job in src/cron/store/load.kernel.ts:24; the supported heartbeat and user-created job remain. That behavior is unchanged by this PR. The replay compared all retained fields, canonicalizing only equivalent ISO timestamp spellings, and the actual Gateway read confirmed the user-facing values.
  • An atMs-only row is invalid in the canonical SQLite store (src/cron/persisted-shape.ts:96). Its expected repair is backed-up quarantine, not an active-job timestamp rewrite. The first harness assertion expected the row to stay active and failed; inspection confirmed the complete row survives in the verified backup and diagnostic_events quarantine. That assertion failure is not counted as a passing run. Canonical and restored-stable CLI replays passed their assertions.

This covers the actual Doctor entry point, valid stable data loading, and genuine repair protection. Installer self-replacement and live-channel delivery were outside these checks.

@harshitgupta31415

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper could not start a re-review for this item.

Reason: re-review requires an open issue or PR.

RomneyDa pushed a commit that referenced this pull request Oct 12, 2026
Doctor's cron store migration marked every one-shot schedule as mutated, so canonical stores entered SQLite backup repair on every run. Only noncanonical at/atMs schedules are rewritten now. Fixes #168838. Thanks @harshitgupta31415.

(cherry picked from commit 1bd9966)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
…#168938)

Doctor's cron store migration marked every one-shot schedule as mutated, so canonical stores entered SQLite backup repair on every run. Only noncanonical at/atMs schedules are rewritten now. Fixes openclaw#168838. Thanks @harshitgupta31415.
RomneyDa pushed a commit that referenced this pull request Oct 13, 2026
Backport of 1bd9966 (#168938) adapted for 2026.10.3.

Applied the canonical-schedule guard to 10.3's parsedAt/fallbackAt normalization; the
main-only single-expression rewrite was not taken.

(cherry picked from commit 1bd9966)
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Doctor marks canonical one-shot schedules mutated and enters SQLite backup repair

2 participants