Skip to content

refactor(cron): move due timers into the Gateway scheduler - #159099

Merged
steipete merged 1 commit into
mainfrom
hostneutral/scheduler-cron-due-0926
Sep 26, 2026
Merged

steipete merged 1 commit into
mainfrom
hostneutral/scheduler-cron-due-0926

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Cron owns a private host timer outside the Gateway schedule, so shutdown and next-wake diagnostics must account for another timer owner.

User Impact

Cron continues to own which jobs run, persisted deadlines, catch-up, concurrency, pacing, receipts and run records. Only wake arming moves to the Gateway scheduler. Closing the scheduler also cancels a tick waiting behind suspended admission, while admitted work remains joined.

Why This Change Was Made

Require a scheduler in CronServiceDeps, Gateway cron construction, lazy startup and reload. Move stopTimer to the timer-arming owner and remove direct timeout creation/clearing. The Gateway passes its kernel scheduler throughout; tests use the existing shared injected-clock factory.

One scheduler instance per Gateway process, enforced by types. Standalone Doctor monitor/cadence migration and local agent-job removal explicitly create and stop their short-lived scheduler at the existing operation entry points. No hidden constructor fallback is added.

Existing installs retain their cron store, configuration, spools and ports. Existing startup/store recovery reconstructs due times; no new deadline table, schema, retention, persistence, config, SDK or RPC contract is introduced. Execution watchdogs and operation-local retry timers remain with their existing owners. Foreign-receipt and system-job retry arming are separate followups.

Strict production +121/−72/net +49; tests +1268/−768/net +500; docs +0/−0/net 0. Runtime owners alone are +86/−60/net +26; the requested production glob also counts two existing test-support filenames. The 151-file, 2229-line slice exceeds the preferred size because the required constructor dependency must migrate its entire caller and fixture closure atomically. Its production concern remains one timer owner; optional dependencies or intermediate unused APIs are not introduced.

Evidence

Prepared on main f61e10a7f49798cd7a041ca3509d3a2c5e0b99bc, tree a40024ed3f9144aa401de85071b37539e3378667. Already-merged Gmail scheduler plumbing is deduplicated. Four fixture conflicts retain the exact reviewed shared-clock bindings. Main's admission-helper cleanup, PR-subscription forwarding, scheduler-diagnostics test, backup test pruning and real-heartbeat dispatch/abort prewarm are preserved. Worker-owned task/cron recovery from #158827 remains untouched. The cross-shard constructor census has no new or removed caller paths.

Publication head: b81440e44fce9391ae1325a185d592ea421998de. A later main change added task-notification custody to the cross-tick fixture. The resolution preserves its held-notification/settlement assertions and uses the shared injected scheduler clock, joining both ticks and notification cleanup. Fresh Codex P2 review of the whole composition was clean (one round, three passes). On blacksmith-testbox lease tbx_01m3fe5xws0vqv7gvgg8bg9q61, run 36261201574, pnpm test src/cron/service.cross-tick-admission.test.ts --maxWorkers=1 passed all six cases in 26.38s at exact composition tree b379a3f8d4432b14b21f30a788912ca0852a62d2. Frozen install and before/after source checks passed. The subsequent publication rebase preserves the reviewed patch; exact-head CI attaches on publication.

The original exact due composition passed independent Codex review through P2 as part of both followup compositions. This mechanical refresh adds no new design or substantive runtime adaptation. Formatting, whitespace and source/index checks pass. The proof below belongs to the earlier exact tree; the earlier broad proof is not relabeled as publication-head proof. GitHub's enforced openclaw/ci-gate supplies changed-file validation.

On base d4e7850dd56abcfb66ba8cda511378ff2f98c0da, verified due tree b546a229b2b9dda7e128c89d7cfc4378ba17ecaf passed 135 file runs and 2,059 case executions. Evidence combines 65 unchanged retained file runs with the continuation's remaining 70 due runs; these are recorded executions, not a claim of unique cases or a fresh run on the publication head.

Both providers were blacksmith-testbox. Origin A: lease tbx_01m3ezy8rsvrbyzc6121b5y475, run 36246724140. Origin B: lease tbx_01m3f70jxsg7e3036jppdwwv8j, run 36253776173. Frozen install and exact source/tree checks precede proof; command receipts retain before/after verification. The continuation reused only completed passing receipts with matching source identity. Its private checkout and task processes were cleaned up after completion.

The admission negative control restored an uninterruptible wait and ran pnpm test src/cron/service.armtimer-tight-loop.test.ts --maxWorkers=1 --testNamePattern "joins a scheduled tick waiting for admission without reopening suspension": one intended timeout failure, four skipped, 136.402s command wall. The control was reversed to the exact reviewed tree. The positive file passed all five cases. Final live Gateway/cron/suspend/shutdown proof follows the complete merged stack.

Per-file test costs and commands

Every row used pnpm test <file> --maxWorkers=1. Origin A additionally used --reporter=json --outputFile /tmp/hn-cron-three-slice-results/logs/<receipt-id>.vitest.json; the exact argument arrays and receipt IDs are retained with the proof. Command wall includes wrapper/compiler setup, so these sequential measurements are not a performance comparison. Existing native worker, process, storage and Gateway compositions account for files above 30 seconds; this constructor migration adds no per-test Gateway boots. The timer-owner cases use the shared injected clock.

File Passed case executions Command wall Origin
src/cron/service.armtimer-tight-loop.test.ts 5 23.437s A
src/cron/service.rearm-timer-when-running.test.ts 1 17.559s A
src/cron/service.cross-tick-admission.test.ts 6 17.695s A
src/cron/service.prevents-duplicate-timers.test.ts 5 16.385s A
src/cron/service.every-jobs-fire.test.ts 7 17.201s A
src/cron/service.one-shot-schedule-ownership.test.ts 24 19.469s A
src/cron/service.failure-alert.test.ts 42 18.302s A
src/cron/service.heartbeat-payload.test.ts 10 17.069s A
src/cron/service.session-reaper-in-finally.test.ts 14 26.348s A
src/cron/service.list-past-due.test.ts 3 16.997s A
src/cron/service.timer-maintenance.test.ts 9 18.863s A
src/cron/service.restart-catchup.test.ts 26 18.503s A
src/cron/service/state.test.ts 2 1.672s A
src/cron/service/run-recovery.lifecycle.test.ts 15 18.895s A
src/cron/service/owner-hardening.test.ts 14 34.893s A
src/cron/service/shared-store-runtime.test.ts 5 21.239s A
src/gateway/server-cron.test.ts 128 40.837s A
src/gateway/server-cron-lazy.test.ts 25 18.075s A
src/gateway/server-cron.drain.test.ts 7 25.910s A
src/gateway/server-close.queued-heartbeat.test.ts 1 19.055s A
src/gateway/server-reload-handlers.test.ts 208 28.156s A
src/gateway/server-methods/cron.self-removal.test.ts 8 23.862s A
src/commands/doctor-heartbeat-task-migration.test.ts 14 32.688s A
src/tasks/task-registry.maintenance-cron.test.ts 5 25.022s A
src/agents/mcp-connection-resolver.test.ts 11 29.210s A
src/agents/prepared-model-runtime.hot-reload-dispatch.test.ts 12 20.426s A
src/agents/tools/cron-tool.output-contract.test.ts 20 20.004s A
src/cli/cron-cli/cron-suppression.gateway.test.ts 1 25.753s A
src/commands/backup-schedule.test.ts 14 18.755s A
src/cron/active-jobs-manual-run.test.ts 6 16.550s A
src/cron/cron-delivery-outcomes.e2e.test.ts 6 690.686s A
src/cron/cron-execution-diagnostics.e2e.test.ts 9 741.312s A
src/cron/cron-state-contracts.e2e.test.ts 2 694.690s A
src/cron/legacy-default-agent-owner-migration.test.ts 4 17.289s A
src/cron/service.add-recompute-drops-due-every.test.ts 1 16.480s A
src/cron/service.backup-timing.test.ts 1 16.983s A
src/cron/service.channel-requester.test.ts 21 17.741s A
src/cron/service.declarative-jobs.test.ts 13 19.749s A
src/cron/service.delivery-plan.test.ts 3 18.166s A
src/cron/service.failure-alert-notifications.test.ts 5 17.651s A
src/cron/service.failure-alert-silent-reply.test.ts 1 25.873s A
src/cron/service.get-job.test.ts 3 17.327s A
src/cron/service.grant-generation.test.ts 1 16.984s A
src/cron/service.heartbeat-busy-poll.test.ts 9 31.018s A
src/cron/service.heartbeat-ok-summary-suppressed.test.ts 2 16.340s A
src/cron/service.main-job-passes-heartbeat-target-last.test.ts 2 16.619s A
src/cron/service.manual-delivery.test.ts 3 20.168s A
src/cron/service.payload-conversion.test.ts 2 17.394s A
src/cron/service.persists-delivered-status.test.ts 24 18.457s A
src/cron/service.persists-delivery-suppression.test.ts 2 16.292s A
src/cron/service.read-ops-nonblocking.test.ts 13 17.512s A
src/cron/service.recovery-identity.test.ts 6 19.574s A
src/cron/service.recovery-schedule-ownership.test.ts 16 18.745s A
src/cron/service.removal-postcommit.test.ts 9 17.241s A
src/cron/service.remove-recompute-drops-due-every.test.ts 1 16.332s A
src/cron/service.remove-session-cleanup.test.ts 8 21.036s A
src/cron/service.restart-catchup-pacing.test.ts 9 16.696s A
src/cron/service.restart-catchup-schedule-change.test.ts 3 16.479s A
src/cron/service.restart-catchup-subsecond.test.ts 3 16.812s A
src/cron/service.runs-one-shot-main-job-disables-it.test.ts 27 18.472s A
src/cron/service.scheduled-policy-preservation.test.ts 4 16.335s A
src/cron/service.skips-main-jobs-empty-systemevent-text.test.ts 4 17.235s A
src/cron/service.stale-family.test.ts 6 19.638s A
src/cron/service.startup-heartbeat.test.ts 4 16.424s A
src/cron/service.startup-overflow-clobber.test.ts 5 16.947s A
src/cron/service.store-load-invalid-main-job.test.ts 1 22.001s B
src/cron/service.stream-trigger.test.ts 8 16.531s B
src/cron/service.stream-validation.test.ts 13 16.021s B
src/cron/service.trigger-cadence.test.ts 5 16.085s B
src/cron/service.trigger-eval.test.ts 40 17.324s B
src/cron/service.unresolved-next-run.test.ts 3 16.173s B
src/cron/service.unresolved-owner.test.ts 3 16.036s B
src/cron/service.update-recompute-drops-due-every.test.ts 6 16.016s B
src/cron/service.wake-now-real-heartbeat.test.ts 19 26.400s B
src/cron/service.webhook-empty-summary.test.ts 4 16.113s B
src/cron/service/failure-alerts.account-routing.test.ts 34 15.585s B
src/cron/service/initial-delivery.test.ts 5 16.077s B
src/cron/service/jobs.schedule-error-isolation.test.ts 5 13.879s B
src/cron/service/manual-ack-durability.test.ts 3 18.798s B
src/cron/service/ops.gateway-mutations.test.ts 12 22.257s B
src/cron/service/ops.native-attempt.test.ts 7 23.461s B
src/cron/service/ops.pacing.test.ts 13 15.984s B
src/cron/service/ops.regression.test.ts 20 16.771s B
src/cron/service/ops.test.ts 71 58.679s B
src/cron/service/ops.update.disable-and-list.test.ts 1 19.144s B
src/cron/service/run-receipt-settlement.test.ts 15 20.223s B
src/cron/service/run-recovery.admission.test.ts 1 18.843s B
src/cron/service/run-recovery.batch.test.ts 3 18.680s B
src/cron/service/run-recovery.settlement.test.ts 3 20.112s B
src/cron/service/run-recovery.test.ts 30 19.478s B
src/cron/service/runtime-store.test.ts 4 17.321s B
src/cron/service/startup-run-repair.auto-disable.test.ts 12 15.521s B
src/cron/service/store.schedule-reload.test.ts 9 16.527s B
src/cron/service/store.test.ts 20 16.952s B
src/cron/service/task-runs.test.ts 16 16.223s B
src/cron/service/timer-execution.script-wake.test.ts 3 15.192s B
src/cron/service/timer-execution.tool-policy.test.ts 8 16.000s B
src/cron/service/timer-outcome-finalization.receipts.test.ts 6 16.317s B
src/cron/service/timer-trigger.test.ts 5 15.406s B
src/cron/service/timer.batch-finalization.test.ts 27 30.619s B
src/cron/service/timer.pacing.test.ts 28 16.139s B
src/cron/service/timer.quiet-finalization.test.ts 9 19.986s B
src/cron/service/timer.regression.test.ts 48 23.301s B
src/cron/service/timer.task-ledger.test.ts 4 18.361s B
src/cron/service/timer.test.ts 28 29.592s B
src/cron/service/wake-owner.test.ts 11 15.815s B
src/cron/store.worker.test.ts 21 19.805s B
src/cron/store/run-receipt-retention.test.ts 1 16.682s B
src/cron/store/run-receipt-store.test.ts 37 18.706s B
src/cron/task-run-history.test.ts 33 17.960s B
src/gateway/server-cron-skill-review-jobs.responsiveness.test.ts 2 27.113s B
src/gateway/server-cron-skill-review-jobs.test.ts 10 22.539s B
src/gateway/server-methods/cron.list-scoped.test.ts 6 29.281s B
src/gateway/server-methods/cron.runs.test.ts 9 29.741s B
src/gateway/server-methods/cron.scheduled-policy-adoption.integration.test.ts 4 19.313s B
src/gateway/server-methods/cron.validation.test.ts 256 20.199s B
src/gateway/server-methods/cron.webchat-delivery.test.ts 7 26.665s B
src/gateway/server-methods/requester-cron-authority.integration.test.ts 15 29.037s B
src/gateway/server-plugin-reload.recovery.test.ts 105 29.675s B
src/gateway/server-reload-handlers.hot-reload-status.test.ts 1 25.729s B
src/gateway/server-reload-handlers.operator-model-policy.test.ts 1 22.798s B
src/gateway/server-reload-hot.cron-lazy.test.ts 12 25.228s B
src/gateway/server-reload-managed-context.test.ts 1 21.015s B
src/gateway/server-restart-heartbeat.test.ts 1 17.451s B
src/gateway/server-secrets-reload.model-runtime.test.ts 9 25.904s B
src/gateway/server.cron.test.ts 28 45.869s B
src/gateway/tool-resolution.cron-capture.test.ts 7 20.410s B
src/plugins/services.cron.test.ts 8 24.109s B
test/discord-live-policy.integration.test.ts 1 37.114s B
test/e2e/qa-lab/runtime/gateway-cron-startup-recovery.e2e.test.ts 1 807.693s B
test/gateway.multi.e2e.test.ts 3 47.033s B
test/plugins/dreaming-cron-doctor.integration.test.ts 15 41.063s B
test/plugins/memory-dreaming-cron.test.ts 5 17.273s B
test/plugins/workboard-automation-authority.test.ts 4 26.755s B
ui/src/lib/cron/editor-save.node.test.ts 13 18.008s B
Scheduler stack

Earlier slices: diagnostic preparation #157517, auth factory naming #158275, kernel scheduler #158423, event-loop health #158531, channel health #158537, mention expiry #158614, upstream monitoring #158617, worker placement #158662, idle/prewarm #158666, Incognito expiry #158690, OAuth maintenance #158717, initial lifetime maintenance #158727, worker reconciliation #158812, PR subscriptions #158821, update checks #158909, Gmail renewal #158913, metadata capture maintenance #158959, and audit maintenance #158982.

This PR moves cron due-timer arming. Foreign-receipt monitoring and system-job retry are the next two prepared cron slices, with links added when published. Combined post-ready #159047 precedes this work.

Task maintenance #159038, generation #159042, approval deadlines #159081, and cold storage #159088 are merged. Outbound recovery #159096 is pending. Remaining reviewed work includes periodic/media maintenance, diagnostic/SDK lifetimes, session delivery, update watchers and cron followups. Final timer exceptions and the merged-main Gateway/cron/suspend/shutdown proof follow the last slice.

@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes commands Command implementations agents Agent runtime and tooling size: XL labels Sep 26, 2026
@steipete
steipete enabled auto-merge (squash) September 26, 2026 18:49
@steipete
steipete merged commit b29a243 into main Sep 26, 2026
246 of 250 checks passed
@steipete
steipete deleted the hostneutral/scheduler-cron-due-0926 branch September 26, 2026 18:54
steipete added a commit that referenced this pull request Sep 26, 2026
Complete the test dependency migration after #159099 merged alongside
both history fixtures and the startup recovery service/lazy proxy.

Drive startup recovery with the existing joined scheduler clock instead
of polling detached fake-timer callbacks. Inject an actual schedule-call
failure and prove that work due during suspension runs exactly once after
resume. Production startup recovery and Gateway scheduler behavior remain
unchanged.

Validation: all 25 pnpm tsgo:core:test shards; all cron tests plus
server-cron-lazy and both cron.history suites (263 files, 3400 tests);
changed-file checks, formatting, lint, and independent review. The focused
start-arm run passed all 3 cases in 18.29s wall time (1.6s test time).
Audited all CronService/lazy-cron callers under src, extensions, and test.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
Complete the test dependency migration after openclaw#159099 merged alongside
both history fixtures and the startup recovery service/lazy proxy.

Drive startup recovery with the existing joined scheduler clock instead
of polling detached fake-timer callbacks. Inject an actual schedule-call
failure and prove that work due during suspension runs exactly once after
resume. Production startup recovery and Gateway scheduler behavior remain
unchanged.

Validation: all 25 pnpm tsgo:core:test shards; all cron tests plus
server-cron-lazy and both cron.history suites (263 files, 3400 tests);
changed-file checks, formatting, lint, and independent review. The focused
start-arm run passed all 3 cases in 18.29s wall time (1.6s test time).
Audited all CronService/lazy-cron callers under src, extensions, and test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui cli CLI command changes commands Command implementations gateway Gateway runtime size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant