Repository navigation
fix(cron): prevent missed events and broken recovery - #149673
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 16, 2026, 1:50 AM ET / 05:50 UTC (Revision 3). ClawSweeper reviewWhat this changesRepairs automation timing, interrupted-run recovery, command timeout reporting, stream matching, and command-exit rearming, while including the related delivery/accounting fixes and small CI repairs. Merge readiness⛔ Blocked before merge - 2 items remain The scheduler repairs remain useful and are not implemented on the inspected main revision. Both previous findings are addressed; this review found no new blocking correctness defect. The related PR covers only the shared delivery/accounting portion. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s Gateway scheduler turns saved schedules, watched command exits, and stream output into automation runs. It coordinates execution ownership, completion history, and delivery to conversations or webhooks. flowchart TD
A[Saved jobs and schedules] --> C[Scheduler and event watchers]
B[Command exits and stream lines] --> C
C --> D[Bounded matching and eligibility]
D --> E[Durable run admission]
E --> F[Payload execution]
F --> G[Settlement and recovery]
G --> H[Run history and delivery]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +724, Tests +2414, Docs +12. Total +3150 across 60 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep matching off the Gateway thread and preserve atomic receipt ownership, with the author-documented bounded failure and explicit re-enable behavior. Do we have a high-confidence way to reproduce the issue? Yes: current main’s truncated matching path and separate exit-disable/run sequence establish concrete failure mechanisms, with focused regressions and recorded Gateway scenarios. This read-only review did not execute them. Is this the best way to solve the issue? Yes: the patch repairs the existing scheduler, receipt, and watcher owners rather than adding competing scheduling state, while preserving current configuration and storage formats. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 29ed7e3b810a. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
aee17fe to
ff6e924
Compare
Share the existing enable reset for disabled and exhausted jobs, persist recovered stream state through declaration no-op detection, and retain running jobs’ failure streaks during routine convergence.
Carry reclaimed run outcomes into the shared recovery publisher so timer recovery finalizes the exact task, preserves failed history, and emits a finished event before scheduling a successor. Keep startup and foreign-owner recovery on the same publisher.
Evaluate complete intake-bounded lines before batch truncation so long anchored patterns do not silently miss events. Keep safe pattern compilation and oversized-input handling unchanged.
Keep the pending minimum interval after quiet, fired, and busy trigger checks, including evaluations that finish between cron expression slots. Count completed quiet evaluations during restart catch-up so a previous fired payload does not cause an already evaluated occurrence to replay. Preserve stale-slot repair and genuinely missed catch-up. Add service regressions covering maintenance, restart, and exact eligibility boundaries, and document the existing interval and quiet-evaluation contracts. Validation: 207 focused cron tests passed; regressions failed before repair; isolated review found no actionable P0-P2 findings. Targeted formatting, diff checks, and docs MDX checks passed.
Share the pending trigger interval predicate between scheduling repair and restart admission without growing the scheduling owner. Inline its only backoff wrapper at the existing repair decision and explicitly enable the cadence regression fixtures required by the creation contract. Validation: 167 focused cron tests, syntax lint including max-lines, formatting, and diff checks passed. Independent review found no actionable P0-P2 findings.
Keep observed exits pending through durable receipt cleanup, then reserve their run and disable the job in the existing admission transaction. Preserve cancellation, FIFO capacity waits, queued rearming, and delete-after-run ownership. Gate adopted exits until the replacement scheduler starts, including retry after startup failure, and cancel outer Gateway admission waits with the watcher. Validation: 101 focused Gateway, watcher, receipt, and admission checks; meaningful negative controls for queue ownership, handoff ordering, and closed-fence cancellation; real ProcessSupervisor and durable-receipt timeout proof. Fresh full-owner Codex review is clean through P2. No schema, configuration, or public API changes.
931cfc0 to
1b2e54a
Compare
|
Merged via squash.
|
|
@steipete The canonical test-only follow-up is #149836; it was already being prepared by another lane when I checked this merged PR after the exact CI failure blocked #148962. The directly authored on-exit fixture inherits a due I am reusing the existing repair at |
* fix(cron): reset failures when declarations re-enable jobs Share the existing enable reset for disabled and exhausted jobs, persist recovered stream state through declaration no-op detection, and retain running jobs’ failure streaks during routine convergence. * fix(cron): record interrupted runs during timer recovery Carry reclaimed run outcomes into the shared recovery publisher so timer recovery finalizes the exact task, preserves failed history, and emits a finished event before scheduling a successor. Keep startup and foreign-owner recovery on the same publisher. * fix(cron): match complete stream source lines Evaluate complete intake-bounded lines before batch truncation so long anchored patterns do not silently miss events. Keep safe pattern compilation and oversized-input handling unchanged. * fix(cron): preserve trigger cadence through maintenance and restart Keep the pending minimum interval after quiet, fired, and busy trigger checks, including evaluations that finish between cron expression slots. Count completed quiet evaluations during restart catch-up so a previous fired payload does not cause an already evaluated occurrence to replay. Preserve stale-slot repair and genuinely missed catch-up. Add service regressions covering maintenance, restart, and exact eligibility boundaries, and document the existing interval and quiet-evaluation contracts. Validation: 207 focused cron tests passed; regressions failed before repair; isolated review found no actionable P0-P2 findings. Targeted formatting, diff checks, and docs MDX checks passed. * fix(cron): rearm on-exit jobs during payload completion * fix(cron): retain command timeout output after cleanup * fix(cron): retain rearmed exits until prior payloads settle * test(cron): cover scheduler recovery through the public CLI * refactor(cron): isolate pending trigger interval checks Share the pending trigger interval predicate between scheduling repair and restart admission without growing the scheduling owner. Inline its only backoff wrapper at the existing repair decision and explicitly enable the cadence regression fixtures required by the creation contract. Validation: 167 focused cron tests, syntax lint including max-lines, formatting, and diff checks passed. Independent review found no actionable P0-P2 findings. * refactor(cron): isolate declaration comparison helpers * fix(cron): bound full-line stream matching in workers * fix(cron): atomically admit observed exits after settlement Keep observed exits pending through durable receipt cleanup, then reserve their run and disable the job in the existing admission transaction. Preserve cancellation, FIFO capacity waits, queued rearming, and delete-after-run ownership. Gate adopted exits until the replacement scheduler starts, including retry after startup failure, and cancel outer Gateway admission waits with the watcher. Validation: 101 focused Gateway, watcher, receipt, and admission checks; meaningful negative controls for queue ownership, handoff ordering, and closed-fence cancellation; real ProcessSupervisor and durable-receipt timeout proof. Fresh full-owner Codex review is clean through P2. No schema, configuration, or public API changes. * fix(cron): publish recovered receipts before on-exit admission * fix(cron): narrow committed on-exit reservations
Follows #149697 (merged). This PR contains only the scheduler repairs; the already-merged delivery commits have been removed from its stack.
What Problem This Solves
Fixes cron jobs losing observed exits or stream matches, evaluating conditions too soon after maintenance or restart, and failing to recover cleanly after interruption or automatic disablement.
User Impact
Conditions retain their minimum interval, matching stream lines fire before delivery truncation, and interrupted or timed-out runs retain useful history and output. Operators can re-enable declarations and on-exit watches, including while the preceding payload is still finishing. Existing configuration needs no migration or new settings. Database schemas, stored job/receipt/history formats, and retention are unchanged; existing-state restart and recovery regressions cover the repaired lifecycle.
Why This Change Was Made
The repairs stay with the existing scheduler, admission, receipt, and watcher owners:
Stream matching uses at most two shared-compute workers, 32 outstanding requests, 8 MiB of accounted input, and a three-second request deadline covering queueing and execution. Exceeding a budget stops the source with a recorded error; operators can inspect the expression or Gateway load and re-enable it. The deadline includes shared-compute queueing, so sustained load can stop a valid stream. This is an intentional availability tradeoff; the failure is visible and recovery is explicit.
Evidence
The integrated focused run passed 517 tests across 28 files, covering scheduler cadence, declarations, receipt recovery, command timeout/cancellation, watcher races, stream handling, Gateway drain, and worker lifecycle. The additional dead-receipt regression failed with the retired helper name and passed with the correction; it checks interrupted history/events before successor reservation and both final receipt outcomes. All seven matcher tests passed again after the final lint repairs. Targeted typed lint and diff checks passed, and independent reviews through P2 are clean, including the final integration and regression.
The complete production build and permanent five-flow public-CLI Gateway suite passed at final head
1b2e54aa6c2ac16ae93e9b7a877f58e3d9077c3d: quiet-trigger restart timing, full-line matching and child shutdown, command timeout output, rearming during a pending payload, and repeated declarative recovery.A separate registered-Gateway-owner proof used real supervised children with a payload runner deliberately held after abort. Before release, two observed exits produced one reservation and one payload while the receipt remained active. After release, exactly two reservations and payloads completed, history retained the timeout and success, the job was disabled, and the receipt retired. All owned children and isolated state were cleaned up. This supplements the public-CLI suite; it does not claim an HTTP or model round trip. Earlier two-process recovery proof also recorded exactly one interrupted task/history event without payload replay.
A final-head registered-Gateway fixture also injected one benign matcher timeout. It verified durable error/history with no payload, completed source teardown, and successful matching after
cron.update(enabled: true): exactly one payload and both history entries retained. Recovery used the real matcher worker; the process and outbound sink were fixtures. This joins the existing queue/deadline/overload tests without claiming public-CLI saturation testing.Hosted live checks passed the five scheduler flows and all ten tool-allowlist cases across OpenClaw and Codex at
ff6e92471fba9e808df121b97f10f5e868b164fd.CI then found a strict-indexing type error in the first-reservation guard. The final correction explicitly narrows that entry and reuses the existing receipt map instead of allocating a duplicate set. It preserves admission behavior and passed 71 tests across six files, core and services-test type checks, typed lint, formatting and fresh independent review through P2.
Current candidate:
1b2e54aa6c2ac16ae93e9b7a877f58e3d9077c3d. All 14 scheduler commits are patch-identical after moving the stack onto merged main. Required CI completed successfully on this head. Final-head production build and all five public-CLI Gateway flows also passed.