Skip to content

fix(cron): Gateway exits on resume when a queued cron run hits a storage error - #175678

Merged
obviyus merged 3 commits into
openclaw:mainfrom
yxshee:fix/cron-resume-drain-rejection
Oct 31, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
yxshee:fix/cron-resume-drain-rejection

Conversation

@yxshee

@yxshee yxshee commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Related #172273. The Gateway can exit with Unhandled promise rejection when scheduling resumes while a cron run is queued and queue activation fails with a non-transient storage error. The detached resume drain previously dropped its rejecting promise; the synchronous suspend coordinator cannot catch it.

User Impact

The Gateway now observes that background rejection and logs cron: queue drain delayed, matching the existing same-store wake path. The request stays queued while the Gateway remains available. Awaited callers such as a manual cron.run still receive the storage error. No new retry, persistence format, scheduling policy, or configuration option.

Why This Change Was Made

Attach the existing catch/log contract at the detached caller, without changing drainCronRunQueue or its awaited callers. All contributor commits are preserved. Credit @yxshee and #172273 by @wangmiao0668000666, which identified the same missing observer.

The follow-up documents the warning and removes the added regression/imports to satisfy the explicit zero-net-new-test ceiling. Existing tests and assertions remain unchanged. Simplification keeps the direct observer rather than adding an abstraction. Final merge-base diff: production +3/-1, docs +1/-0, tests +0/-0.

Evidence

Independent built Gateway / shipped CLI before-and-after proof: two main runs exit 1 with the fatal unhandled-rejection log and failed health; two candidate runs log the warning, remain healthy, and retain the unchanged queued receipt plus persisted queued job state. Normal suspend/resume and command execution pass, and manual storage errors are surfaced in both arms.

The proof uses isolated Linux Node 24.22.1 full runtime builds, real command cron jobs and shipped suspend/resume/health RPCs. An external, job-specific SQLite activation trigger produces a real non-transient storage rejection. This is controlled fault injection, not organic corruption or a full-disk claim. No synthetic in-process latch replaces the Gateway proof.

18 existing tests passed across queue and lifecycle suites; targeted formatting passed. Evidence describes initial harness observation mistakes and retains their traces. Remaining CLI process groups are stopped after the shutdown grace.

Merge Danger

Two-way door: a revert restores the previous detached rejection behavior; there is no schema or config migration. Blast radius is background cron queue draining when Gateway scheduling resumes. The change affects error observation only; queued state and errors awaited by callers retain their owners.

resumeScheduling() started the cron run-queue drain without observing it,
so a non-transient storage failure while resuming after a suspension reached
the fatal unhandled-rejection handler and stopped the Gateway. Log it the
way the same-store wake path does; the queued run stays durable for a later
drain.

Co-authored-by: wangmiao0668000666 <[email protected]>
@clawsweeper

clawsweeper Bot commented Oct 17, 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 17, 2026
@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR catches background cron queue-drain failures after scheduling resumes and documents the warning.

Example: A queued command job encounters ERR_SQLITE_ERROR during Gateway resume.

  • Before: The detached rejection reaches the fatal handler and the Gateway exits.
  • After: The Gateway logs cron: queue drain delayed, remains healthy, and retains the queued request.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A minimal, source-supported repair with supplied before-and-after shipped-Gateway proof and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Exact-head proof supplied by obviyus exercises built Gateway suspend/resume and health through the shipped CLI in isolated Linux Node 24.22.1 containers; real SQLite activation fault injection shows baseline exits and candidate survival with unchanged queued state, alongside normal execution and manual-error controls.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: The Gateway can exit when resumed cron queue activation encounters a non-transient storage error.
Reason: Preventing a background failure from terminating the Gateway restores the error-observation behavior already used by the sibling wake path.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

This PR fixes a real Gateway crash path still present on current main; the narrow patch has no actionable findings, and CI remains pending.

Priority: P2
Reviewed head: 77cbbdd5eff1ee6716855f66e348240199a744fd

Before merge

None.

Findings

None.

Agent review details

How this fits together

The cron lifecycle resumes scheduling and starts queue activation; the durable worker owns requests and activation, while awaited manual callers receive errors.

flowchart TD
  A[Gateway resume RPC] --> B[Suspend coordinator]
  B --> C[Cron lifecycle]
  C --> D[Queue drain]
  D --> E[SQLite worker activation]
  E --> F[Job launcher]
  D --> G[Background warning observer]
Loading

Technical review

Best possible solution:

Retain the direct background rejection observer while preserving worker-owned queue state and error propagation to awaited callers.

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

Source confirms the unobserved promise on current main, and the supplied built-Gateway comparison demonstrates the fatal storage-error path; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch repairs the detached caller's missing observer using the existing wake-path contract without swallowing errors in shared queue operations.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 80e0c1f6ff4c.

Provenance checked

  • Detached resume queue draining keeps the original intent (0973bef: Centralize durable queue admission, capacity, activation, and host launch ownership.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +2, Docs +1. Total +3 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 3 1 +2
Tests 0 0 0 0
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 4 1 +3

Root-cause cluster

Relationship: canonical
Canonical: #175678
Summary: This PR carries the same focused repair as the closed predecessor and supplies the previously missing shipped-Gateway evidence.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A non-transient storage failure during resume can terminate the Gateway, but the demonstrated trigger is limited to queued cron activation.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • 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-10-17T16:31:14.793Z sha 675af83 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-31T11:02:17.162Z sha 4fe0cef :: needs maintainer review before merge. :: none

Reviewed October 31, 2026, 7:55 AM ET / 11:55 UTC (Revision 3).

@yxshee

yxshee commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 31, 2026
@obviyus

obviyus commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

Independent built Gateway / shipped CLI proof

Candidate 77cbbdd5eff1ee6716855f66e348240199a744fd preserves the contributor commits and unchanged production fix from 4fe0cef973d73a975a5bec8cbc0b9713bc7739af. Baseline main: 7293e892728aef27996d8a15626e006e2d537dcc.

Both arms were independently installed and built with the canonical full runtime build in secretless Linux Node 24.22.1 containers. Each run used fresh task-owned home/state/config paths, a distinct loopback port, and a real command cron job (true). All run requests, suspend, resume, and health checks used the built openclaw.mjs CLI and shipped Gateway RPC—not an in-process CronService or a synthetic rejected promise.

The external harness installed a job-specific SQLite BEFORE UPDATE OF owner_pid ON cron_run_receipts trigger with RAISE(ABORT, 'proof: injected cron queue activation failure'). The real queue activation operation rejected with ERR_SQLITE_ERROR. This is controlled storage fault injection, not a claim of organic corruption or full-disk reproduction.

                         main #1    main #2    candidate #1    candidate #2
normal suspend/resume    PASS       PASS       PASS            PASS
normal command run       ok         ok         ok              ok
manual run storage error surfaced   surfaced   surfaced        surfaced
resume unhandled reject  YES        YES        NO              NO
Gateway exit             1          1          alive           alive
health RPC               failure    failure    success         success
queue-drain warning      absent     absent     WARN            WARN
queued receipt unchanged n/a*       n/a*       YES             YES

Candidate captures also read the persisted job state: queuedAtMs remains set and runningAtMs is absent. The receipt is byte-for-byte unchanged across the rejected resume drain, with no completion or delivery attempt. The warning is in the actual structured Gateway log:

{"err":"Error: proof: injected cron queue activation failure"}
cron: queue drain delayed

Baseline logs after the successful resume RPC:

[openclaw] Unhandled promise rejection: Error: proof: injected cron queue activation failure
[admission] closed: stop (process exit: unhandled rejection)
[gateway] received unhandled rejection; shutting down

*The baseline's fatal shutdown subsequently marks the pending manual request skipped with cron service stopped. The first baseline harness reached and verified exit 1 and failed health, then failed an overly broad queue-unchanged assertion; that assertion was corrected to apply only to the surviving candidate. Its crash trace is retained and counted, not rerun to confirm. A first candidate capture looked for the warning only in console output and timed out despite the warning being present in the structured log; the final two candidate captures explicitly read that log.

18 existing tests passed across service.run-queue.test.ts and ops-lifecycle.start-arm.test.ts; changed source/test/docs formatting passed. The added contributor regression/imports were removed to meet the explicit zero-net-new-test ceiling; existing tests and assertions are unchanged. Final diff: production +3/-1, docs +1/-0, tests +0/-0. Simplification keeps the same existing wake-path catch/log contract, with no retry, queue-state change, new helper, or swallowed awaited error.

Credit: @yxshee; predecessor #172273 by @wangmiao0668000666 identified the same missing observer. No system clock was changed. All application logs and shutdown traces are retained; the harness kills any remaining CLI process group after its shutdown grace.

@obviyus

obviyus commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: XS and removed size: S labels Oct 31, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 31, 2026
@clawsweeper clawsweeper Bot removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 31, 2026
@obviyus

obviyus commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

Exact-head CI classification — paused on unrelated red

Head 77cbbdd5eff1ee6716855f66e348240199a744fd has 5/6 exact-head review with no findings, and the built Gateway proof is complete. after-push.sh completed.

Current ci-gate is FAILURE:

  • check-lint-core-5 fails with typescript(no-floating-promises) at src/gateway/server-methods/agent.visitor-access.test-utils.ts:350:11, :444:9, and :700:9.
  • Aggregate ci-gate fails because that selected lint stripe failed; it is not another product defect.

Independent local receipt: I fetched the actual hosted merge tree 83edd4272760fb00653c858e3a2e538f00fd36bd (head above merged into main 447e14d02460342af4fe2c98dbd5475b15b938d2) into secretless Docker. The exact failing file, same repo lint runner, core tsconfig, and hosted environment (CI=1 OPENCLAW_LOCAL_CHECK=0) fail with the same three diagnostics both with the PR and with only src/cron/service/ops-lifecycle.ts replaced by its actual main-parent version:

head:         exit 1; no-floating-promises at 350:11, 444:9, 700:9
owner revert: exit 1; no-floating-promises at 350:11, 444:9, 700:9

The outputs are identical. This PR adds a catch to the cron resume caller and one documentation bullet; it does not modify the visitor-access test helper, its promises, or its types. An earlier direct-head-only lint probe passed because hosted CI tests the newer merge tree; that passing probe is not used as failure-independence evidence.

Cancelled count: 2, both auto-response jobs (124529653503 and 124529660083); no diff-covering test jobs were cancelled. No hosted rerun or further push was made. Retaining the worktree, container/build volume, harness, exact merge-tree comparison and logs for maintainer resumption; not claiming landing-ready while CI is red.

@obviyus

obviyus commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

Maintainer override: the only red, check-lint-core-5, is three no-floating-promises errors at lines 350, 444 and 700 of agent.visitor-access.test-utils.ts, a file this PR does not touch. The hosted merge tree and the same tree with this PR's cron change reverted produce identical errors locally, so they come from main, not from this change. Receipt: #175678 (comment).

@obviyus
obviyus merged commit 159d00b into openclaw:main Oct 31, 2026
123 of 128 checks passed
@obviyus

obviyus commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

Landed in 159d00b. Thanks @yxshee. A rejected cron resume drain no longer crashes the Gateway.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 1, 2026
…age error (openclaw#175678)

fix(cron): don't crash the Gateway when a detached resume drain is rejected

After a cron resume, the drain of queued jobs ran detached. If it rejected, for example on a storage error, nothing observed the rejection, and the Gateway exited with a fatal unhandled rejection. The detached drain now goes through the existing wake-path catch and log, so the Gateway stays up and the queued job state is kept. Errors that callers await directly, such as manual storage errors, are still surfaced.

Evidence: built Gateway with real command cron jobs and the shipped suspend and resume RPCs. On main, a rejected resume drain caused a fatal unhandled rejection and the Gateway exited (twice). With this change it logged the existing warning, stayed healthy and kept the queued receipt and job state (twice). Normal resume and execution worked on both refs. Details: openclaw#175678 (comment).

Thanks @yxshee.

Co-authored-by: wangmiao0668000666 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Nov 17, 2026
Backport #175678 from 159d00b.
Retain queued receipts and direct caller failures; observe only the detached
resume drain. Add a real storage-fault regression covering retry.

Co-authored-by: wangmiao0668000666 <[email protected]>
Co-authored-by: Ayaan Zaidi <[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

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS 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