Repository navigation
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 27, 2026, 12:36 AM ET / 04:36 UTC. ClawSweeper reviewWhat this changesThe PR separates operator, timer, and gateway on-exit cron execution so manual runs preserve scheduled one-shots while scheduler-owned executions retain deletion and rescheduling behavior. Merge readiness⛔ Blocked until stronger real behavior proof is added - 6 items remain Keep this PR open. The origin split is a strong boundary for preventing manual runs from consuming one-shot jobs, but the current error path still lets an operator failure contribute to scheduler retry accounting; a later timer failure can therefore inherit an inflated error count. The supplied live proof also predates the final-head error-accounting change, so it does not yet demonstrate the behavior that needs to merge safely. Likely related people: Priority: P1 Review scores
Verification
How this fits togetherOpenClaw's cron service persists scheduled jobs and their execution state, while the gateway exposes both operator-triggered runs and scheduler/on-exit triggers. Finalization updates job status, retry state, next-run timing, and deletion, which then determines what the next scheduler tick can execute. flowchart LR
A[Operator CLI or RPC] --> B[Cron service]
C[Timer scheduler] --> B
D[Gateway on-exit watcher] --> B
B --> E[Run-origin finalization]
E --> F[Persisted cron job state]
F --> G[Next scheduler tick]
E --> H[Job removal or retry outcome]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +140, Tests +1811. Total +1951 across 22 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Keep operator outcomes observable, but preserve scheduler-owned retry counters and retry/disable thresholds across operator runs; then add final-head live proof showing a manual error followed by a timer error uses only scheduled failure history. Do we have a high-confidence way to reproduce the issue? No fresh runtime reproduction was executed in this read-only review, but the affected mixed-origin path is high-confidence source-reproducible from the changed finalization and retry-state logic. Is this the best way to solve the issue? No. Separating origins is the right fix boundary, but the patch must also keep operator failures out of scheduler retry history rather than only suppressing their immediate backoff. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against a2eceb9b2fd9. LabelsLabel justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (75 earlier review cycles; latest 8 shown)
|
c0a3f5e to
6c8fdf9
Compare
|
Addressed the P1 finding in 6c8fdf9 — the manual-run guard now covers error outcomes too. Changes:
Also rebased on latest upstream/main (d60ab48, clean rebase, no conflicts). |
cf72fb7 to
d8f7ed5
Compare
|
Rebased on latest upstream/main (5e0850f, clean rebase, no conflicts). |
4eb14e6 to
3155142
Compare
|
Rebased on latest upstream/main (b7ba7c3, clean rebase, no conflicts). |
3155142 to
ebf32fe
Compare
|
Rebased on latest upstream/main (48acdd3, clean rebase, no conflicts). |
ebf32fe to
37d24fb
Compare
|
Rebased on latest upstream/main (94d8391, clean rebase, no conflicts). |
d505c29 to
734f827
Compare
|
Rebased on latest upstream/main (79197b3, clean rebase, no conflicts). |
|
ClawSweeper PR egg: 🔥 warming; proof passed, review follow-up or readiness checks remain. Hatch with Rules and detailsHatchability:
About:
|
734f827 to
16e917a
Compare
|
Rebased on latest upstream/main (a002c41, clean rebase, no conflicts). |
|
Rebased onto latest upstream/main (clean, no conflicts); the prior retry-config typing fix rebased in cleanly and src/cron lint/typecheck is green. @clawsweeper re-review |
|
Rebased onto latest upstream/main (clean, no conflicts); src/cron lint/typecheck stays green. @clawsweeper re-review |
1 similar comment
|
Rebased onto latest upstream/main (clean, no conflicts); src/cron lint/typecheck stays green. @clawsweeper re-review |
|
Rebased on latest upstream/main (bb657ee). Upstream split |
|
Rebased on latest upstream/main (9d2d5d1), clean rebase, no conflicts. @clawsweeper re-review |
|
Fixed CI (check-lint / check-test-types / node-compact-small shards) that went red after rebasing onto upstream's removal of the configurable cron.retry and maxConcurrentRuns knobs. resolveRetryConfig() and resolveRunConcurrency() now use built-in defaults, so the tests still referencing cronConfig.retry / cronConfig.maxConcurrentRuns no longer type-checked. Removed the test cases whose sole purpose was asserting the removed knobs (their default behavior is already covered by the sibling retry-hint and one-shot-disable tests) and dropped the now-invalid config fields from the remaining tests whose assertions still hold under the defaults. oxfmt --check clean; node scripts/run-lint.mjs src/cron reports 0 src/cron errors; targeted vitest on both touched files: 111 passed / 0 failed. @clawsweeper re-review |
|
Rebased onto latest upstream/main. The rebase surfaced a regression from the upstream cron refactor: the manual-run origin gate had become too broad and was suppressing error accounting (consecutiveErrors, lastRunStatus=error, failure alerts) for manual runs. Narrowed the gate so only scheduler-consuming success/lifecycle state (deleteAfterRun, one-shot disable-on-success, next-run advance, retry-backoff scheduling) stays non-consuming for manual runs, while error counters, failure-alert emission, and evaluated trigger gate state are recorded for all origins. Full cron suite green (1666/1666). @clawsweeper re-review |
|
Rebased on latest upstream/main (ec06118). Upstream split |
|
Fixed CI failures on the rebased head (test-only changes, no source behavior change):
New head d8ac00735e. |
Manual `cron run` invocations are verification/debugging tools and should not consume the one-shot guarantee. Previously, a manual run on a `deleteAfterRun: true` job would both delete the job and disable it, silently destroying the scheduled future fire. Add an `isManual` flag to `applyJobResult()` opts. When set: - `deleteAfterRun` is skipped (job preserved in store) - One-shot disable logic is skipped (job stays enabled with its original `nextRunAtMs`) - An info log is emitted so operators can see the job was preserved Both manual run paths (`finishPreparedManualRun` and `skipInvalidPersistedManualRun`) now pass `isManual: true`. Timer-driven paths remain unchanged. Closes openclaw#83538
…cheduled timer path
The disabled-heartbeat one-shot retry and exhaustion tests asserted scheduled
retry state (consecutiveSkipped, backoff nextRunAtMs, eventual disable) but
drove execution via cron.run(job.id, "due"). Manual cron runs no longer mutate
scheduled retry/disable state, so these assertions belong on the scheduled
timer path. Rewrite both cases to seed the store and advance through onTimer
ticks, and add a manual-run regression proving cron.run("due") records the run
outcome (lastRunWasManual) without advancing retry/disable state.
The UTF-16 code-point boundary truncation test drove the failure alert
through the manual cron.run("force") path, but manual runs intentionally
no longer emit failure alerts (they are non-consuming verification runs).
Route the test through simulateScheduledRun so it exercises the scheduled
execution path that actually emits the alert, matching the other
alert-text formatting tests in this file.
… test The previous change routed the UTF-16 truncation test through simulateScheduledRun but also dropped the runIsolatedAgentJob mock, which createFailureAlertCron requires, causing a check-test-types failure (TS2741: Property 'runIsolatedAgentJob' is missing). Restore the mock so the helper type-checks while still driving the alert through the scheduled execution path.
…cess The recurring-job success/skipped branch in applyJobResult recomputed nextRunAtMs unconditionally, so a manual ok/skipped run on an enabled every/cron job would overwrite a pending scheduled error-backoff window with the natural next fire. That let a manual verification run clear the scheduled backoff, breaking the non-consuming manual-run contract. Guard the recompute behind !isManual, mirroring the already-guarded error branch, so manual runs leave nextRunAtMs untouched. Disabled jobs still reset nextRunAtMs to undefined regardless of manual. Adds a regression test covering manual success during a pending recurring error-backoff.
… misclassification
Replace the triggerEvalOnly/isManual boolean inference in the cron service
with an explicit CronRunOrigin enum ("timer" | "watcher-terminal" | "operator")
threaded from every entry point, so scheduler-state consumption and
deleteAfterRun deletion are decided by the caller's origin rather than
inferred from run mode + trigger outcome.
- operator (manual RPC/CLI run): non-consuming; never mutates scheduled
counters/backoff/nextRunAtMs and never deletes deleteAfterRun jobs.
- timer (scheduled tick, incl. quiet trigger-eval and evaluator errors):
consuming; errors increment consecutiveErrors and route through execution
backoff, quiet ticks keep counters at zero with stagger-aware reschedule,
and scheduled one-shot deleteAfterRun runs delete and emit the removed
snapshot.
- watcher-terminal (gateway on-exit force): consuming for deleteAfterRun so a
pre-disabled on-exit success is deleted, preserving the base contracts.
This removes the two regressions the previous inference caused: operator due
checks whose evaluator errored or did not fire were misread as scheduled and
mutated scheduler state, and every force run was treated as manual so
watcher-terminal on-exit deletions were skipped.
The RPC handler enqueues runs without an origin parameter, so external clients
cannot inject a consuming origin; only the in-process gateway watcher sets
watcher-terminal.
skipInvalidPersistedManualRun hard-coded origin "operator" when finalizing a persisted job that fails spec validation at preflight. The gateway on-exit watcher reaches this path with origin "watcher-terminal", so invalid watcher-terminal runs were mis-attributed as operator, causing scheduler-owned counters, alerts, and terminal state to diverge from other watcher executions. Thread the resolved CronRunOrigin from run() through inspectManualRunPreflight into skipInvalidPersistedManualRun and pass it to applyJobResult, defaulting to "operator" only for genuinely origin-less callers. Add a regression test asserting watcher-terminal invalid runs keep scheduled/consuming scheduler-state semantics while operator invalid runs stay operator-attributed.
The explicit CronRunOrigin was exposed through the public CronServiceRunOptions, so any in-process facade caller (plugin SDK, RPC handlers, tests) could pass origin "watcher-terminal" and gain scheduler-owned consuming semantics — deleting deleteAfterRun one-shots or mutating scheduler counters, backoff, and nextRunAtMs. That widened an internal seam into public API. Remove origin from the public run options so the public run is always operator semantics, and give the gateway on-exit watcher a concrete-only CronService.runOnExitTerminal entry (absent from CronServiceContract and GatewayCronServiceContract) that keeps watcher-terminal consuming behavior. The watcher already holds the concrete CronService instance, so no plumbing is needed. The internal ManualRunOptions.origin seam and the timer/operator paths are unchanged. Add invariant coverage: the public facade run preserves a deleteAfterRun one-shot (operator semantics, no scheduler-state mutation) even though it can no longer request another origin, while runOnExitTerminal still consumes a successful on-exit one-shot.
Upstream moved onTimer and executeJobCore out of timer.ts into the timer.test-support.ts helper module, so the leftover imports from timer.js broke tsgo type checking (TS2459). Point the three affected cron test files at ./timer.test-support.js to match the new layout.
A due deleteAfterRun one-shot 'at' job that receives an operator (manual) ok run keeps its nextRunAtMs preserved because an operator run does not consume the one-shot. But computeJobNextRunAtMs collapsed the pending slot whenever the last run status was ok, so the next expired-slot maintenance recompute wiped nextRunAtMs and stranded the job as a zombie that never fires and never deletes. Guard the ok-branch collapse with lastRunWasManual !== true so only a scheduler-owned (timer) ok run retires the slot; manual/operator ok runs leave the pending scheduled fire intact. Reuses the already-persisted lastRunWasManual field, so it is restart-safe with no new state or migration. Add a regression test covering the manual ok run surviving maintenance recompute and a restart reload, then firing and deleting on a real scheduled timer tick (existing coverage only exercised skipped runs).
…ance recompute After rebasing onto upstream's scheduleMode-based maintenance recompute, the origin-threaded manual run path referenced an out-of-scope mode flag and applyTriggerNoFireResult still read a removed opts.scheduleMode field. - finishPreparedManualRun runs with operator origin, so it repairs expired slots via a plain maintenance recompute instead of the scheduler-only force-preserve pin. - applyTriggerNoFireResult drops the dead scheduleMode preserve branch: operator runs already return before schedule advancement, and scheduler quiet ticks advance normally, matching the origin model.
…ode removal Upstream replaced the applyJobResult scheduleMode enum with built-in defaults and added coverage asserting a forced operator run on a paced job keeps its pending slot. The origin refactor no longer passed scheduleMode, so the preserve branch went dead and operator runs on paced jobs advanced the slot. - applyJobResult now preserves the scheduled slot for a non-owning (operator) run on a paced job, matching upstream's forced-run pacing coverage while leaving non-paced due runs and scheduler-owned timer/ watcher paths free to advance. - finishPreparedManualRun pins its own expired paced slot for forced runs during post-run maintenance recompute so an expired pending fire is preserved rather than recomputed. - Refresh the pacing regression to drive the forced-run case through the origin option instead of the removed scheduleMode field.
Upstream removed the configurable cron.retry knob (CronRetryOn export and CronConfig.retry) in favor of built-in defaults. Adopt the current resolveRetryConfig() zero-arg shape and import CronRetryOn from retry-hint, thread the required run origin through the invalid-persisted-manual skip paths, and split the oversized ops regression suite so it stays under the max-lines ratchet.
Upstream removed the configurable cron.retry and maxConcurrentRuns knobs from CronConfig; resolveRetryConfig() and resolveRunConcurrency() now use built-in defaults. Delete the test cases whose sole purpose was asserting the removed knobs (their default behavior is covered by sibling retry-hint and one-shot-disable tests), and drop the now-invalid config fields from the remaining tests whose real assertions still hold under the defaults.
…uler-consuming success state Manual run origin must remain non-consuming only for scheduler-owned success/lifecycle state (deleteAfterRun, one-shot disable-on-success, next-run advance, retry-backoff scheduling). It must NOT suppress error accounting: a failed manual run still increments consecutiveErrors, records lastRunStatus=error, and emits failure alerts like a scheduled run. Narrow the origin gate in applyJobResult/applyTriggerNoFireResult so error counters, failure-alert emission, and evaluated trigger gate state are recorded for all origins, while pending-slot and next-run advance stay scheduler-owned. Align the affected regression tests.
…path The "preserves global skipped alerts alongside an owned failure destination" case triggered its skip via cron.run(job.id, "force"), which defaults to origin=operator. Under the run-origin model a manual operator run is non-consuming: it records the outcome but leaves scheduler-owned state untouched, so consecutiveSkipped is not bumped and the opt-in skip alert never fires (see the openclaw#83933 origin regression that asserts an operator skip keeps consecutiveSkipped undefined). Error alerts are origin-independent by design, which is why the sibling error cases still pass through a force run. Skip alerting runs off the scheduler-owned skip counter, so this case belongs on the scheduled path like every other skip-alert test in the file. Drive it through simulateScheduledRun (origin=timer) so it actually exercises what it means to: a scheduled skip must still emit the global skip alert even when the job declares an owned failure destination, since that destination suppresses error alerts only. The assertions are unchanged.
The failure-alert suite grew past the 1000-line max-lines cap for test
files after a scheduler-driven skip-alert case was added. Move the
delivery-routing group (global vs per-job destinations, owned failure
destinations, and mode/accountId threading) into a focused sibling,
service.failure-alert.delivery.test.ts, leaving threshold/text/
classification cases in place. Both files now sit well under the cap.
Also replace the unchecked `(cron as any).state` access in the
simulateScheduledRun helper with the explicit
`(cron as unknown as { state: CronServiceState }).state` form already
used elsewhere, so the type-suppression inventory stays at zero
unchecked any casts.
The three command delete/retain/backoff cases invoked the run via cron.run(job.id, "force"/"due"), which now resolves to operator origin and is deliberately non-consuming: it records the outcome but never deletes a deleteAfterRun one-shot, applies error backoff, or otherwise mutates scheduler-owned state (openclaw#83538/openclaw#83933). The public facade cannot request watcher-terminal/timer semantics by design, so these cases were asserting scheduler-owning outcomes against a non-owning run. Drive them through the real scheduler tick instead (cron.start() + onTimer, origin=timer) — the actual production path for scheduled command jobs. The successful one-shot is deleted even when announce delivery fails, the required-delivery failure retains the one-shot with backoff, and the recurring command error applies backoff. Assertions are unchanged.
|
Thank you, @Jerry-Xin, for investigating and proposing the original repair. The maintainer-selected, narrower ownership fix has landed in #114491 and closes #83538; your contribution is credited with a Co-authored-by trailer on the merged commit. The landed fix additionally preserves queued manual runs that cross the scheduled deadline, keeps already-due and on-exit behavior unchanged, and is proven with live packaged-Gateway/Docker output plus the full cron suite. Closing this now that the underlying issue is fixed on main. |
What Problem This Solves
openclaw cron run(a manual/operator run) on adeleteAfterRunone-shot ("at") job used to delete the job on success — consuming the one-shot so its scheduled fire never happened (issue #83538). Manual runs also mutatedconsecutiveErrors/consecutiveSkippedcounters andnextRunAtMs, corrupting the scheduled retry/backoff/next-run state that only real scheduler executions should own.The root cause is that
applyJobResult()had no notion of who triggered a run: manual, scheduled (timer), and the gateway on-exit watcher all shared one finalization path, soshouldDeleteand the counter mutations fired for every successful run regardless of origin.Why This Change Was Made
The fix threads an explicit
CronRunOrigin("timer" | "watcher-terminal" | "operator") through cron finalization.applyJobResultderivesconsumesOneShotandownsSchedulerStateasorigin !== "operator"and recordslastRunWasManual = origin === "operator", so operator runs record the outcome only (never consume adeleteAfterRunone-shot, never touch scheduler counters /nextRunAtMs/ enabled state), whiletimerandwatcher-terminalruns keep consuming and owning scheduler state — preserving the merged on-exitdeleteAfterRuncontract from #104550.originis kept strictly internal. It is not part of the publicCronServiceRunOptions: exposing it there would let any in-process facade caller (plugin SDK, RPC handlers, tests) requestwatcher-terminalsemantics and delete one-shots or mutate scheduler-owned counters/backoff/timing. Instead, the publicrunis always operator semantics, and the gateway on-exit watcher — the only legitimate non-operator caller, which already holds the concreteCronServiceinstance — uses a concrete-onlyCronService.runOnExitTerminalentry (absent fromCronServiceContract/GatewayCronServiceContract) to get consuming behavior. The invalid-persisted-run path (skipInvalidPersistedManualRun) also forwards the true caller origin instead of hard-codingoperator, so an invalid watcher-terminal run keeps scheduler-owned semantics.User Impact
deleteAfterRunjob no longer silently cancels its upcoming scheduled fire.run.Evidence
Real-setup proof at the current head using a real running OpenClaw gateway process and the real
openclaw cronCLI (not a vitest/function harness). Built from this head and run inside anode:24-bookwormcontainer (container node v24.18.0; the repo engines floor is 24.15.0), against a real on-disk cron store (sqlite).Unit/regression coverage at head: the public
CronServiceContract.runpreserves adeleteAfterRunone-shot (operator semantics, no scheduler-state mutation) even though it can no longer request another origin,CronService.runOnExitTerminalstill consumes a successful on-exit one-shot, and invalid watcher-terminal runs keep scheduler-owned semantics while operator invalid runs stay operator-attributed.Persisted-state coverage for
lastRunWasManual(timer.backoff-config-readback.test.ts, real on-disk sqlite store): a fresh store where a manual/operator error run persistslastRunWasManual: true, reloads from sqlite, and keeps the natural next-run slot (no backoff floor,consecutiveErrorsuntouched) so the scheduled fire still triggers on a fresh service state; and an upgraded store whose persisted job predates the field (nolastRunWasManualon disk) — on reload the absent field is treated as a scheduled run, so the error backoff window still applies and the past-due slot is correctly suppressed. This proves the new optional field degrades safely for both new and pre-existing stores.Proof equivalence: transcript head → current head
The live-setup transcript above was captured at
c071ce7c. The branch head has since been rebased onto newermain(current headc42041b0). Scoped to the cron runtime surface exercised by the transcript (src/cron/service/,src/gateway/server-cron.ts), the full non-test delta betweenc071ce7cand the current head is:export-keyword removals on now-module-local symbols —onTimer,executeJobCore(timer.ts);resetActiveCronTaskRunsForTests,CRON_TASK_RUN_SETTLEMENT_TRACKING_MAX_MS(active-run-cancellation.ts);DEFAULT_JOB_TIMEOUT_MS,AGENT_TURN_SAFETY_TIMEOUT_MS(timeout-policy.ts). Values and in-module usage unchanged; no prod file outside each defining module imported them.timer.tsandactive-run-cancellation.tsnow expose those test-only helpers via aglobalThissymbol registered inside anif (process.env.VITEST || process.env.NODE_ENV === "test")guard, imported by new*.test-support.tsmodules. This block is a no-op in a production gateway./* oxlint-disable max-lines */directive comments (jobs.ts,ops.ts,timer.ts,server-cron.ts).mainchange fix(cron): cap trigger script tool access #104430 ("cap trigger script tool access") —mergeCronPayloadand itstoolsAllowhelpers moved out ofjobs.tsinto the newsrc/cron/service/payload-merge.ts, with cross-payload-kindtoolsAllowmarker handling. This is genuine upstream behavior on thecron.updatepayload-merge / trigger-script tool-access surface, disjoint from scheduler counters and one-shot consumption; it arrived through the rebase and is not part of this PR's proof scope.server-cron.tstoolsAllowtype-guard simplification — the trigger-script call now readsjob.payload.toolsAllowdirectly (valid once fix(cron): cap trigger script tool access #104430 liftedtoolsAllowto a sharedCronPayloadfield) instead of gating onkind === "agentTurn". This is on the trigger-script tool-access path, not therunOnExitTerminal/ delete-after-run wiring.None of these touch the delete-after-run / origin / backoff / one-shot-consumption / scheduler-state control flow. The
CronRunOriginthreading,consumesOneShot/ownsSchedulerState(origin !== "operator"),lastRunWasManual(origin === "operator"),shouldDelete = wouldDelete && consumesOneShotintimer.ts, theops.tsorigin forwarding, and therunOnExitTerminalwiring inserver-cron.tsare unchanged. The recorded operator-preservation and watcher-terminal-consumption behavior therefore holds on the current head. Reviewers can confirm the delta with:Follow-up fix: manual ok run must not strand the one-shot slot
A further defect on the same origin-threading surface: a due
deleteAfterRunone-shotatjob that receives an operator (manual) ok run keeps itsnextRunAtMspreserved (operator runs do not consume the one-shot), butcomputeJobNextRunAtMs'sat-branch collapsed the pending slot toundefinedwhenever the last run status wasok. The next expired-slot maintenance recompute then wiped the slot, stranding the job as a zombie that never fires and never deletes. Existing coverage only exercisedskippedruns, so theokpath was missed.Fix: the ok-branch collapse in
computeJobNextRunAtMsis now guarded bylastRunWasManual !== true, so only a scheduler-owned (timer) ok run retires the slot; manual/operator ok runs leave the pending scheduled fire intact. This reuses the already-persistedlastRunWasManualfield, so it is restart-safe with no new state or migration (an absent field on a pre-upgrade store is treated as a scheduled run, preserving prior behavior). A regression test drives a manual ok run on a due deleteAfterRun one-shot through the maintenance recompute and a restart reload (slot preserved both times), then a real scheduled timer tick that fires and deletes it.