Skip to content

refactor(gateway): schedule update checks through the lifetime owner - #158909

Merged
steipete merged 2 commits into
mainfrom
hostneutral/scheduler-update-lifecycle-0925
Sep 26, 2026
Merged

steipete merged 2 commits into
mainfrom
hostneutral/scheduler-update-lifecycle-0925

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway update checks own sleep loops outside the kernel’s timed-work and shutdown owner.

User Impact

Checks keep their existing cadence and update decisions. Early update RPC work is cancelled and joined with the Gateway, including minimal/canary modes where autonomous checks remain disabled. Existing installs need no migration or operator action; the installed updater still owns staging, activation, and recovery.

Why This Change Was Made

Require the kernel scheduler in the existing update lifecycle and require that lifecycle in the check factory. Named check/catalog jobs replace sleep loops; the deferred owner is registered for shutdown before automatic work can start. Delete implicit lifecycle construction and retain the existing cancellation/drain contract.

One scheduler instance per Gateway process, enforced by types. This slice adds no standalone scheduler. Campaign/watch timers remain assigned to their later slices. No storage/schema, retention, config, RPC, SDK, or port change.

Strict LOC: production +78/−62/net +16; tests +122/−17/net +105; docs +0/−0/net 0. The production metric includes eight test-harness lines; required lifecycle admission and dependency closure explain the growth.

Evidence

Current publication head: 382eca5fb9c05ea17cde994328ce32d6a5be8b59. Current-head focused proof and exact-head CI: after frozen install, pnpm test src/infra/update-startup.test.ts --maxWorkers=1 passed 109 cases in 30.214s on blacksmith-testbox lease tbx_01m3er4ym3e4e69mfkcyc84m7t, run 36239456451. Exact commit/tree and unchanged tracked source were verified. the original update-startup overlap proof was on 00ca227; current head also passed focused type-aware lint (20.475s) and all 117 server-startup-post-attach.test.ts cases (12.839s) on blacksmith-testbox lease tbx_01m3ezy8rsvrbyzc6121b5y475, run 36246724140. Current CI and the enforced gate are green; the exact-head watcher exited successfully. CI on 00ca227 found one no-shadow violation in the new regression; a three-line local binding rename fixed it without changing test behavior. The delta passed Codex P2 review. The remaining prior proof below is reused for the unchanged production patch. GitHub’s enforced openclaw/ci-gate replaces a separate Testbox check-changed run.

Prior proof: Blacksmith-testbox, lease tbx_01m3egmtwwrpzy41g7v4x5807e, run 36232827179. Commands ran after pnpm install --frozen-lockfile in isolated checkouts. Head 05d6381638fb247c3f4ac2c48085a9811b09ce5c, verified tree e507580be304168e8769416cec31c220e947adfd: 431 cases across 16 files passed. The earlier minimal/canary regression also failed with the old dummy owner and passed with explicit lifecycle publication.

The reviewed composition on bde1d5fae5976acd64c04902af82c9a866100f3f changes only the test-helper conflict resolution: retain main’s log/Nix defaults and the required scheduler. Production files are byte-identical to the reviewed slice. The published rebase onto 380a77a86f6a1e877cb3876c6c67d2759455edde has the identical stable patch ID. Deslop and a fresh Codex P2 review passed with zero findings; the six-root caller census found no new production callers.

Recorded commands and per-file test cost

Each test row is pnpm test <target> --maxWorkers=1; command wall includes wrapper/build setup. These are prior-run measurements, not a performance comparison.

Target Cases Wall
src/gateway/server-startup-update-check.test.ts 5 21.275s
src/infra/update-startup.test.ts 116 25.683s
src/infra/update-startup-request-adoption.test.ts 3 15.974s
src/infra/update-global.freebsd.test.ts 13 15.833s
src/gateway/server-methods/update-admission-freshness.test.ts 7 25.794s
src/infra/update-startup.campaign-apply-error.test.ts 3 16.145s
src/gateway/server-methods/update-status-schedule.test.ts 15 16.266s
src/gateway/server-methods/update-run-campaign.test.ts 30 18.690s
src/gateway/server-startup-post-attach.test.ts 117 8.025s
src/gateway/server-methods/update.test.ts, src/gateway/server-methods/update-owner.test.ts, src/gateway/server-methods/update-unexpected-error.test.ts, src/gateway/server-methods/update-freebsd-pkg.test.ts, src/gateway/server-methods/update-handoff-failure.test.ts 104 45.282s
src/gateway/server-startup-update-canary.test.ts 1 27.431s
src/gateway/server.roles-allowlist-update.test.ts 17 28.256s
Scheduler stack

Merged: diagnostic preparation (#157517), auth factory naming (#158275), kernel scheduler and companion sweep (#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 is also merged: #158812. Also merged: PR subscriptions (#158821). Publication order continues with update checks, Gmail renewal, metadata capture maintenance, and audit maintenance; this PR is update checks. Links for these four: Gmail renewal (#158913) is open; metadata and audit follow.

Later reviewed slices: task maintenance, cold storage, approval/secret expiry, publication and post-ready work, diagnostic heartbeat and SDK/CLI lifetime, auth pruning, MCP idle retirement, generation/periodic/media maintenance, outbound recovery, session delivery, update watcher/campaign, and cron due/foreign-receipt/system jobs. Final cleanup removes superseded timer plumbing and records the exception census; merged-main Gateway/cron/SIGSTOP/SIGTERM proof follows 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.

@wjc2821296948 wjc2821296948 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码审查

const controller = new AbortController();
const { signal } = controller;
const pending = new Set<Promise<unknown>>();
const scope = new AsyncWorkScope();

This comment was marked as spam.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 26, 2026, 10:24 AM ET / 14:24 UTC (Revision 2).

ClawSweeper review

What this changes

The branch moves Gateway update and remote catalog checks onto the shared scheduler and registers their lifecycle for shutdown, including modes that suppress automatic checks.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open. In the minimal test Gateway, an authenticated update request can arrive before the new lifecycle exists. The repository-required published-updater to candidate upgrade proof is also outstanding.

Priority: P2
Reviewed head: 382eca5fb9c05ea17cde994328ce32d6a5be8b59

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused validation supports the scheduler cutover, while the narrow startup defect and required upgrade-proof gap limit merge readiness.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The maintainer-authored internal refactor is exempt from the external-contributor proof gate. Reported focused tests cover scheduling and shutdown after lifecycle creation, but the separate repository-required published-driver × candidate update cell remains outstanding; no stored-data contract changes.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored internal refactor is exempt from the external-contributor proof gate. Reported focused tests cover scheduling and shutdown after lifecycle creation, but the separate repository-required published-driver × candidate update cell remains outstanding; no stored-data contract changes.
Evidence reviewed 9 items Introduced missing-owner exception: The branch replaces lazy lifecycle creation with an exception when no lifecycle has been registered.
Startup order: The listener binds and dispatch becomes ready before the post-attach module is loaded; that module creates the update lifecycle after its system CA warmup.
Reachable mode and boundary: The minimal test Gateway starts with sidecars marked ready, allowing a connection during the pre-registration window. Ordinary startup retains its connection gate until sidecars are ready; the finding is limited to the minimal mode.
Findings 1 actionable finding [P2] Register the update lifecycle before minimal-mode RPC admission
Security None None.

How this fits together

Gateway startup creates the owner used by automatic update checks and operator update requests. That owner schedules checks and drains accepted work when the Gateway closes.

flowchart LR
  A[Gateway startup] --> B[Update lifecycle]
  C[Operator update request] --> B
  B --> D[Shared scheduler]
  D --> E[Update and catalog checks]
  E --> F[Update status]
  B --> G[Shutdown drain]
Loading

Before merge

  • Register the update lifecycle before minimal-mode RPC admission (P2) - The minimal test Gateway marks sidecars ready before post-attach startup, so an authenticated update.run request can arrive after the listener binds but before this lifecycle exists. The new exception then fails update admission; the added tests begin only after registration. Preserve an owner for that early request and cover the RPC boundary.
  • Resolve merge risk (P1) - The repository-required published-driver × candidate update proof is not shown; focused candidate tests and green CI do not establish the existing-install upgrade path.
  • Complete next step (P2) - Register the lifecycle before minimal-mode update RPC admission, prove the early authenticated request, and provide published-driver × candidate update proof.

Findings

  • [P2] Register the update lifecycle before minimal-mode RPC admission — src/infra/update-check-lifecycle.ts:94-97
Agent review details

Security

None.

PR surface

Source +8, Tests +113. Total +121 across 14 files.

View PR surface stats
Area Files Added Removed Net
Source 4 69 61 +8
Tests 10 130 17 +113
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 199 78 +121

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Close the startup window (recommended)
    Register the lifecycle before update RPCs are admitted in minimal mode, prove that request path, and supply the required existing-install update cell.

Technical review

Best possible solution:

Register one update lifecycle before minimal-mode RPC admission, keep automatic checks gated on readiness, and verify an existing installation updates into the candidate through the published driver.

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

Yes, from source: connect an authenticated administrator to a minimal test Gateway after its listener binds but before post-attach registers the update lifecycle, then request update.run. This read-only review did not execute that race.

Is this the best way to solve the issue?

No. The shared scheduler is the appropriate owner, but the lifecycle must be registered before its admitted RPC callers can use it.

Full review comments:

  • [P2] Register the update lifecycle before minimal-mode RPC admission — src/infra/update-check-lifecycle.ts:94-97
    The minimal test Gateway marks sidecars ready before post-attach startup, so an authenticated update.run request can arrive after the listener binds but before this lifecycle exists. The new exception then fails update admission; the added tests begin only after registration. Preserve an owner for that early request and cover the RPC boundary.
    Confidence: 0.86

Overall correctness: patch is incorrect
Overall confidence: 0.87

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A bounded startup race can fail an authenticated update request in the minimal test Gateway.
  • merge-risk: 🚨 availability: The new missing-owner exception can make an admitted update RPC fail before post-attach registration.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The maintainer-authored internal refactor is exempt from the external-contributor proof gate. Reported focused tests cover scheduling and shutdown after lifecycle creation, but the separate repository-required published-driver × candidate update cell remains outstanding; no stored-data contract changes.

Evidence

Acceptance criteria:

  • [P1] pnpm test src/gateway/server.startup-websocket-race.test.ts --maxWorkers=1.
  • [P1] pnpm test src/gateway/server-startup-post-attach.test.ts --maxWorkers=1.
  • [P1] pnpm test src/gateway/server-startup-update-check.test.ts --maxWorkers=1.
  • [P1] pnpm test src/infra/update-startup.test.ts --maxWorkers=1.
  • [P1] git diff --check.

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 362cee1 adds src/infra/gateway-scheduler.ts:83 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 362cee12114d; files: src/infra/gateway-scheduler.ts)

Rank-up moves

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

  • Cover an authenticated minimal-mode update RPC before post-attach lifecycle registration and repair that window.
  • Provide the repository-required published-driver × candidate update proof.

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 (1 earlier review cycle)
  • reviewed 2026-09-26T14:05:18.004Z sha 382eca5 :: blocked before merge. :: [P2] Register the update lifecycle before accepting update RPCs

@steipete
steipete merged commit 1b9dac4 into main Sep 26, 2026
215 checks passed
@steipete
steipete deleted the hostneutral/scheduler-update-lifecycle-0925 branch September 26, 2026 14:40
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants