Repository navigation
refactor(gateway): share periodic maintenance scheduling - #159111
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 3:09 PM ET / 19:09 UTC. ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherThe 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -8, Tests +32. Total +24 across 5 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
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 tree63caa82a92cf6ecd67d8100e7431b779c461f877on base41324a0f2562c7998abe0152aa9b3be20bf0e4depassed all 12 owner/consumer file runs (248 cases, 154.662s). Every row usedpnpm test <file> --maxWorkers=1; source was verified before/after each command.src/gateway/host-thaw-recovery.test.tssrc/gateway/server-maintenance.test.tssrc/gateway/server-maintenance.telemetry.test.tssrc/gateway/server-maintenance.chat-state.test.tssrc/gateway/server-maintenance.dedupe.test.tssrc/gateway/server-maintenance.delivery-queue.test.tssrc/gateway/server-maintenance.recipients.test.tssrc/gateway/server-startup-early.test.tssrc/gateway/server-startup-post-ready.test.tssrc/gateway/server-kernel.startup.test.tssrc/gateway/server-methods/send.test.tssrc/gateway/server.private-completion.test.tsThe 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 tree4b44ca53e3ce92faec178a9397f4ba09ce1d57d9: 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 enforcedopenclaw/ci-gatesupplies 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.