Skip to content

fix(cron): fence executions with durable receipts - #122948

Merged
steipete merged 26 commits into
mainfrom
claude/cron-owner-hardening
Aug 13, 2026
Merged

steipete merged 26 commits into
mainfrom
claude/cron-owner-hardening

Conversation

@steipete

@steipete steipete commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Cron previously combined process-local locks with persisted queuedAtMs / runningAtMs markers. Two gateways could load the same runnable job, execute it twice, or let a stale run mutate a job after ownership changed. Operators then had to infer whether a job ran from logs and best-effort task history.

This is the multi-gateway cron ownership hardening follow-up split from parent program #114388.

Why This Change Was Made

The change adds a lazy, additive SQLite cron_run_receipts table without a schema-version bump. Each reservation records the exact store/job, config revision, effective agent, PID/process-start incarnation, start time, and terminal result. The receipt is both the durable execution fact and the cross-process lease.

The implementation is organized around four lifecycle invariants:

  • I1 — live owner or recoverable: every non-terminal receipt belongs to a live process or can be recovered by a sibling gateway without restart.
  • I2 — atomic transitions: receipt state and queued/running job markers change in the same synchronous transaction, or have an explicit exact-receipt recovery rule.
  • I3 — complete abandonment: every cleanup or abandon path terminalizes and releases its exact receipt.
  • I4 — authoritative finalization: outcomes apply to rows reread inside the write transaction, never to stale in-memory snapshots.

Scheduler runtime writes are row-scoped, so gateway B cannot replay stale state for gateway A's job. Claims use PID-safe incarnation identity, including the existing Windows process-start reader. Owner/config changes and dispatch admission share the durable fence; stale runs are superseded before effects or final state can cross revisions. Notifications and completion events publish only after committed state, and startup repair buffers notifications until its transaction succeeds.

The archive was mined rather than transplanted. The final design keeps durable receipts, exact-owner liveness recovery, config-revision adjudication, and the small current-main rollback seam. It drops the archive's aggregate runtime revision, baseline/delta merge, expanded rollback snapshots, live-service registry, and config-owner handoff receipts because #114388 now owns those roster/owner transitions and row-scoped receipt transactions close the remaining concurrency invariant directly.

User Impact

  • Scheduled, startup catch-up, stream, and manual runs share one durable claim protocol.
  • Overlapping gateways cannot execute the same logical cron invocation concurrently.
  • A surviving gateway recovers reservations, running work, and settling receipts after an owner dies without requiring another restart.
  • Agent/config changes fence stale work before external effects and authoritative finalization.
  • Every admitted run leaves bounded durable receipt history; active receipts are never pruned.
  • Events and notifications describe committed state exactly once.

Release-note context: Cron execution ownership: record durable SQLite run receipts, fence overlapping gateway schedulers by exact process ownership, and supersede live results when the job's effective agent changes.

Evidence

  • Exact-head pull-request CI: head 80bafb0f7a9c95ba84fa58dce5c45d690703535f, run 31734932917, green.
  • External review gate: zero findings on the exact head; no autoreview was run per review policy.
  • Final touched tests, unfiltered: 26 files, 442/442 passed, including overlapping gateways, restart/handoff recovery, owner/config changes during live runs, reservation and settlement crash windows, authoritative-row finalization, Windows/null-start identity, older-reader reopen/use, and spoofed unavailable-agent error text.
  • Static proof: pnpm check:architecture, all pnpm tsgo:all lanes, pnpm check:test-types, targeted oxlint/oxfmt, dead-code export checks, and git diff --check passed.
  • Earlier hosted broad proof: changed gate on Testbox tbx_01kzwgh4ewf7cqekrhtab1s55k in run 31662123279; full TypeScript lanes on tbx_01kzwbz89eyrnxjkqpqh5b83se in run 31658015925; broad receipt/cron tests in run 31655061953. The final follow-up round used local unfiltered/type proof, with exact-head PR CI as the hosted final gate.
  • ClawSweeper disposition: the latest durable comment has no literal Rank-up moves: list. Its concrete before-merge moves were all applied: native-Windows process identity, older-reader database reopen/use proof, release-owned changelog removal, conflict resolution, and refreshed exact-head CI. No move was skipped.

@clawsweeper

clawsweeper Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: XL maintainer Maintainer-authored PR labels Aug 13, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. 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 Aug 13, 2026
@clawsweeper

clawsweeper Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 13, 2026, 6:16 AM ET / 10:16 UTC.

ClawSweeper review

What this changes

This PR adds durable SQLite receipts that fence scheduled, startup, stream, and manual cron runs so concurrent gateways and stale job owners cannot apply duplicate or obsolete effects.

Merge readiness

⛔ Blocked by patch quality or review findings - 10 items remain

Keep open: the prior P1 remains on the exact head—native Windows cannot obtain the required process-start identity, so every cron admission aborts before executing its payload. The PR also needs persistent-schema upgrade proof and removal of its release-owned changelog edit.

Priority: P1
Reviewed head: 8591c8056f1fa0c0b564319275cd2adfcda63d0c
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The durable-receipt approach has meaningful validation, but a supported-platform P1 and unresolved upgrade proof keep the patch below merge quality.
Proof confidence 🌊 off-meta tidepool Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; the PR body nevertheless cites real second-process cron coverage on Testbox.
Patch quality 🦪 silver shellfish (2/6) 3 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; the PR body nevertheless cites real second-process cron coverage on Testbox.
Evidence reviewed 6 items Windows identity behavior: The shared identity helper returns null outside Linux and Darwin; native Windows therefore has no identity through this path.
Exact-head regression contract: The receipt null-identity test is byte-identical at the previous reviewed head and current head; its supplied PR patch mocks the shared helper to null and requires the claim to throw.
Existing Windows-safe implementation: The repository already has a PowerShell-then-WMIC process-creation-time reader, and sibling identity paths route win32 through it.
Findings 3 actionable findings [P1] Preserve cron admission on native Windows
[P2] Prove reopening receipt databases with an older reader
[P3] Remove the release-owned changelog entry
Security None None.

How this fits together

Cron turns scheduled and manual job requests into agent, command, script, and webhook effects. The proposed receipt sits between admission and execution, then records the terminal outcome alongside the job’s next schedule.

flowchart LR
  A[Scheduled or manual cron request] --> B[Durable receipt claim]
  B --> C{Owner identity and receipt current?}
  C -->|yes| D[Execute payload or webhook]
  C -->|no| E[Skip or supersede run]
  D --> F[Atomic job and receipt finalization]
  F --> G[Notify and schedule next run]
Loading

Decision needed

Question Recommendation
Should this PR retain the same-version lazy receipt table after it has Windows identity support and explicit older-reader reopen proof, or should that persistence boundary be reshaped before merge? Keep the companion table with proof: Repair Windows admission and demonstrate older-reader reopen/use safety while preserving the lazy additive table design.

Why: The durable receipt design changes shared persisted state and requires maintainer judgment on the approved upgrade contract after the concrete platform bug is repaired.

Before merge

  • Preserve cron admission on native Windows (P1) - This contract makes a null process-start identity abort prepareCronRunReceiptClaim. On win32 the shared helper always returns null (src/shared/pid-alive.ts:108-113), so every scheduled, startup, and manual admission stops before its payload. Route Windows through readWindowsProcessStartTimeSync and add a Windows-path admission regression.
  • Prove reopening receipt databases with an older reader (P2) - Late finding: this unchanged test only checks SQL projection and does not show that a database after receipt creation can be opened and used by the prior reader. Same-version lazy tables depend on that upgrade guarantee; add an older-reader open/use and candidate-reopen regression.
  • Remove the release-owned changelog entry (P3) - CHANGELOG.md is release-generated and must not be edited by this normal PR; retain the user-impact context in the PR body instead.
  • Resolve merge risk (P1) - The new same-version receipt table and indexes need older-reader open/use plus candidate-reopen proof; the added projection test only proves that a fresh runtime can omit lazy tables.
  • Resolve merge risk (P1) - The PR body reports production +839/-18 for a bug fix; a durable receipt boundary may justify growth, but the unavailable exact-head blobs prevented an independent simplification audit.
  • Resolve merge risk (P1) - GitHub reports the current head as conflicted, so exact-head validation must be refreshed after the functional fixes and rebase.
  • Improve patch quality - Route receipt identity through the existing Windows creation-time reader and add a Windows-path regression.
  • Improve patch quality - Add older-reader open/use and candidate-reopen coverage for a database containing receipt rows.
  • Improve patch quality - Remove the release-owned changelog edit and refresh exact-head proof after resolving conflicts.

Findings

  • [P1] Preserve cron admission on native Windows — src/cron/store/run-receipt-store.null-start-time.test.ts:27-34
  • [P2] Prove reopening receipt databases with an older reader — src/state/openclaw-state-schema-compatibility.test.ts:5-11
  • [P3] Remove the release-owned changelog entry — CHANGELOG.md:71
Agent review details

Security

None.

PR surface

Source +1652, Tests +1399, Docs +1, Generated +16. Total +3068 across 57 files.

View PR surface stats
Area Files Added Removed Net
Source 26 1879 227 +1652
Tests 12 1433 34 +1399
Docs 1 1 0 +1
Config 0 0 0 0
Generated 18 33 17 +16
Other 0 0 0 0
Total 57 3346 278 +3068

Review metrics

Metric Value Why it matters
Production versus test delta production +839/-18; tests +432/-0; generated contracts +63/-17 (PR body) The receipt owner boundary is substantial bug-fix growth and needs a clear canonical-flow justification before merge.
Persistent state surface 1 lazy SQLite table and 2 indexes added Same-version additive storage is upgrade-sensitive and requires older-reader reopen/use proof.

Stored data model

Persistent data-model change detected: database schema: src/state/openclaw-state-schema-compatibility.test.ts, database schema: src/state/openclaw-state-schema-compatibility.ts, database schema: src/state/openclaw-state-schema.sql, migration/backfill/repair: src/cron/service/ops-lifecycle.ts, migration/backfill/repair: src/cron/service/run-recovery.ts, serialized state: src/cron/service/owner-hardening.test.ts, and 3 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Repair platform and upgrade behavior (recommended)
    Route Windows claims through the established creation-time reader, add Windows and older-reader regressions, and refresh proof on the rebased head.
  2. Pause the receipt rollout
    Do not merge if the team does not want to support this persistent-state contract and its required upgrade guarantees in this branch.

Technical review

Best possible solution:

Use the existing Windows creation-time reader for receipt identity, add a native-Windows admission regression and an older-reader reopen/use test for the lazy table, remove the changelog line, then rebase and publish exact-head cron proof.

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

Yes. On native Windows, getFileLockProcessStartTime returns null and the receipt claim’s exact-head test requires that condition to throw, so a scheduled, startup, or manual cron run aborts before payload execution.

Is this the best way to solve the issue?

No. A durable per-run receipt is a plausible owner boundary, but the current implementation regresses native Windows and lacks the required persisted-state upgrade proof.

Full review comments:

  • [P1] Preserve cron admission on native Windows — src/cron/store/run-receipt-store.null-start-time.test.ts:27-34
    This contract makes a null process-start identity abort prepareCronRunReceiptClaim. On win32 the shared helper always returns null (src/shared/pid-alive.ts:108-113), so every scheduled, startup, and manual admission stops before its payload. Route Windows through readWindowsProcessStartTimeSync and add a Windows-path admission regression.
    Confidence: 0.99
  • [P2] Prove reopening receipt databases with an older reader — src/state/openclaw-state-schema-compatibility.test.ts:5-11
    Late finding: this unchanged test only checks SQL projection and does not show that a database after receipt creation can be opened and used by the prior reader. Same-version lazy tables depend on that upgrade guarantee; add an older-reader open/use and candidate-reopen regression.
    Confidence: 0.9
    Late finding: first raised on code an earlier review cycle already covered.
  • [P3] Remove the release-owned changelog entry — CHANGELOG.md:71
    CHANGELOG.md is release-generated and must not be edited by this normal PR; retain the user-impact context in the PR body instead.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The proposed admission contract prevents every native Windows cron payload from running.
  • merge-risk: 🚨 compatibility: The PR adds a same-version persisted receipt table and changes cron admission on supported platforms.
  • merge-risk: 🚨 message-delivery: Cron admission controls whether agent and webhook payload effects are delivered.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is maintainer-authored work, so the external-contributor proof gate does not apply; the PR body nevertheless cites real second-process cron coverage on Testbox.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/cron/store/run-receipt-store.null-start-time.test.ts.
  • [P1] node scripts/run-vitest.mjs src/state/openclaw-state-schema-compatibility.test.ts.
  • [P1] Run a native-Windows cron admission scenario and an older-reader reopen/use scenario against the exact rebased head.

What I checked:

Likely related people:

  • steipete: Authored this PR and the merged ownership refactor that this follow-up explicitly builds on. (role: related feature owner and recent cron contributor; confidence: high; commits: 1ca60fbc3a3f, 8591c8056f1f; files: src/cron/service, src/cron/store/run-receipt-store.ts)
  • joshavant: Blame attributes the current lazy-additive schema contract and runtime projection to this contributor. (role: state-schema compatibility contributor; confidence: high; commits: 0901efe3ddf6; files: src/state/openclaw-state-db-contract.ts, src/state/openclaw-state-schema-compatibility.ts)

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 (8 earlier review cycles)
  • reviewed 2026-08-13T03:19:20.346Z sha d37f26acc048094bd5788046d45ad95dbbbbef93 :: found issues before merge. :: [P1] Reject same-agent configuration changes before stale effects | [P3] Remove the release-owned changelog entry
  • reviewed 2026-08-13T04:24:06.400Z sha 0b152be :: found issues before merge. :: [P1] Reject same-agent configuration changes before effects | [P3] Remove the release-owned changelog entry
  • reviewed 2026-08-13T05:11:29.615Z sha e4894ba :: found issues before merge. :: [P1] Fence same-agent configuration changes before effects
  • reviewed 2026-08-13T06:16:32.909Z sha c13c24c :: found issues before merge. :: [P1] Fence same-agent configuration changes before effects
  • reviewed 2026-08-13T07:05:06.001Z sha c13c24c :: found issues before merge. :: [P1] Fence same-agent configuration changes before effects
  • reviewed 2026-08-13T07:22:58.409Z sha c32d69f :: found issues before merge. :: [P1] Reject same-agent configuration changes before effects | [P3] Remove the release-owned changelog entry
  • reviewed 2026-08-13T08:20:46.476Z sha bae9351 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-13T08:34:28.264Z sha 5cd93f8 :: found issues before merge. :: [P1] Preserve cron admission on native Windows | [P3] Remove the release-owned changelog entry

@steipete
steipete force-pushed the claude/cron-owner-hardening branch 2 times, most recently from ad5ddb5 to 0b152be Compare August 13, 2026 03:28
@steipete
steipete marked this pull request as ready for review August 13, 2026 03:29
@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 13, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Aug 13, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 13, 2026
@openclaw-barnacle openclaw-barnacle Bot reopened this Aug 13, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 13, 2026
@steipete
steipete force-pushed the claude/cron-owner-hardening branch from 3240e17 to 1d6cb07 Compare August 13, 2026 16:57
@steipete
steipete marked this pull request as draft August 13, 2026 17:32
@steipete
steipete marked this pull request as ready for review August 13, 2026 17:32
@steipete
steipete merged commit d3308e2 into main Aug 13, 2026
131 checks passed
@steipete
steipete deleted the claude/cron-owner-hardening branch August 13, 2026 19:40
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 14, 2026
* fix(cron): fence concurrent executions durably

* refactor(cron): keep receipt hooks internal

* refactor(cron): hide internal save hooks

* test(cron): inspect receipts through SQLite

* test(cron): auto-clean process fixtures

* refactor(cron): avoid receipt service cycle

* fix(cron): harden receipt cleanup and retention

* refactor(cron): simplify receipt cleanup

* fix(cron): serialize owner updates with run leases

* fix(cron): hold run leases through settlement

* fix(cron): recover stale foreign run receipts

* fix(cron): complete durable receipt recovery

* fix(cron): preserve foreign handoff transitions

* fix(cron): make owner recovery atomic

* fix(cron): isolate reservation retries

* refactor(cron): scope runtime writes by job

* fix(cron): harden lazy receipts and reservations

* fix(cron): close startup recovery races

* fix(cron): make queued leases atomic

* fix(cron): unify receipt lifecycle recovery

* fix(cron): adjudicate stale receipts before fencing

* fix(cron): close terminal consistency gaps

* fix(cron): preserve terminal publication ordering

* fix(cron): break rebased store import cycles

* fix(cron): reconcile rebased finalization contracts

* fix(cron): type unavailable-owner settlement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant