Skip to content

fix(cron): preserve lazy ownership and bounded notification lifetimes - #117018

Merged
steipete merged 2 commits into
mainfrom
codex/qa300-cron-lazy-owner
Jul 31, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/qa300-cron-lazy-owner

Conversation

@steipete

@steipete steipete commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Five distinct cron/Gateway owner-boundary defects could silently lose an operator/model wake, misreport that loss as CLI success, strand a system-owned heartbeat monitor, or keep detached Gateway work alive indefinitely:

  1. The lazy cron proxy dropped remove(..., { systemOwned: true }), so the real owner rejected legitimate stale heartbeat-monitor cleanup.
  2. Gateway became request-ready before lazy cron startup; a synchronous cold-start wake returned { ok: false } and never delivered the requested event.
  3. openclaw system event printed ok even when its actual wake acknowledgment resolved to { ok: false }.
  4. Failure notification deadlines covered only part of transport: never-settling target resolution or abort-ignoring senders retained Gateway admission indefinitely, and late target resolution could send after the owner had timed out.
  5. A never-settling webhook response-body cancellation kept the guarded dispatcher and its Gateway work root alive indefinitely.

Why This Change Was Made

Each defect is repaired at its canonical lifecycle/decision owner. The lazy proxy transparently forwards removal options and provides Gateway-only optional wake preparation after existing authorization. The CLI consumes the real acknowledgment. Failure notifications reuse the existing timeout helper through OpenClaw's canonical src/infra/fs-safe.ts policy owner around the complete target-resolution and transport lifetime, propagate abort, and share one late-send checkpoint. The immediate-alert sibling drops duplicate timer/race machinery. Webhook body cleanup is bounded by its existing original request deadline before the existing dispatcher release.

Historical caller-scoped cross-agent authorization, scheduled update policy forwarding, persisted session collisions, broad scheduler starvation, and durable delivery-state changes were deliberately held for separate authority/state review. This change adds no config, environment option, dependency, public Gateway protocol, authorization behavior, SQLite schema, or persisted-state shape.

User Impact

Cold-start system/model wake requests are actually delivered to the intended system-event queue. Rejected CLI wake requests report their real reason. Stale system-owned heartbeat monitors can be removed. Hung cron notification targets, transports, and unread webhook bodies stop retaining Gateway work indefinitely; timed-out work cannot send after ownership has ended. Existing wake authorization and public contracts remain unchanged.

Evidence

Real post-fix Gateway runtime transcript

Executed the actual changed source implementation, actual Gateway wake RPC handler, actual lazy cron service, and actual system-event queue against isolated throwaway state. No module mocking, fake clock, external account, credential, or live-user state was involved. The same process then exercised a genuinely non-settling ReadableStream.cancel(), the production fs-safe timeout facade, and the production Gateway independent-root admission owner using a real 40 ms clock:

[proof] branch head: 9d07dff959b4615c024d7cd36ba1b9a99d3c24d5
[proof] Gateway cron owner: real source implementation, isolated ephemeral state
[proof] cold lazy owner before RPC: {"loadedJob":null,"queuedEvents":0,"cronEnabled":true}
[proof] Gateway RPC wake response: {"ok":true,"payload":{"ok":true}}
[proof] real cron owner queued session event: {"sessionKey":"agent:main:main","queuedEvents":["qa-proof: cold-start Gateway wake accepted"]}
[proof] RESULT: cold-start Gateway wake delivered to the real system-event queue
[proof] real-clock stalled webhook-body cleanup: {"cancellationStarted":true,"deadlineMs":40,"elapsedMs":42,"timedOut":true,"admittedRootsDuringCleanup":1,"admittedRootsAfterCleanup":0}
[proof] RESULT: non-settling response cancellation is bounded and Gateway work admission returns to zero

The cleanup probe intentionally uses a controlled non-settling response stream; it does not claim that an external webhook or channel was contacted. Its measured transition from one admitted Gateway root to zero after the real timeout demonstrates the production lifecycle invariant directly.

Exact-head verbose Gateway, CLI, and notification owner proof

Actual focused execution on immutable commit 9d07dff959b4615c024d7cd36ba1b9a99d3c24d5; controlled stalled transports and fake timers are explicitly scoped to the regression tests:

✓ |cron| ../../src/cron/delivery.failure-notify.test.ts > sendFailureNotificationAnnounce > bounds stalled target resolution without starting a late channel send 939ms
✓ |cron| ../../src/cron/delivery.failure-notify.test.ts > sendFailureNotificationAnnounce > bounds a stalled failure notification when its channel 'honors cancellation' 4ms
✓ |cron| ../../src/cron/delivery.failure-notify.test.ts > sendFailureNotificationAnnounce > bounds a stalled failure notification when its channel 'ignores cancellation' 1ms
✓ |cli| ../../src/cli/system-cli.test.ts > system-cli > reports a rejected system event instead of claiming it was enqueued 720ms
✓ |gateway-server| ../../src/gateway/server-cron-notifications.test.ts > dispatchGatewayCronFinishedNotifications > releases Gateway admission when webhook response cancellation never settles 109ms
✓ |gateway-server| ../../src/gateway/server-cron-notifications.test.ts > dispatchGatewayCronFinishedNotifications > releases immediate failure alert admission when a stalled sender 'honors cancellation' 2ms
✓ |gateway-server| ../../src/gateway/server-cron-notifications.test.ts > dispatchGatewayCronFinishedNotifications > releases immediate failure alert admission when a stalled sender 'ignores cancellation' 1ms
✓ |gateway-server| ../../src/gateway/server-cron-lazy.test.ts > createLazyGatewayCronState > prepares a lazy scheduler before an operator wake without starting it 2ms

Test Files  4 passed | 1 skipped (5)
Tests       8 passed | 230 skipped (238)

Separate complete exact-head focused coverage: 240/240 passed across Gateway lazy/notifications/validation, cron failure notification, system CLI, and the fs-safe import-policy boundary. Parent commit c032c9a1 additionally passed the complete remote changed gate: all repository guards, formatting, public SDK baseline, plugin boundaries, dead exports, production and test tsgo, runtime import cycles, webhook/database checks, and changed-file oxlint with zero warnings/errors. The exact corrected head changes only two canonical infrastructure-owner imports from that remotely proven parent.

Refreshed current-main review and hosted CI

  • Re-reviewed the current-main source at 661afc22ac0eafe395625c8cc32469dabc22a5a0: src/gateway/server-cron-lazy.ts still drops system-owned remove options and has no prepareWake; the wake handler has no lazy-owner preparation; src/cron/delivery.ts has no full-owner timeout/late-send checkpoint; src/gateway/server-cron-notifications.ts still awaits unbounded response-body cancellation; src/infra/fs-safe.ts:60 already exposes the canonical existing timeout facade used by this PR.
  • GitHub's live comparison reports exactly the same 11 intended cron/Gateway/CLI paths, with the PR two commits ahead and 76 current-main commits behind; GitHub independently reports the exact head MERGEABLE. Behind-main drift is therefore documented; no rebase is required to invent a different reviewed commit.
  • Exact-head hosted openclaw/ci-gate: SUCCESS — https://github.com/openclaw/openclaw/actions/runs/30665696116/job/91274171962.
  • Exact-head full-branch structured autoreview: Codex gpt-5.6-sol, high reasoning, --max-priority P3, CLEAN, confidence 0.88, verified TruffleHog clean; independent full-owner/caller/sibling cross-review clean.
  • Dependency contract directly inspected: existing @openclaw/[email protected] timing implementation, TypeScript declaration, and timing documentation; no new dependency or private dependency import outside the infrastructure facade.
  • Production delta +98/-64 (net +34); the additional lifecycle ownership replaces duplicate timeout machinery. Baseline 36b80ada3ceae2de21b3d8710b883d778e4c4578; exact reviewed/CI-green head 9d07dff959b4615c024d7cd36ba1b9a99d3c24d5.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime cli CLI command changes size: M maintainer Maintainer-authored PR labels Jul 31, 2026
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 31, 2026
@clawsweeper

clawsweeper Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 31, 2026, 5:18 PM ET / 21:18 UTC.

ClawSweeper review

What this changes

This PR makes Gateway cron wakes load their lazy scheduler before acknowledging a wake, preserves system-owned cleanup options, reports rejected CLI wakes as errors, and bounds cron notification and webhook cleanup lifetimes.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 4 items remain

Keep this PR open for human merge review: the source repair is coherent and has no concrete correctness finding, but the current head still needs directly inspectable after-fix runtime proof and a review refresh against current main. Likely related people: Peter Steinberger, based on the recent cron and fs-safe facade history.

Priority: P1
Reviewed head: 9d07dff959b4615c024d7cd36ba1b9a99d3c24d5

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch has a focused, owner-boundary implementation and regression tests, but mock/CI evidence alone does not satisfy the real-behavior merge gate.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR body reports focused Testbox suites and CI, but contains no directly inspectable after-fix Gateway/CLI runtime transcript, redacted log, terminal output, recording, or artifact. Add redacted real behavior proof; updating the PR body should trigger re-review automatically, or a maintainer can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR body reports focused Testbox suites and CI, but contains no directly inspectable after-fix Gateway/CLI runtime transcript, redacted log, terminal output, recording, or artifact. Add redacted real behavior proof; updating the PR body should trigger re-review automatically, or a maintainer can comment @clawsweeper re-review.
Evidence reviewed 6 items Current main does not yet contain the central repair: Current-main source has no prepareWake contract or lazy-owner preload path, and sendCronAnnouncePayloadStrict still starts delivery immediately after target resolution; the PR adds those owner-boundary safeguards.
Lazy owner repair preserves the requested authority and readiness boundary: The branch forwards removal options unchanged and explicitly loads the lazy cron owner before wake, while the validation test checks that authorization rejection occurs before preload.
Notification deadline repair covers target resolution and cleanup release: The branch wraps the full failure-notification path in the existing timeout facade, checks abort after delayed resolution, and bounds unread webhook-body cancellation before releasing the guarded dispatcher.
Findings None None.
Security None None.

How this fits together

Gateway receives operator and model wake requests, then delegates them to the cron scheduler; cron failures can send channel alerts or webhooks under Gateway work admission. This PR changes the scheduler readiness boundary and the timeout/release behavior of those detached notification paths.

flowchart LR
  Wake[Operator or model wake] --> Gateway[Gateway cron handler]
  Gateway --> LazyOwner[Lazy cron owner]
  LazyOwner --> Scheduler[Cron scheduler]
  Scheduler --> Alerts[Failure notifications]
  Alerts --> Delivery[Channel or webhook delivery]
  Delivery --> Release[Gateway work release]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body reports focused Testbox suites and CI, but contains no directly inspectable after-fix Gateway/CLI runtime transcript, redacted log, terminal output, recording, or artifact. Add redacted real behavior proof; updating the PR body should trigger re-review automatically, or a maintainer can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The branch changes scheduler readiness and detached Gateway work-release timing; a rebase/review refresh is needed because GitHub reports it as behind current main.
  • Resolve merge risk (P1) - The PR body reports focused tests and CI, but it does not provide an inspectable after-fix Gateway/CLI runtime transcript, redacted logs, terminal output, recording, or artifact proving the real lifecycle behavior outside mocks.
  • Complete next step (P2) - No mechanical defect was found, but the protected maintainer label, current-base drift, and missing real behavior proof require a human merge review rather than an automated repair.
Agent review details

Security

None.

PR surface

Source +34, Tests +240. Total +274 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 6 98 64 +34
Tests 5 241 1 +240
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 339 65 +274

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Refresh and prove the exact merge candidate (recommended)
    Rebase or otherwise validate the clean merge result, then attach redacted runtime evidence for cold-start wake delivery and deadline-bounded Gateway work release before merge.
  2. Pause pending owner review
    Keep the PR open without merging if a reviewer cannot confirm the changed timeout semantics and real runtime behavior on the current base.

Technical review

Best possible solution:

Rebase or merge-test the exact head against current main, then add redacted real Gateway or CLI evidence showing a cold wake is accepted and timeout cleanup releases work without late delivery; retain the focused owner-boundary tests as regression coverage.

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

Yes, from source and focused regression coverage: a lazy cron wake can return before the owner is loaded, and unresolved notification or response-body promises retain Gateway admission. This read-only review did not execute a live current-head reproduction.

Is this the best way to solve the issue?

Yes, provisionally: the diff repairs the owner boundaries rather than adding a parallel scheduler or fallback, and it reuses the existing timeout facade. Its merge suitability still depends on exact-head runtime proof and current-base validation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against e73250f54baf.

Labels

Label justifications:

  • P1: The proposed repair addresses operator and model wake loss plus cron notification work that can remain admitted indefinitely.
  • merge-risk: 🚨 availability: Scheduler initialization and timeout cleanup determine whether Gateway-owned cron work is delivered or released under failure conditions.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body reports focused Testbox suites and CI, but contains no directly inspectable after-fix Gateway/CLI runtime transcript, redacted log, terminal output, recording, or artifact. Add redacted real behavior proof; updating the PR body should trigger re-review automatically, or a maintainer can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current main does not yet contain the central repair: Current-main source has no prepareWake contract or lazy-owner preload path, and sendCronAnnouncePayloadStrict still starts delivery immediately after target resolution; the PR adds those owner-boundary safeguards. (src/gateway/server-methods/cron.ts:414, e73250f54baf)
  • Lazy owner repair preserves the requested authority and readiness boundary: The branch forwards removal options unchanged and explicitly loads the lazy cron owner before wake, while the validation test checks that authorization rejection occurs before preload. (src/gateway/server-cron-lazy.ts:262, 9d07dff959b4)
  • Notification deadline repair covers target resolution and cleanup release: The branch wraps the full failure-notification path in the existing timeout facade, checks abort after delayed resolution, and bounds unread webhook-body cancellation before releasing the guarded dispatcher. (src/cron/delivery.ts:161, 9d07dff959b4)
  • Timeout helper is an existing internal facade rather than a new dependency: The checked-out dependency declaration pins @openclaw/fs-safe at 0.5.0 and src/infra/fs-safe.ts re-exports withTimeout from its advanced surface; the branch imports the repository facade. (src/infra/fs-safe.ts:60, f18d619c025c)
  • Feature-history provenance: The current fs-safe facade export and adjacent current cron notification timeout code are attributed to Peter Steinberger; the PR head is a follow-up commit authored by the same person. (src/infra/fs-safe.ts:60, 9d07dff959b4)
  • Release and current-main-only check: The PR head is not an ancestor of the checked-out current main, so this work is neither implemented on main nor eligible for an implemented/release close; the current latest release supplied for review is v2026.7.1. (src/gateway/server-cron-lazy.ts:295, 9d07dff959b4)

Likely related people:

  • Peter Steinberger: Current timeout facade and adjacent cron notification behavior trace to this contributor, who also authored the PR head and its immediate predecessor. (role: recent area contributor; confidence: high; commits: f18d619c025c, c032c9a1e73f, 9d07dff959b4; files: src/infra/fs-safe.ts, src/cron/delivery.ts, src/gateway/server-cron-notifications.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add a redacted after-fix Gateway or CLI runtime transcript proving cold-start wake delivery and bounded notification cleanup.
  • Refresh the merge result against current main and retain the existing focused owner-path tests.

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 (2 earlier review cycles)
  • reviewed 2026-07-31T19:37:42.126Z sha c032c9a :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-31T19:53:40.572Z sha c032c9a :: needs real behavior proof before merge. :: none

@steipete
steipete marked this pull request as ready for review July 31, 2026 19:46
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 31, 2026
@steipete
steipete merged commit 383363e into main Jul 31, 2026
130 of 132 checks passed
@steipete
steipete deleted the codex/qa300-cron-lazy-owner branch July 31, 2026 21:38
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Jul 31, 2026
* origin/main: (22 commits)
  fix(cron): preserve lazy ownership and bounded notification lifetimes (#117018)
  fix: live updater no-op restarts healthy gateways (#117038)
  fix(bedrock): release streaming clients (#117039)
  fix(google): restore canonical Gemini and Vertex provider invariants (#117042)
  fix(channels): preserve accepted LINE and Mattermost delivery (#117024)
  fix(feishu): unify truthful delivery and media ownership (#117023)
  fix(ui): isolate gateway observer lifecycles (#117017)
  fix(tui): keep reset transitions isolated from stale input (#116873)
  fix(gateway): centralize streamed media descriptor ownership (#117000)
  feat(plugins): externalize OpenCode provider (#117035)
  fix(onboarding): restore skill dependency consent (#116644)
  fix(streaming): preserve incomplete bracket tails in final replies (#116983)
  fix: allow slower gateway readiness after updates (#117032)
  fix(plugin-state): avoid shared SQLite corruption when CLI starts during gateway runtime (#113204)
  fix(cli): keep config file output raw under JSON logging (#116968)
  fix(ai): malformed Anthropic stream frames expose raw event payloads (#116938)
  fix(qa): authenticate actual scenario execution evidence (#117004)
  feat(plugins): externalize NovitaAI provider (#117007)
  fix(text): preserve fenced tool markers in visible-text sanitizer (#116939) (#116971)
  fix(channels): reset metadata memos with plugin lifecycle (#117005)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
…openclaw#117018)

* fix(cron): preserve lazy ownership and bound notification lifetimes

* fix(cron): respect fs-safe policy boundary

---------

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

Labels

cli CLI command changes gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant