Skip to content

refactor(gateway): share periodic maintenance scheduling - #159111

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

steipete merged 1 commit into
mainfrom
hostneutral/scheduler-periodic-0926

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway tick, health, worktree cleanup, device setup expiry, dedupe and telemetry maintenance maintain independent timers and duplicate running-work state.

User Impact

Missed maintenance periods coalesce into one pass, callbacks do not overlap, and shutdown joins admitted work. Host-thaw sampling resets both wall and CPU baselines after recovery so slow recovery does not trigger another false thaw or hide a later real one.

Why This Change Was Made

Register periodic maintenance with the required kernel scheduler. Remove four intervals, the periodic AsyncWorkScope, telemetry deadline polling and the device-expiry in-flight flag. Store decisions, newer chat-run retention rules, error reporting and existing startup/shutdown boundaries remain with their owners.

One scheduler instance per Gateway process, enforced by types. No private fallback or standalone scheduler constructor is introduced. Existing state, configuration, spools and ports remain unchanged on update. Main’s first-hour worktree-cleanup delay is preserved; the scheduler provides the same non-overlap guarantee, including when a sweep spans the next cadence. No storage, schema, config, SDK or RPC contract changes are required.

Production +85/−93/net −8; tests +58/−26/net +32; docs +0/−0/net 0. The host-thaw correction itself adds two production lines.

Evidence

Publication head 53ca45a0a64b2a2c5dc7786da8fc413f568d31dc. Fresh Codex P2 composition review is clean. Rebase resolutions preserve newer main’s first-hour worktree policy and held-sweep test, deduplicate scheduler forwarding from cold storage, and retain the approved thaw-baseline correction. Deslop, formatting and caller closure passed.

Blacksmith-testbox lease tbx_01m3f70jxsg7e3036jppdwwv8j, run 36253776173: after frozen install, all four baseline files passed (77 cases, 71.065s). Periodic candidate tree 63caa82a92cf6ecd67d8100e7431b779c461f877 on base 41324a0f2562c7998abe0152aa9b3be20bf0e4de passed all 12 owner/consumer file runs (248 cases, 154.662s). Every row used pnpm test <file> --maxWorkers=1; source was verified before/after each command.

File Cases Command wall
src/gateway/host-thaw-recovery.test.ts 15 1.882s
src/gateway/server-maintenance.test.ts 30 21.396s
src/gateway/server-maintenance.telemetry.test.ts 12 3.536s
src/gateway/server-maintenance.chat-state.test.ts 13 9.717s
src/gateway/server-maintenance.dedupe.test.ts 5 8.174s
src/gateway/server-maintenance.delivery-queue.test.ts 3 8.086s
src/gateway/server-maintenance.recipients.test.ts 1 8.362s
src/gateway/server-startup-early.test.ts 13 9.581s
src/gateway/server-startup-post-ready.test.ts 2 17.689s
src/gateway/server-kernel.startup.test.ts 3 12.781s
src/gateway/server-methods/send.test.ts 130 22.845s
src/gateway/server.private-completion.test.ts 21 30.613s

The existing private-completion suite covers real persistence and completion composition; no new per-test Gateway boots were added. These measurements include wrapper setup and are not a performance comparison.

Both thaw negative controls failed the intended recovery-count assertions: removing both baseline resets (1.937s), then removing only the CPU reset (1.862s). Each was reversed to the exact candidate before the named regression passed (1.911s).

After integrating main’s newer worktree policy, blacksmith-testbox lease tbx_01m3fe5xws0vqv7gvgg8bg9q61, run 36261201574, proved exact refreshed tree 4b44ca53e3ce92faec178a9397f4ba09ce1d57d9: maintenance 30 cases/27.31s, telemetry 12/3.92s, thaw 15/2.47s; all 57 passed (33.70s summed command wall). A preceding SSH failure occurred before checkout creation or test execution; reconciliation confirmed no partial work, and the transport was recovered without changing source or proof. The publication rebase preserves the reviewed patch. GitHub's enforced openclaw/ci-gate supplies changed-file validation; final merged-stack live proof remains pending.

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 is the periodic maintenance slice. Prerequisites task #159038, cold storage #159088, approval #159081, generation #159042, and post-ready #159047 are merged. Outbound recovery #159096 and cron due timers #159099 are also merged.

Remaining reviewed work includes media maintenance, diagnostic/SDK lifetimes, session delivery, update watchers, and cron receipt/system timing. 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.

@clawsweeper

clawsweeper Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 3:09 PM ET / 19:09 UTC.

ClawSweeper review

What this changes

The branch moves Gateway tick, health, cleanup, and telemetry wakeups to the existing kernel scheduler and resets host-thaw sampling baselines after recovery.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main still runs these maintenance tasks on separate timers, so this PR has a distinct purpose. Source review found no concrete introduced defect.

Priority: P3
Reviewed head: 53ca45a0a64b2a2c5dc7786da8fc413f568d31dc

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused cutover with relevant lifecycle coverage and no supported correctness finding; combined live proof remains planned for the stack.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. The reported Testbox runs exercise the production scheduler with injected time and lifecycle fixtures; final combined live Gateway proof is planned after the scheduler stack. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. The reported Testbox runs exercise the production scheduler with injected time and lifecycle fixtures; final combined live Gateway proof is planned after the scheduler stack. No stored-data contract changes.
Evidence reviewed 6 items Introduced scheduling change: The PR registers seven recurring maintenance callbacks and a separately rescheduled telemetry check with the existing Gateway scheduler.
Current main retains separate timers: Current main still uses separate tick, health, worktree, and dedupe intervals; the central cutover has not landed there.
Scheduler settlement contract: The existing scheduler tracks each callback and its descendant work, coalesces missed periods, and waits for pending work when a job stops.
Findings None None.
Security None None.

How this fits together

The Gateway runs periodic checks and cleanup while serving clients and agents. Its kernel scheduler receives maintenance deadlines, runs the owning callbacks, and joins admitted work during shutdown.

flowchart LR
  A[Gateway startup] --> B[Maintenance deadlines]
  B --> C[Kernel scheduler]
  C --> D[Health and tick callbacks]
  C --> E[Cleanup and telemetry callbacks]
  D --> F[Gateway clients]
  E --> G[Maintained runtime state]
  C --> H[Shutdown drain]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -8, Tests +32. Total +24 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 85 93 -8
Tests 3 58 26 +32
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 143 119 +24

Review metrics

Metric Value Why it matters
Scheduled maintenance owners 7 recurring jobs, 1 jittered telemetry job These registrations define the callbacks whose cadence and shutdown settlement the cutover must preserve.

Technical review

Best possible solution:

Keep one kernel-owned scheduler for periodic wakeups while each maintenance owner retains its policy, error handling, and shutdown settlement.

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

Not applicable: this PR refactors existing lifecycle scheduling rather than reporting a reproducible bug. The source and focused tests establish the behavior under review.

Is this the best way to solve the issue?

Yes: the existing kernel scheduler is the appropriate wakeup owner, and the branch retains task-specific decisions in their current owners.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a bounded internal Gateway scheduling refactor with no established current user-facing regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Label justifications:

  • P3: This is a bounded internal Gateway scheduling refactor with no established current user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.

Evidence

What I checked:

  • Introduced scheduling change: The PR registers seven recurring maintenance callbacks and a separately rescheduled telemetry check with the existing Gateway scheduler. (src/gateway/server-maintenance.ts:134, 53ca45a0a64b)
  • Current main retains separate timers: Current main still uses separate tick, health, worktree, and dedupe intervals; the central cutover has not landed there. (src/gateway/server-maintenance.ts:203, 5f00d9608bf6)
  • Scheduler settlement contract: The existing scheduler tracks each callback and its descendant work, coalesces missed periods, and waits for pending work when a job stops. (src/infra/gateway-scheduler.ts:190, 53ca45a0a64b)
  • Shutdown integration: The Gateway close prelude fences the scheduler and joins maintenance before dependent runtime owners close. (src/gateway/server-lifecycle.ts:392, 53ca45a0a64b)
  • Focused validation reported by author: The PR body reports 57 passing focused cases on a refreshed candidate tree and earlier owner and consumer runs. Those are test results on stated candidate trees; the body says final combined live proof remains pending. (53ca45a0a64b)
  • Merged feature history: Repository history identifies the merged kernel-scheduler foundation and recent Gateway maintenance changes as the relevant prior work. (src/infra/gateway-scheduler.ts, 362cee12114d)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@steipete
steipete merged commit 97b0a7c into main Sep 26, 2026
199 checks passed
@steipete
steipete deleted the hostneutral/scheduler-periodic-0926 branch September 26, 2026 19:19
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant