Skip to content

fix(cron): scheduled jobs stay stopped after a native worker exits - #194048

Merged
obviyus merged 4 commits into
openclaw:mainfrom
indra622:fix/cron-closed-worker-lease-194032
Nov 12, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
indra622:fix/cron-closed-worker-lease-194032

Conversation

@indra622

@indra622 indra622 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #194032

What Problem This Solves

Fixes scheduled jobs staying stopped after their shared-state native worker exits while the Gateway keeps running.

User Impact

Eligible jobs resume on the same running service after recoverable worker loss. Paused scheduling stays paused; intentional shutdown or database retirement does not restart it. The original incident's trigger is unknown, so this does not attribute it to OOM.

Why This Change Was Made

Forward the existing native-loss fact to cron's connection owner. Drain the old work and native custody, recheck the original database admission and current service lifecycle, then use the existing scheduler/receipt path to reconnect. No new schema, persistence contract, permissions, configuration, timer framework, or failed-mutation replay.

Evidence

  • Before production edits, a real-worker service regression completes one scheduled job, terminates the actual native worker, then stalls on the next job. It passes with the fix, with pause/resume, stop and database-retirement controls.
  • An isolated actual Gateway and public CLI create two harmless /usr/bin/printf command jobs with delivery disabled. After real native worker termination, the second job executes autonomously exactly once, the first complete run-history entry is unchanged, and the Gateway PID stays the same. Owned Gateway and port-helper exits are both 0. No model or external delivery is used.
  • Eight focused suites / 75 tests pass, including the required cron scheduler, lease/native-loss/settlement, queue and lifecycle scopes. Touched typecheck, lint, format, test-line ratchet and diff checks pass. The runtime cliStartup build and bootstrap guard pass; a full release/UI/declaration build and hosted CI are not claimed.
  • Fresh independent parent source/proof review of f7a46e85d26ad28de5eba194a386731ed28a518f..fd186b2b53d0aaee0f2d5dd4ee44259bfabe333b found no actionable issue. Source/test hashes match the precommit review. Local autoreview/ClawSweeper was not run.

The original production trigger and an active-SQL-write fault are not reproduced. The base red is the real-worker service boundary; the Gateway scenario covers the fixed candidate. Setup attempts rejected before startup or waiting on obsolete readiness wording are not counted as product reds. A separate terminal-upload temp-root warning was unrelated to this no-upload scenario.

Maintainer update: merged current main (conflict with #196387 resolved; the native-loss callback attaches only to the persistent lease that exists while cron is enabled). The worker-recovery unit suite and its test-lines allocation were removed; the built-Gateway matrix below replaces it (main twice, candidate twice, plus pause, shutdown, in-process restart and moved-state-folder controls): #194048 (comment). Recovery now retries with backoff until a live store answers (ClawSweeper P1); proof: #194048 (comment). Production delta against main +97/-8; tests 0.

Portable reproduction and actual CLI/Gateway evidence

Real cron worker-loss proof: issue #194032

Fixed source commit: fd186b2b53d0aaee0f2d5dd4ee44259bfabe333b. Base: f7a46e85d26ad28de5eba194a386731ed28a518f. Node v24.22.1, pnpm 12.15.0, macOS arm64. The isolated Gateway reported OpenClaw 2026.11.1.

What ran

The real OpenClaw launcher (node openclaw.mjs gateway run) started an isolated, loopback-only Gateway. Public CLI cron add, cron runs, and cron status commands communicated with it. Two admin-authored command jobs invoked /usr/bin/printf, with delivery disabled, and used the real cron store, shared-state native worker, scheduler, command executor, and durable run history. No model request or external delivery was needed.

A proof-only Node preload observed the worker's existing postMessage boundary without changing messages. It selected the actual worker receiving cron.scheduler* commands and called that Worker's real terminate() on a test signal. The Gateway process stayed alive and kept the same PID. This is real native worker loss, not a mocked lease rejection. The test signal was SIGWINCH, not OpenClaw's SIGUSR2 restart signal.

Before/after evidence

Before production editing, the real CronService integration scenario at the base completed its first scheduled no-op, recorded its durable result, terminated the native shared-state worker, and then stalled waiting for the second scheduled no-op. The milestone trace was:

proof: service started
proof: first scheduled run committed [ 'before-loss' ]
proof: real native worker exited; awaiting second scheduled run [ 'before-loss' ]
Test timed out in 10000ms.
exit: 1

This red reached the actual defect rather than failing setup. Production code was still at the base. The committed table-driven regression retains that recovery scenario and adds pause/resume, stop, and intentional database-retirement controls.

The fixed isolated Gateway/CLI run observed:

PROOF_NATIVE_WORKER_BOUND <same-gateway-pid>
PROOF_NATIVE_WORKER_EXITED 1
PASS: public CLI jobs ran before and after native worker loss; prior receipt unchanged
exit: 0

The runner's phrase “prior receipt unchanged” refers to exact equality of the full durable run-history entry returned by the public CLI. Private run IDs encode the isolated store path and are intentionally omitted here.

Sanitized projection of the actual CLI results:

{
  "outcome": "passed",
  "gatewayPidUnchanged": true,
  "nativeWorkerExited": true,
  "beforeRun": {
    "jobName": "proof-before-loss",
    "status": "ok",
    "completionStatus": "succeeded",
    "summary": "proof-before-loss",
    "durationMs": 9,
    "deliveryStatus": "not-requested"
  },
  "afterRun": {
    "jobName": "proof-after-loss",
    "status": "ok",
    "completionStatus": "succeeded",
    "summary": "proof-after-loss",
    "durationMs": 8,
    "deliveryStatus": "not-requested"
  },
  "beforeRunHistoryUnchanged": true,
  "eachJobRunCount": 1,
  "schedulerEnabled": true,
  "gatewayExit": 0,
  "portClaimExit": 0
}

There was no manual run, job edit, cron-service replacement, or Gateway restart after the native fault. The second job had already been created before fault injection. Polling cron runs only observed completion. Each job had exactly one successful history entry, with delivery not-requested; the first entry was unchanged after recovery.

Build and focused validation

The repository runtime/CLI build profile ran before the Gateway scenario:

node --import ./scripts/tsx.mjs scripts/build-all.mts cliStartup

Exit 0; 44.2 seconds; CLI bootstrap import guard passed. It builds runtime JavaScript and startup metadata; this is not a full release/declaration/UI build. Build metadata still named the base because the local commit was created afterward. The built recovery algorithm/source snapshot is the one subsequently committed; the only later source adjustments were a callback-local rename and erased test generic typing, with no recovery behavior change. Parent-reviewed source hashes match the final commit.

pnpm test src/cron/service.scheduler-regressions.test.ts src/cron/store/scheduler-actor.worker.test.ts --maxWorkers=1
# exit 0: 25 tests
pnpm test src/state/openclaw-state-worker-lease.test.ts src/infra/sqlite-worker-shared-state-idle.test.ts src/state/openclaw-state.worker.settlement.test.ts src/cron/service.run-queue.test.ts src/cron/service/ops-lifecycle.start-arm.test.ts --maxWorkers=1
# exit 0: 46 tests
pnpm test src/cron/service.worker-recovery.test.ts --maxWorkers=1
# exit 0: 4 tests; recovery, pause/resume, stop, intentional database retirement

The new file's final standalone wall time was 30.65 seconds including 23 seconds of compilation; the four actual tests took about 4.48 seconds total (1.56, 1.26, 0.84, 0.82 seconds). CI seconds are not yet available. The real native timer is exercised because injecting only a host wake would bypass the stalled worker-owned timer. No new test-only production hook was added.

Targeted typecheck, lint and formatting passed, as did the exact 120-line test allocation ratchet and git diff --check. The state/queue suites retain the existing accepted-write, native-cleanup, receipt and uncertain-settlement checks; no failed mutation is explicitly replayed by this repair.

Portable reproduction

Use a disposable local directory on a sufficiently large safe filesystem, a checkout containing the fixed commit, Node v24.22.1 and pnpm 12.15.0. Install dependencies physically in that checkout with a local store. Never point this scenario at operator state or an existing Gateway.

  1. Build with the cliStartup command above.
  2. Create isolated OpenClaw home, state, workspace, config and temporary directories. Configure gateway.mode: local, loopback binding, a claimed free port, a fresh local token, agents.ownership: explicit, agents.entries.main: {}, cron.enabled: true, and disabled plugins/browser/Control UI. The successful scenario used no ambient credentials. Keep the token private.
  3. Start the real launcher under the preload below, setting only the child process's OPENCLAW_HOME, OPENCLAW_STATE_DIR, OPENCLAW_CONFIG_PATH, TMPDIR, NODE_COMPILE_CACHE and NODE_OPTIONS=--import=<fault-worker.mjs>. Wait for [gateway] ready; retain the port claim through shutdown. The repository's acquireTestPortBlock from src/test-utils/port-claims.ts supplied the claim in the recorded run.
  4. Use public CLI commands in the same isolated environment:
node ./openclaw.mjs cron add --name proof-before-loss --agent main \
  --at <future-ISO-time> --command-argv '["/usr/bin/printf","proof-before-loss\\n"]' \
  --session isolated --no-deliver --keep-after-run --json
node ./openclaw.mjs cron runs --id <first-job-id> --limit 10
# Wait for the first job's single successful result, then create the second:
node ./openclaw.mjs cron add --name proof-after-loss --agent main \
  --at <future-ISO-time> --command-argv '["/usr/bin/printf","proof-after-loss\\n"]' \
  --session isolated --no-deliver --keep-after-run --json
# The recorded run used five seconds in the future for each job.
kill -WINCH <pid-from-PROOF_NATIVE_WORKER_BOUND>
# Observe PROOF_NATIVE_WORKER_EXITED, then inspect without manually running anything:
node ./openclaw.mjs cron runs --id <second-job-id> --limit 10
node ./openclaw.mjs cron runs --id <first-job-id> --limit 10
node ./openclaw.mjs cron status
  1. Require one ok result per job, full equality of the first history entry before/after, and unchanged Gateway PID. Stop only this owned Gateway with SIGTERM, await exit, and release the port claim. Both owned process exits were 0 in the successful run.

Exact proof-only preload (fault-worker.mjs):

import { isMainThread, Worker } from 'node:worker_threads';
import { deserialize } from 'node:v8';
if (isMainThread) {
  let target;
  let announced = false;
  const post = Worker.prototype.postMessage;
  Worker.prototype.postMessage = function (message, ...args) {
    if (message?.type === 'execute' && message.input instanceof Uint8Array) {
      const command = deserialize(message.input);
      if (command?.type?.startsWith('cron.scheduler')) {
        target = this;
        if (!announced) {
          announced = true;
          process.stdout.write(`PROOF_NATIVE_WORKER_BOUND ${process.pid}\n`);
        }
      }
    }
    return Reflect.apply(post, this, [message, ...args]);
  };
  process.on('SIGWINCH', () => {
    if (!target) throw new Error('No cron shared-state worker captured');
    const worker = target;
    target = undefined;
    void worker.terminate().then((code) => {
      process.stdout.write(`PROOF_NATIVE_WORKER_EXITED ${code}\n`);
    });
  });
}

This fixture belongs only to the disposable Gateway. It forwards every original worker message unchanged and terminates only the worker selected by actual cron scheduler commands. Do not preload it into a production Gateway or send its signal to any unrelated process.

Limits and setup history

The original production trigger remains unknown; this proves recovery from deliberately induced idle native loss and does not establish OOM or reproduce the reported nine-hour incident. The real Gateway scenario covers the fixed path; the exact base red is the real-worker service boundary, not a second base Gateway build. Existing state/queue tests support settlement safety; there is no new claim to have faulted an active SQL write in the Gateway scenario.

A first fixture used the retired agents.list config and failed before startup. A second Gateway was healthy but the orchestration waited for an obsolete listening-log format; that setup attempt was intentionally canceled and drained. Neither is counted as a product red. The successful third attempt used the observed [gateway] ready signal. The Gateway also logged an unrelated terminal-upload temp-root warning for the validation volume's ancestor permissions; no upload was used, and the command jobs/receipts completed successfully. No mount permissions or global settings were changed.

No live accounts, external sends, user Gateway changes, or publication occurred. Parent source review is separate from publication. All task-owned runtime/test/build processes were joined and stopped; requested evidence was retained.

@clawsweeper

clawsweeper Bot commented Nov 6, 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.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 6, 2026
@clawsweeper

clawsweeper Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Reconnects cron scheduling after native worker loss and retries failed replacement starts with bounded backoff.

Example: The SQLite worker exits after the 04:36 scheduled run while the Gateway remains running.

  • Before: Replacement startup can fail once and leave subsequent scheduled runs stopped indefinitely.
  • After: Recovery retries until a healthy worker answers, allowing the 04:37 and 04:38 runs to execute once each.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, useful recovery repair with production-entry-point proof and no remaining finding; the exact concurrent-borrower incident timing was not forced, but repeated failed replacement startup was exercised successfully.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The built isolated Gateway and public automation commands exercise the real shared-state worker, scheduler, command side effects, and durable history; the current-head storm trace shows recovery after repeated replacement-worker deaths, with earlier unchanged lifecycle controls covering pause, shutdown, restart, and moved state.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Scheduled automations stop indefinitely after their native worker exits, despite the Gateway remaining available.
Reason: Restoring eligible scheduled execution has clear value, and the collaborator's repair and Gateway matrix establish direction without introducing a new user-facing policy.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current scheduler recovery defect, and the new retry loop resolves the previous finding; no additional actionable defect was found.

Priority: P1
Reviewed head: 201726305d6963f0eb9aeb39f31a0ce56041c82a

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gateway cron connection submits scheduling operations to the shared-state SQLite worker and launches its committed run requests through the existing durable queue.

flowchart TD
  A[Native worker loss] --> B[Shared state lease]
  B --> C[Cron connection owner]
  C --> D[Lifecycle and database checks]
  D --> E[Scheduler restart with backoff]
  E --> F[Existing durable run queue]
Loading

Technical review

Best possible solution:

Land scheduler-owned reconnection with retry while preserving the existing lifecycle, database-admission, and durable-run owners.

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

Current-main source retains a permanently closed scheduler lease, and the supplied built-Gateway comparisons demonstrate stopped scheduling after worker exit or OOM; no target code was executed during this review.

Is this the best way to solve the issue?

The change uses the existing connection and lease owners, joins old work, and restarts through durable scheduling rather than replaying failed mutations; each added production hunk serves that repair.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +89. Total +89 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 97 8 +89
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 97 8 +89

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #194032
Summary: This PR owns scheduler recovery; the related agent-opening PR prevents one distinct cause of worker retirement.

Members:

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Native worker loss can indefinitely suppress all scheduled automations while the Gateway remains running.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-06T09:18:59.397Z sha fd186b2 :: needs maintainer review before merge. :: none
  • reviewed 2026-11-12T04:10:19.112Z sha 9471487 :: needs changes before merge. :: [P1] Keep recovery pending until the dead shared-state store can be replaced

Reviewed November 11, 2026, 11:46 PM ET / November 12, 2026, 04:46 UTC (Revision 3).

@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Maintainer proof for the merged head (main 43fc7446e8 merged in, no conflicts left with #196387's borrowed leases).

Setup. Built Gateway (pnpm build, node openclaw.mjs gateway run) in a secretless node:24.22.1 container, isolated home/state/config. One automation per run: automations create "* * * * *" --command "date -u +%H:%M:%S >> ticks.log". No model, no delivery.

The fault. The shared-state SQLite worker is a worker thread inside the Gateway process, so it can't be killed as a separate OS process. Instead we stopped it from outside with no OpenClaw code change and no preload. kill -USR1 <gateway pid> opens Node's built-in inspector. A small CDP client then attaches to the sqlite-store.worker.js thread that has openclaw-state.worker loaded and makes it either crash (process.exit(1)) or run out of heap (it hits its 512 MiB resourceLimits, ERR_WORKER_OUT_OF_MEMORY). The Gateway pid stays up throughout. Each run: one normal slot, kill at about :17, then two more slots. An operator automations edit after the first post-kill slot forces a scheduler refresh.

run fault runs after the kill (one per minute slot expected) cron log
main-1 (43fc7446e8) exit none; nextWake=03:35:00 (PAST) at 03:35 and 03:36 cron: worker refresh delayed | SqliteWorkerError: Shared-state worker lease is closed
main-2 OOM none; nextWake=03:41:00 (PAST) same lease is closed
cand-1 (this PR) exit 03:38:00, 03:39:00 one cron: scheduler reconnected after native worker loss (03:37:21)
cand-2 OOM 03:44:00, 03:45:00 one reconnect (03:43:22)

Run history (automations runs --json) matches the side-effect file exactly in every run: one ok per slot, no duplicates. Example, cand-1: 3 runs: ok@03:37:00 ok@03:38:00 ok@03:39:00. Main-1: 1 runs: ok@03:34:00, and that is all.

Controls

  • Paused scheduling stays paused. Scheduling was paused with gateway.suspend.prepare, then the worker was killed. Candidate: no run and no reconnect while paused (ticks=1 at 03:47:17). After gateway.suspend.resume at 03:47:19, one reconnect at 03:47:20 and one catch-up run for the missed slot, then 03:48 and 03:49. Main with the same steps: after resume, lease is closed on every refresh and no further runs.
  • Intentional shutdown. Every run ends with SIGTERM. The Gateway exits in 2-3 s with zero reconnect or recovery-failed lines after the signal.
  • Database retirement. After the kill and reconnect, an in-process restart (kill -USR2) closes and retires the shared-state database. It then reopens cleanly and the job keeps one run per slot (03:56, 03:57). The only reconnect line is the one before the restart.
  • Moved state folder. mv the state folder, then kill the worker. The Gateway notices the moved state lock and starts its own restart path. Cron logs shutdown left work for recovery and stops. There is no reconnect and no new state/openclaw.sqlite at the old path. Main behaves the same.
  • Normal operation. The first slot before any fault runs once on main and candidate alike. Nothing reconnects without a worker loss.
Worker kill client (proof only, runs outside the Gateway)
const [port, mode] = process.argv.slice(2);
// node kill-worker.mjs <inspectorPort> <exit|oom|list>
const targets = await (await fetch(`http://127.0.0.1:${port}/json/list`)).json();
const ws = new WebSocket(targets[0].webSocketDebuggerUrl);
// NodeWorker.enable -> attachedToWorker for every worker thread
// per worker: Debugger.enable, collect scriptParsed URLs
// shared-state carrier = the thread whose scripts include "openclaw-state.worker"
// then Runtime.evaluate in that thread:
//   exit: process.exit(1)
//   oom:  for (;;) fill.push(new Array(1e6).fill(Math.random()))

PR changes on top of the contributor's commit: merged current main, resolving the scheduler-actor.ts conflict with #196387. The native-loss callback now attaches only to the persistent lease, created when cronEnabled. Borrowed per-refresh leases used while cron is disabled don't need it, because each borrow already opens a fresh lease. Also removed service.worker-recovery.test.ts and its test-lines allocation; this e2e matrix replaces it. Production delta against main: +70/-7 in three files. Tests: 0.

@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 12, 2026
@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Follow-up for the ClawSweeper P1 (a single reconnect attempt that fails is never retried), at head 201726305d.

Change. Recovery is now a single retry loop per cron service. If the replacement scheduler fails to start, because the dead store is still held or its worker dies during startup, the lost slot is put back. The loop waits 250 ms, doubling up to 30 s, and tries again. It stops when a scheduler is running, or when cron is paused, stopped or changes generation. Pause, stop and admission checks are the same as before. Waits end early on shutdown. A replacement that loses its worker during startup no longer starts a second, competing recovery.

Proof (same container and harness as before). The new "storm" fault ends the shared-state worker. It then ends each replacement worker as soon as that worker loads the shared-state module, which is while cron's reconnect is still starting. The faults come from outside through the Node inspector; no OpenClaw code is changed.

build storm after the storm cron log
previous head 5b010a5c 3 workers ended (the second 0.56 s after the first, mid-reconnect) no runs at 04:34 or 04:35; nextWake=04:34:00 (PAST) one cron: worker recovery failed | SQLite worker stopped before its result was received, then nothing
this head 201726305d 4 workers ended within 1.7 s runs at 04:37:00 and 04:38:00, one each, matching run history three worker recovery failed (04:36:17, :18, :19), then scheduler reconnected after native worker loss at 04:36:20

The single-kill case still works on this head (cand2-1: kill at 04:39:17, reconnect at 04:39:19, run at 04:40:00). A busy-worker variant ran on the previous head: six audit.list reads were in flight when the worker exited, and cron recovered there too. So the concurrent-borrower timing from the issue report can't be forced from outside in this setup. Killing the replacement during startup does reach the same failure (a failed start with no retry), and this head recovers from it.

@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 12, 2026
@indra622

Copy link
Copy Markdown
Contributor Author

Thanks @obviyus for updating this against current main, resolving the borrowed-lease conflict, and exercising the real Gateway lifecycle controls and replacement-worker storm.

The important follow-up is the failed-start retry at 201726305d6963f0eb9aeb39f31a0ce56041c82a: losing a replacement worker during reconnect must not leave cron permanently stopped after a single attempt. Your storm and single-kill results, together with the pause/shutdown/restart/moved-state matrix, cover that gap. The latest exact-head review now reports no remaining actionable findings and marks it ready for maintainer review.

The original concurrent-borrower incident timing remains unforced; the demonstrated recovery from repeated replacement-start failures should not be presented as reproducing that exact incident. Your code updates and the Gateway matrix replacing the earlier recovery unit suite are preserved. No new execution or merge is claimed by this acknowledgement.

@obviyus
obviyus merged commit 231fae1 into openclaw:main Nov 12, 2026
142 of 143 checks passed
@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Landed in 231fae1. Thanks @indra622.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 13, 2026
…penclaw#194048)

fix(cron): recover the scheduler after the shared-state worker is lost

When the shared SQLite worker hosting cron exited while the Gateway kept running, for example when it ran out of its 512 MiB heap, cron kept its closed connection. Every refresh then failed with "Shared-state worker lease is closed", status still reported cron enabled with a wake time in the past, and nothing ran until a restart. Cron now reacts to the existing worker-lost signal on its persistent lease: it closes the dead connection and starts a replacement scheduler, retrying with a capped backoff if the replacement fails to start, and stops retrying when a scheduler is running or cron is paused, stopped or changes generation. Paused scheduling, intentional shutdown, database retirement and a moved state folder do not trigger recovery. Stored formats are unchanged. Recovery adds two operator log lines.

Evidence: a built Gateway in a secretless node:24.22.1 container with a one-minute command automation, the shared-state worker thread ended from outside through the Node inspector by exit or by exhausting its heap, with the Gateway process staying up, two runs each. On main, every refresh after the loss failed with "lease is closed", no later slot ran and the next wake stayed in the past; with this change cron reconnected once and the next slots ran once each, matching run history with no duplicates. Ending each replacement worker during startup left main's previous recovery stuck, and this head retried and recovered. Paused scheduling, SIGTERM shutdown, an in-process restart and a moved state folder behave as intended. Details: openclaw#194048 (comment) and openclaw#194048 (comment).

Closes openclaw#194032. Thanks @indra622.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 17, 2026
Backport #194048 with an abortable-timer adaptation for the stable baseline.
Retain one recovery owner and prove native replacement loss and delivery.

Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot added a commit that referenced this pull request Nov 21, 2026
Port the stable native-loss regression from a77c494 and add the accepted bounded failure-only transport trace. Main contains the production recovery from #194048 but not this regression, so the main delta is 156 test lines (85 original plus 71 diagnostic lines).

Keep original faults, assertions, deadlines and cleanup. Observe scalar open/start replies, native exits and existing recovery logs only; transport success is not lease readiness. No production changes or claim that the unresolved release scheduler failure is fixed. Parent reviewed the complete candidate and accepted diagnostic patch e416e0c441ed9fb5e2f2f802a8e9d791150157a84be25274e40914eda3adde34.

Co-authored-by: Hosung Park <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 21, 2026
Port the stable native-loss regression from a77c494 and add the accepted bounded failure-only transport trace. Main contains the production recovery from #194048 but not this regression, so the main delta is 156 test lines (85 original plus 71 diagnostic lines).

Keep original faults, assertions, deadlines and cleanup. Observe scalar open/start replies, native exits and existing recovery logs only; transport success is not lease readiness. No production changes or claim that the unresolved release scheduler failure is fixed. Parent reviewed the complete candidate and accepted diagnostic patch e416e0c441ed9fb5e2f2f802a8e9d791150157a84be25274e40914eda3adde34.

Co-authored-by: Hosung Park <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: RomneyDa <[email protected]>

(cherry picked from commit 112ba9e)

Adaptation: candidate already contains the original 85-line test; retain it and apply only the reviewed 71-line diagnostic delta.

Co-authored-by: vincentkoc <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 22, 2026
…203104)

Port the stable native-loss regression from a77c494 and add the accepted bounded failure-only transport trace. Main contains the production recovery from openclaw#194048 but not this regression, so the main delta is 156 test lines (85 original plus 71 diagnostic lines).

Keep original faults, assertions, deadlines and cleanup. Observe scalar open/start replies, native exits and existing recovery logs only; transport success is not lease readiness. No production changes or claim that the unresolved release scheduler failure is fixed. Parent reviewed the complete candidate and accepted diagnostic patch e416e0c441ed9fb5e2f2f802a8e9d791150157a84be25274e40914eda3adde34.

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

Labels

P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

[Bug]: Cron scheduler never recovers after its worker lease closes ("Shared-state worker lease is closed")

2 participants