Skip to content

refactor(gateway): schedule generation startup sidecars - #159042

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

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

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Delayed startup hooks and restart-sentinel recovery arm private timers outside the Gateway scheduler.

User Impact

The existing 250ms hook and 750ms sentinel delays remain. Generation retirement cancels waiting work and joins admitted callbacks, while restart recovery keeps its captured state root and legacy-update import custody.

Why This Change Was Made

Require the kernel scheduler in the generation timer owner and forward it through both consumers. Remove the private timeout, unref and clearTimeout bookkeeping. Move the two sentinel scheduling cases out of the broad startup suite and drive their owner with the shared injected clock, including cancellation while admission is suspended.

One scheduler instance per Gateway process, enforced by types. This slice creates no standalone scheduler. Updating preserves state, configuration, ports and existing sentinel rows; there is no storage, config or SDK contract change. Admission-only setImmediate sidecars, bounded ACP readiness polling and pending-update retry backoff retain their existing owners.

Production +33/−24/net +9; tests +95/−41/net +54; docs +0/−0/net 0. The small production increase makes scheduler and admission cancellation ownership explicit.

Evidence

Reviewed refresh at be46e6966c2b52c6cde06abf965c44f9a175a47f, mechanically applied to fresh main for publication. The touched owners have no intervening changes. Gmail already supplied the required outer scheduler dependency and caller plumbing, so those duplicate hunks are omitted. Newer update-check behavior and its minimal/canary tests are preserved. The three fixture conflicts resolve to the exact previously reviewed and tested state-context file; the timer and sentinel owners also retain their reviewed bytes. Deslop, formatting, whitespace and cross-shard caller checks pass. The original slice passed independent Codex review through P2; this refresh adds no new behavior.

Historical focused proof: blacksmith-testbox lease tbx_01m3er4ym3e4e69mfkcyc84m7t, run 36239456451, pinned base 3ed87e53daf5cdd5a69efbc471519ddf427b73de, candidate tree 30eaa1f29b558ac9c560b62c718f542eec05c357. After pnpm install --frozen-lockfile, all three completed candidate files passed: 141 cases in 56.688s command wall. The later post-ready baseline in that multi-slice run was interrupted; the completed generation results were retained.

Each row ran as pnpm test <file> --maxWorkers=1:

File Candidate cases Command wall
src/gateway/server-startup-restart-sentinel.test.ts 3 19.612s
src/gateway/server-startup-post-attach.test.ts 113 7.388s
src/gateway/server-restart-sentinel.state-context.test.ts 25 29.688s

The two existing baseline files passed 115 cases in 12.123s and 25 cases in 48.032s respectively. These sequential measurements include wrapper/build setup and do not establish a performance improvement. No separate Testbox run was performed for this mechanical refresh; these counts and costs belong to the historical candidate. The enforced openclaw/ci-gate validates the published head instead of a separate Testbox check-changed invocation. The final live proof remains with the complete merged stack.

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 migrates generation startup sidecars. The next prepared slice combines post-ready release and maintenance scheduling; its link will be added when published.

Task maintenance is #159038. Remaining reviewed work includes cold-storage maintenance, approval deadlines, periodic/media maintenance, diagnostic/SDK lifetimes, outbound/session delivery, update watchers and cron 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Sep 26, 2026
@steipete
steipete enabled auto-merge (squash) September 26, 2026 16:51
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 12:56 PM ET / 16:56 UTC.

ClawSweeper review

What this changes

The branch schedules delayed Gateway startup hooks and post-restart recovery through the server's shared scheduler, with clock-driven lifecycle tests.

Merge readiness

✅ Ready for maintainer review

Keep open: the pinned main still lacks this startup-sidecar cutover. The earlier scheduler foundation and the open task-maintenance slice address different work, and the reviewed patch has no concrete blocking defect.

Priority: P3
Reviewed head: ef9f369e6a783e48811d2d56ce23f9479e8e5ded

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The cutover is focused, retains lifecycle ownership, and has relevant historical test coverage with no identified blocking defect.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The supplied Repository State identifies this as a member-authored PR, so contributor real-setup proof is not required. Historical focused tests exercise the startup and sentinel owners; the PR does not claim a post-refresh live Gateway run, and it changes no stored-data contract.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied Repository State identifies this as a member-authored PR, so contributor real-setup proof is not required. Historical focused tests exercise the startup and sentinel owners; the PR does not claim a post-refresh live Gateway run, and it changes no stored-data contract.
Evidence reviewed 8 items Pinned introduced change: The PR replaces the generation helper's private timeout with a named registration on the supplied scheduler and makes stopping await that job.
Current main still uses private timers: The pinned main version of the generation helper arms a direct setTimeout; this PR's precise change remains useful.
Scheduler lifecycle: The existing scheduler replaces registrations by ID, cancels future wakes on close, and tracks running jobs until they settle.
Findings None None.
Security None None.

How this fits together

The Gateway starts hooks and recovery work after its server attaches. Its scheduler wakes delayed work, while admission and sidecar handles control execution and shutdown.

flowchart LR
  A[Gateway startup] --> B[Delayed sidecar registration]
  B --> C[Shared scheduler]
  C --> D{Active and admitted?}
  D -->|Yes| E[Startup hook or restart recovery]
  D -->|No| F[Cancelled wake]
  E --> G[Hook effect or restart notice]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +9, Tests +54. Total +63 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 33 24 +9
Tests 3 95 41 +54
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 128 65 +63

Review metrics

None.

Technical review

Best possible solution:

Keep one scheduler responsible for these wakeups while restart recovery retains its captured state context and shutdown joins admitted work.

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

Not applicable: this is an internal scheduling refactor. Current-main source confirms the private timers it intends to replace.

Is this the best way to solve the issue?

Yes: passing the existing kernel scheduler to both consumers uses the established wake owner and preserves the restart-sentinel context.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a contained internal Gateway lifecycle refactor with no identified user-facing contract change or regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied Repository State identifies this as a member-authored PR, so contributor real-setup proof is not required. Historical focused tests exercise the startup and sentinel owners; the PR does not claim a post-refresh live Gateway run, and it changes no stored-data contract.

Label justifications:

  • P3: This is a contained internal Gateway lifecycle refactor with no identified user-facing contract change or regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied Repository State identifies this as a member-authored PR, so contributor real-setup proof is not required. Historical focused tests exercise the startup and sentinel owners; the PR does not claim a post-refresh live Gateway run, and it changes no stored-data contract.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 7974d9c adds src/gateway/server-startup-sidecar-scheduler.ts:61 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7974d9cf48d7; files: src/gateway/server-startup-sidecar-scheduler.ts)

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 dd3e8a4 into main Sep 26, 2026
201 checks passed
@steipete
steipete deleted the hostneutral/scheduler-generation-0926 branch September 26, 2026 17:07
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 P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant