Skip to content

fix(cron): release queued reservations when activation fails - #141008

Merged
fuller-stack-dev merged 4 commits into
openclaw:mainfrom
holny:fix/139215-cron-ticks
Sep 15, 2026
Merged

fuller-stack-dev merged 4 commits into
openclaw:mainfrom
holny:fix/139215-cron-ticks

Conversation

@holny

@holny holny commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Refs #139215 — kept open. After a closer pass through the timer-scheduler callers, the producer-side cleanup alone does not demonstrate the reported missing-tick fix, so this PR should not auto-close the issue.

What Problem This Solves

When the write that moves a cron run from queued to running fails, the job can be left holding a durable queuedAtMs marker, an open run receipt, and a process-local reservation. Three facts from the current code:

  • executeQueuedCronRun only released its own reservation when the failure happened after activation (if (activated) in the .catch).
  • persistQueuedCronRunReservations skips jobs whose queuedAtMs is already set, so a surviving marker blocks later re-queuing.
  • Recovery treats an own-process receipt as live (never stale), so it won't reclaim it.

The timer scheduler does have a batch-level safety net: a mapper-level catch stops admitting further due jobs, and the batch tail calls releaseUnclaimedDueJobReservationsWithRetry → cleanupQueuedCronRunReservations, which settles the receipt as skipped, deletes queuedAtMs, and recomputes nextRunAtMs. So on the normal timer path a queued-phase failure self-heals at the end of that batch. The marker survives only where that batch-tail cleanup itself fails (store still erroring through the tail) or on callers without the net.

That residual window does not, by itself, demonstrate the reporter's observed shape (missed occurrences with no receipt at all, manual force-runs succeeding), so this PR is a producer-side hardening, not a proven fix for every reported occurrence.

Why This Change Was Made

The queued producer owns the reservation it receives, so its failure path should release that exact reservation rather than defer to the caller's net. Any admission or queued-phase failure now runs the same cleanupQueuedCronRunReservations the post-activation path already used: the receipt settles as skipped, the marker clears, and the next tick re-queues and runs the job. The cleanup is identity-matched, so it stays a no-op once another claimant has taken over. The batch-level nets in the timer scheduler and startup catch-up are unchanged.

The earlier approach on this branch (proving own-process liveness inside repairInDatabase) is fully reverted — recovery semantics are unchanged.

User Impact

Jobs that fail during admission or the queued phase settle immediately instead of waiting on the batch tail; the residual wedge window shrinks to store failures that also defeat the batch-tail cleanup. No schema, config, or API changes.

Evidence

Current qualification, 2026-09-15.

Original production repair by @holny; maintainer qualification preserves its ancestry and identity-matched cleanup. No unrelated timing blocks or recovery changes were imported.

Five focused regression designs

  • Baseline producer from the PR merge-base, using the same final fixtures: 2 expected failures (durable marker survives; local reservation survives). This is a fault-injected before/after comparison, not an untouched-main run.
  • Fixed direct producer: 3/3 passed — activation-write rejection, pre-activation callback rejection, and replacement-identity preservation. The activation test also preserves the same-time sibling's marker, receipt and local ownership.
  • Fixed Gateway scheduler controls: 2/2 passed, 135 unrelated cases skipped — activation failure followed by a later cron-expression tick; an execution failure does not swallow due siblings.
  • These five tests use real SQLite and scheduler code, but mock isolated-agent execution. Earlier contributor-reported full-suite numbers are historical, not current-head qualification.

Real local runtime trace

A separate isolated process used the candidate source, Node 24.20.0 on macOS, real SQLite, the production wall-clock timer and runCronCommandJob. No Vitest, fake timers, product monkeypatching, model call or operator Gateway was involved. A temporary SQLite trigger injected only the selected queued-to-running write failure; it was removed before the timer was armed.

02:32:49.141Z durable reservation: receipt running, localOwned=true
02:32:49.145Z activation rejected: injected real activation write failure
02:32:49.146Z BEFORE arming scheduler: queuedAtMs=null, runningAtMs=null,
                  localOwned=false, admissionActive=0, original receipt=skipped
02:32:49.147Z real wall-clock timer armed
02:32:51.159Z cron event: started
02:32:51.193Z native child: scheduled-command-executed
02:32:51.217Z cron event: finished, status=ok
02:32:51.244Z original receipt=skipped; new receipt=ok;
                  localReservations=0, admissionActive=0, activeTimerTicks=0
02:32:51.274Z disposed: timer=null, admissionActive=0, activeTimerTicks=0

The child wrote its completion artifact and exited successfully through the production command runner. This demonstrates immediate producer cleanup followed by real scheduled command execution. It does not claim real model/provider execution, full-Gateway startup or reproduction of the receipt-free missing ticks in #139215.

Maintained checks and review

  • Published candidate: 1d1e62d098c1795057a274465e1d09aefa0c9ff7, with unchanged tested/reviewed source bytes.
  • Fresh independent final-source review: scoped-clean P0–P2, including test design and real runtime evidence.
  • oxfmt, targeted oxlint, core production and test type checks, native schema, dependency pins/patches, boundary/coercion/deprecation/import checks, and maintained dead-export scans passed.
  • Local check:changed stopped at the pre-existing dated sdk-untrusted-context-identifier-aliases removal guard (removeAfter: 2026-09-08). Current main marks that unrelated SDK item removal-pending. All 18 subsequent checks from the maintained plan were run separately and passed; no guard was disabled and no unrelated SDK policy was copied into this PR.
  • Exact-head hosted CI and native prepare/merge remain pending. Earlier CI and earlier source-only reviews are not final-head proof.

CI repair continuation — 2026-09-15

  • Published head: c016b10d3754a2c0caba421b199593ce37094250. Integrated main 7bf5deb308ed73fd3b327752eb6cc1b2907128b1 by ordinary merge; holny’s original commit and all three cron patch payloads are preserved.
  • Previous exact-head CI run34922026897 failed one newly merged model-policy integration test (job104232305427); 3051 other tests in that lane passed. The test read model state after a chat admission ACK instead of waiting for command completion.
  • Replaced expect.poll with the existing agent.wait terminal result, requiring success before asserting the same history model. No production behavior, timeout, or test count changed.
  • The unchanged test passed locally; the recorded CI failure is the observed timing-sensitive reproduction, not a claimed deterministic local failure. Both repaired model-policy cases and21 existing terminal-wait controls passed (23/23).
  • Fresh independent final-candidate review is clean at P0–P2. The earlier five cron designs and isolated native-command proof remain historical qualified evidence, not newly rerun tests.
  • Maintained check:changed passed in full, including the Gateway test-type graph, dead-export scans and targeted lint. New exact-head hosted CI is pending. Native preparation/merge remain gated on required CI and the independently owned trusted non-force cleanup route.

@clawsweeper

clawsweeper Bot commented Sep 7, 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 gateway Gateway runtime size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 7, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 11:20 PM ET / September 15, 2026, 03:20 UTC (Revision 6).

ClawSweeper review

What this changes

Release a scheduled job’s queued reservation when admission or activation fails, add cleanup and scheduler regression coverage, and make a model-policy integration test await command completion.

Merge readiness

✅ Ready for maintainer review

This remains a useful, bounded repair absent from current main and the latest release. No blocking patch defect was found, and the supplied runtime evidence supports the narrowed cleanup claim without establishing a fix for the related missing-tick report.

Priority: P2
Reviewed head: c016b10d3754a2c0caba421b199593ce37094250

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful ownership controls, sufficient runtime evidence, and no blocking findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The captured macOS terminal trace exercises the reservation producer with a real SQLite activation fault, observes immediate cleanup, then records successful execution through the production timer and native command runner. Historical proof remains relevant to the preserved cleanup change; it does not prove the linked missing-tick report.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The captured macOS terminal trace exercises the reservation producer with a real SQLite activation fault, observes immediate cleanup, then records successful execution through the production timer and native command runner. Historical proof remains relevant to the preserved cleanup change; it does not prove the linked missing-tick report.
Evidence reviewed 10 items Current main still needs the repair: The fetched main implementation still guards reservation cleanup with activated, leaving pre-activation rejection dependent on caller cleanup.
Latest-release comparison: The v2026.9.4 source also retains the activated-only cleanup guard; this repair is not already present in that release.
Cleanup preserves reservation ownership: The introduced catch invokes the existing cleanup owner. That owner checks reservation identity inside the serialized transaction, settles the receipt, clears matching markers, and releases only matching local ownership. No recovery policy, schema, public API, or authorization rule is introduced.
Findings None None.
Security None None.

How this fits together

OpenClaw’s cron scheduler reserves due jobs before admitting them for execution. Reservation cleanup settles their execution receipts and clears scheduling markers so subsequent runs can proceed.

flowchart TD
  A[Due scheduled job] --> B[Durable queued reservation]
  B --> C[Admission and activation]
  C -->|Success| D[Execute job]
  C -->|Failure| E[Identity-checked cleanup]
  E --> F[Settle receipt and clear marker]
  F --> A
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -2, Tests +379. Total +377 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 7 9 -2
Tests 3 389 10 +379
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 396 19 +377

Review metrics

None.

Technical review

Best possible solution:

Keep failure cleanup with the reservation producer, preserve identity fencing and caller safety nets, and investigate receipt-free missing ticks separately.

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

Yes, for the narrow producer defect: reject the queued-to-running write and inspect reservation state before caller cleanup. Current main retains the faulty guard; this review did not execute that reproduction.

Is this the best way to solve the issue?

Yes. Extending the existing identity-checked cleanup to pre-activation failures repairs the owning boundary without adding a competing recovery mechanism.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded cron failure-cleanup repair with existing caller safety nets, rather than a demonstrated fix for widespread missed schedules.
  • 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 (terminal): The captured macOS terminal trace exercises the reservation producer with a real SQLite activation fault, observes immediate cleanup, then records successful execution through the production timer and native command runner. Historical proof remains relevant to the preserved cleanup change; it does not prove the linked missing-tick report.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured macOS terminal trace exercises the reservation producer with a real SQLite activation fault, observes immediate cleanup, then records successful execution through the production timer and native command runner. Historical proof remains relevant to the preserved cleanup change; it does not prove the linked missing-tick report.

Evidence

What I checked:

  • Current main still needs the repair: The fetched main implementation still guards reservation cleanup with activated, leaving pre-activation rejection dependent on caller cleanup. (src/cron/service/run-admission.ts, 5b1d6e02a0f8)
  • Latest-release comparison: The v2026.9.4 source also retains the activated-only cleanup guard; this repair is not already present in that release. (src/cron/service/run-admission.ts, 3a9d69db306c)
  • Cleanup preserves reservation ownership: The introduced catch invokes the existing cleanup owner. That owner checks reservation identity inside the serialized transaction, settles the receipt, clears matching markers, and releases only matching local ownership. No recovery policy, schema, public API, or authorization rule is introduced. (src/cron/service/run-admission.ts:670, c016b10d3754)
  • Regression coverage distinguishes producer cleanup from caller recovery: Three direct cases cover activation-write rejection, admission callback rejection, and replacement-identity preservation. Two Gateway cases cover later scheduled execution and execution-failure siblings. The direct assertions inspect cleanup before the scheduler’s existing batch-tail safety net can conceal the defect. (src/cron/service/run-admission.lost-queued.test.ts:111, c016b10d3754)
  • Real production-path evidence: The supplied body snapshot, sourceRevision 84e777bae5c79823f94a5bd8e8e0958128cd1a5940c8f57239c06422c8f9f4e6, records Node 24.20.0 on macOS with real SQLite, an injected activation-write failure, the production wall-clock scheduler, and the production command runner. Before arming the timer, markers and local ownership were cleared and the original receipt was skipped; a later native command completed with a new successful receipt. This is historical qualification of candidate 1d1e62d, not a reviewer-run test. (1d1e62d098c1)
  • Re-review continuity: The prior reviewed source and current source preserve the same producer-cleanup change. Their surrounding differences come from integrated main work, including atomic activation results and running-receipt fields. The pinned introduced delta contains no earlier recovery rewrite, so the historical sibling-service receipt finding no longer applies. Missing local historical blobs prevented a complete local comparison; GitHub contents supplied the earlier production file for direct comparison. (src/cron/service/run-admission.ts:668, c016b10d3754)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

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 (5 earlier review cycles)
  • reviewed 2026-09-07T08:14:44.488Z sha 8e50f977be605d21b81a8285b722913ee17f8458 :: needs real behavior proof before merge. :: [P1] Preserve live receipts owned by sibling service instances
  • reviewed 2026-09-09T16:05:46.888Z sha ecfe687 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-10T03:11:25.598Z sha ecfe687 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-10T08:02:06.784Z sha ecfe687 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-15T02:47:51.081Z sha 1d1e62d :: needs maintainer review before merge. :: none

A transient store failure between the durable queued marker and run
activation left the job holding its own queuedAtMs marker, an open
receipt, and a process-local reservation. Every later tick skipped the
job behind that marker, so cron-expression runs went silent until
restart (openclaw#139215).

Release the reservation from the producer on any admission or
queued-phase failure: the receipt settles as skipped, the marker
clears, and the next tick re-queues and runs the job. Recovery
semantics are unchanged.
@holny
holny force-pushed the fix/139215-cron-ticks branch from 8e50f97 to ecfe687 Compare September 9, 2026 15:58
@holny holny changed the title fix(cron): reclaim own-process queued runs whose outcome was lost fix(cron): release queued reservations when activation fails Sep 9, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 9, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. and removed P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Sep 9, 2026
@fuller-stack-dev fuller-stack-dev self-assigned this Sep 15, 2026
Preserve holny's PR openclaw#141008 producer repair and qualify activation and
admission failures, replacement ownership, and scheduler siblings.
Keep receipt-free missing ticks in openclaw#139215 outside this claim.
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 15, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 15, 2026
@fuller-stack-dev
fuller-stack-dev merged commit d8e50a3 into openclaw:main Sep 15, 2026
397 of 399 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 15, 2026
…w#141008)

* fix(cron): release queued reservations when activation fails

A transient store failure between the durable queued marker and run
activation left the job holding its own queuedAtMs marker, an open
receipt, and a process-local reservation. Every later tick skipped the
job behind that marker, so cron-expression runs went silent until
restart (openclaw#139215).

Release the reservation from the producer on any admission or
queued-phase failure: the receipt settles as skipped, the marker
clears, and the next tick re-queues and runs the job. Recovery
semantics are unchanged.

* test(cron): qualify exact queued-reservation cleanup

Preserve holny's PR openclaw#141008 producer repair and qualify activation and
admission failures, replacement ownership, and scheduler siblings.
Keep receipt-free missing ticks in openclaw#139215 outside this claim.

* test(gateway): await model reset command completion

---------

Co-authored-by: Jason (Json) <[email protected]>
vincentkoc added a commit that referenced this pull request Sep 15, 2026
* commit 'd8e50a38fd1c4df6dd69bcbc155697c464e1be45': (23 commits)
  fix(cron): release queued reservations when activation fails (#141008)
  fix(gateway): reduce CPU work in session lists and searches (#148713)
  feat(gateway): add admin CPU profile diagnostics (#148004)
  fix(gateway): cap device-required probe cache to prevent unbounded growth (#147708)
  fix(ci): align Gateway E2E expectations (#148653)
  refactor(ai): remove unused overflow wrapper (#148719)
  feat: stage selected chat text as editable comments (#148649)
  fix(ci): admit reachable release refs with large histories (#148161)
  fix(agents): allow authorized email CLI actions (#148521)
  improve(agents): trim large tool results with less CPU (#148718)
  refactor(docker): share image version parsing (#148243)
  fix(ci): retain passing hosted checks after skipped duplicates (#148722)
  fix(update): report configuration failures during repair (#144819)
  refactor(imessage): share handle classification (#148229)
  fix(ui): keep the selected agent across Settings pages (#148667)
  test(telegram): reuse deferred fixture helper (#148501)
  fix(media): resize images before understanding (#122431)
  fix: preserve unfinished work during completed PR cleanup (#148704)
  refactor(migrate-hermes): reuse canonical config record coercion (#148645)
  perf(channels): reduce history worker metadata footprint (#148711)
  ...
vincentkoc added a commit to nvtoroy/openclaw that referenced this pull request Sep 15, 2026
Reuse the landed test correction from openclaw#141008 so the assertion observes the completed reset before requesting history.

Co-authored-by: holny <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime 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: M 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