Skip to content

refactor(gateway): schedule channel health checks - #158537

Merged
steipete merged 1 commit into
mainfrom
hostneutral/scheduler-channel-health-0925
Sep 26, 2026
Merged

steipete merged 1 commit into
mainfrom
hostneutral/scheduler-channel-health-0925

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Channel health checks own a separate timeout/rearm loop even though the Gateway kernel now owns scheduled work.

User Impact

Channel startup grace, health policy, restart ordering, cooldowns, and hourly limits stay unchanged. The existing kernel scheduler runs checks once after a delayed wake and rearms only after work settles. Retirement cancels future checks; shutdown still prevents a delayed provider stop from restarting a channel.

Existing installs need no migration or operator action. Config, state, schemas, ports and public SDK contracts are unchanged. The existing five-second operation handoff timeout remains with the handoff operation.

Why This Change Was Made

Pass the kernel scheduler as a required dependency through both startup layers to the channel health monitor. Delete the monitor's private timer and rearm helper, and use the scheduler's clock and single-flight cadence. The invariant remains one scheduler instance per Gateway process, enforced by types; no production constructor is added.

Owner tests drive the shared manual clock. Five existing channel integration construction sites use the reviewed shared adapter for their existing fake timers. The standalone QA producer constructs and stops its scheduler explicitly around its synthetic ChannelManager; it never starts a Gateway kernel. Its real-time checks remain existing QA coverage.

Production: +25 / -39 / net -14. Tests/support: +203 / -119 / net +84. Docs: +0 / -0 / net 0. Eleven files, 386 changed lines. Existing test helpers remain at their current locations; the optional reviewed relocation is omitted.

Stack

  1. #157517 — diagnostic liveness preparation, merged as 645f8273a86268c84ec7c3542735e68ecde9c215.
  2. #158275 — auth factory naming, merged as 52c7502c8613d02e5fda0c7d36dd7ed5d544ba71.
  3. #158423 — kernel scheduler and companion sweep; merged as 362cee12114d8a41b2b5eff42e96d973b6cfc327.
  4. #158531 — event-loop health sampling; this slice is independent of it.
  5. Channel health checks — this PR.
  6. Remaining small caller migrations, obsolete-path deletion, and final docs — pending.

Evidence

Current head fa7cedf4f2c10e042cb0e9927112b894d42f7b52 includes the main-owned SDK repair #158520; the scheduler range-diff is identical. Exact-head focused proof passed on blacksmith-testbox, lease tbx_01m3dnnvze1jmxvx1wa5ez2yb1, run 36208976081: pnpm install --frozen-lockfile, then each command below as pnpm test <file> --maxWorkers=1. Detached checkout, commit, full tree, and clean source were verified before testing and unchanged afterward. All 7 files / 280 cases passed; summed command wall 73.871s.

File Current-head wall
src/gateway/channel-health-monitor.test.ts 3.360s
src/gateway/channel-health-monitor.clock-rollback.test.ts 2.182s
src/gateway/server-channels.test.ts 35.162s
src/gateway/server-channels.ownership.test.ts 12.155s
src/gateway/server-channels.trust-refusal.test.ts 9.909s
src/gateway/server-runtime-services.test.ts 8.659s
test/e2e/qa-lab/runtime/channel-health-monitor-lifecycle-runtime.test.ts 2.444s

The earlier event-loop CI typecheck failure reproduced on clean main d8f726c5e1dfc2b59fdf33549da92d9c26ea4a45: two undefined SDK helper references (TS2552). Main's #158520 fixes that owner. The exact five-graph type lane then passed on clean main 06da80236ed49ff262c08e0019a4afb6b20d1a34 in 144.172s. No unrelated code was added to these slices. A preceding 18-file focused run also passed, including seven metadata-close fixture consumers on the identical event-loop patch.

The current lease is shared with the next slice's proof and remains active. Historical stopped leases and earlier baseline costs are recorded below.

Codex autoreview passed in one round, scoped-clean through P2 with zero findings. Deslop, full-symbol caller inspection, upstream-preservation review, formatter and whitespace checks passed. The unmodified reviewer helper ran with full Git history/index, all changed files and explicit unchanged context; the full candidate tree and patch matched the source before commit.

blacksmith-testbox, lease tbx_01m3dg6t4fqkfxx8stp6b5d413, run 36203182633: detached baseline 042ab39f55804a51b2d49e913ada422aa1f4e731 and candidate 7bb29cfacd90faa111ca12b9d6042919ec7be95e, with exact commits/trees and clean sources verified before testing and source unchanged afterward. Each worktree ran pnpm install --frozen-lockfile, then pnpm test <file> --maxWorkers=1. All seven files / 280 cases passed on both revisions. Candidate summed command wall: 73.915s. These sequential cold/warm measurements do not establish a performance improvement.

File Cases Baseline wall Candidate wall
src/gateway/channel-health-monitor.test.ts 56 2.844s 3.107s
src/gateway/channel-health-monitor.clock-rollback.test.ts 3 2.060s 2.179s
src/gateway/server-channels.test.ts 172 31.118s 34.785s
src/gateway/server-channels.ownership.test.ts 4 12.768s 12.846s
src/gateway/server-channels.trust-refusal.test.ts 1 10.242s 9.508s
src/gateway/server-runtime-services.test.ts 43 9.095s 9.037s
test/e2e/qa-lab/runtime/channel-health-monitor-lifecycle-runtime.test.ts 1 2.434s 2.453s

No test case, Gateway boot, retry, or sleep was added. Existing integration and QA producer coverage is retained. GitHub enforced openclaw/ci-gate supplies the changed gate; no separate Testbox changed check is claimed. Final live maintenance/cron/suspend/restart/shutdown proof runs on merged main after the stack finishes.

The Testbox lease is stopped; independent provider status confirms completion with no IP.

@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: M labels Sep 26, 2026
@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 25, 2026, 10:08 PM ET / September 26, 2026, 02:08 UTC (Revision 3).

ClawSweeper review

What this changes

The branch moves Gateway channel-health checks from a private timer to the kernel scheduler and updates startup wiring and tests.

Regression provenance

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

Merge readiness

⛔ Blocked before merge - 4 items remain

Keep this PR open. The scheduler consolidation remains useful, but the previously reported shutdown stall is still present on the pinned head and blocks merge.

Priority: P2
Reviewed head: fa7cedf4f2c10e042cb0e9927112b894d42f7b52

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The scheduler migration is focused, but the source-proven Gateway shutdown stall makes this patch unready to merge.
Proof confidence 🌊 off-meta tidepool Not applicable: Real behavior proof is not required for this MEMBER-authored PR. The reported focused tests and synthetic channel-monitor QA path exercise scheduling, but the available evidence does not cover Gateway close with an unresolved provider stop; no stored-data contract changes.
Patch quality 🧂 unranked krab (1/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for this MEMBER-authored PR. The reported focused tests and synthetic channel-monitor QA path exercise scheduling, but the available evidence does not cover Gateway close with an unresolved provider stop; no stored-data contract changes.
Evidence reviewed 8 items Introduced scheduled recovery: The PR registers the full asynchronous health check as a scheduler job, making channel recovery part of the scheduler's pending-work join.
Unbounded scheduler join: Scheduler stop awaits every pending job; cancelling a scheduled registration does not settle an already-running recovery.
Gateway close ordering: Gateway close stops lifetime sidecars before its close prelude. The scheduler is a lifetime sidecar, while the prelude later calls the monitor's bounded wait.
Findings 1 actionable finding [P1] Preserve bounded shutdown for scheduled health checks
Security None None.

How this fits together

The Gateway health monitor reads channel account state and decides when to stop and restart an unhealthy channel. The kernel scheduler supplies its wakeups and joins scheduled work during Gateway shutdown.

flowchart LR
 A[Gateway startup] --> B[Kernel scheduler]
 B --> C[Channel health check]
 D[Channel account state] --> C
 C --> E{Recovery needed?}
 E -- Yes --> F[Stop and restart channel]
 E -- No --> B
 G[Gateway close] --> H[Scheduled work join]
 C --> H
Loading

Before merge

  • Preserve bounded shutdown for scheduled health checks (P1) - The new scheduled callback returns the full recovery promise, which scheduler stop awaits. If a provider's stopChannel never settles, Gateway close joins the scheduler sidecar before reaching the monitor's five-second wait, so close or update restart can remain stuck. Keep that recovery outside the unbounded join and cover Gateway close with an unresolved stop.
  • Resolve merge risk (P1) - A provider stop that does not settle can prevent Gateway shutdown or update restart from completing because scheduler stop joins that recovery before the monitor's five-second handoff.
  • Complete next step (P2) - Keep channel recovery outside the scheduler's unbounded shutdown join and add a Gateway-close regression with a stalled provider stop before merge.
  • Improve patch quality - Repair the scheduler/monitor shutdown boundary and add a Gateway-close regression with a stalled provider stop.

Findings

  • [P1] Preserve bounded shutdown for scheduled health checks — src/gateway/channel-health-monitor.ts:319
Agent review details

Security

None.

PR surface

Source -14, Tests +84. Total +70 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 3 25 39 -14
Tests 8 204 120 +84
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 229 159 +70

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Preserve bounded Gateway close (recommended)
    Keep delayed channel recovery outside the scheduler's unbounded join and add a Gateway-close regression with an unresolved provider stop.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Keep scheduler-owned health-check wakeups, but prevent an unresolved channel stop from entering the scheduler's unbounded shutdown join. Add a Gateway-close regression that holds stopChannel unresolved past the monitor handoff, confirms close proceeds, and confirms a late stop cannot restart the channel.

Technical review

Best possible solution:

Keep scheduler ownership of health-check wakeups while giving in-flight channel recovery a bounded shutdown handoff; prove Gateway close proceeds and a late stop cannot restart the channel.

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

Yes. Source gives a precise path: let a scheduled health check await an unresolved channel stop, then close the Gateway. This review did not execute that path.

Is this the best way to solve the issue?

No. One scheduler is the right wakeup owner, but returning the entire recovery promise to its global join defeats the monitor's existing bounded shutdown.

Full review comments:

  • [P1] Preserve bounded shutdown for scheduled health checks — src/gateway/channel-health-monitor.ts:319
    The new scheduled callback returns the full recovery promise, which scheduler stop awaits. If a provider's stopChannel never settles, Gateway close joins the scheduler sidecar before reaching the monitor's five-second wait, so close or update restart can remain stuck. Keep that recovery outside the unbounded join and cover Gateway close with an unresolved stop.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded internal Gateway refactor with a blocking shutdown defect, not a demonstrated current-user outage.
  • merge-risk: 🚨 availability: The introduced scheduler registration can hold Gateway shutdown or an update restart behind a stalled provider stop.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🌊 off-meta tidepool and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Real behavior proof is not required for this MEMBER-authored PR. The reported focused tests and synthetic channel-monitor QA path exercise scheduling, but the available evidence does not cover Gateway close with an unresolved provider stop; no stored-data contract changes.

Evidence

Acceptance criteria:

  • [P1] pnpm test src/gateway/channel-health-monitor.test.ts --maxWorkers=1.
  • [P1] pnpm test src/gateway/server-close.test.ts --maxWorkers=1.
  • [P1] node scripts/check-changed.mjs --base origin/main.

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 362cee1 adds src/infra/gateway-scheduler.ts:150 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)
  • Ayaan Zaidi: 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-26T01:35:45.061Z sha c0c960ead3a4a0fc7503d7567ffc1c59efa44914 :: blocked before merge. :: [P1] Preserve bounded shutdown for scheduled health checks
  • reviewed 2026-09-26T01:51:04.893Z sha fa7cedf :: blocked before merge. :: [P1] Preserve bounded shutdown for scheduled health checks

@steipete
steipete force-pushed the hostneutral/scheduler-channel-health-0925 branch from c0c960e to fa7cedf Compare September 26, 2026 01:42
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 26, 2026
@steipete
steipete merged commit 8ccd3f5 into main Sep 26, 2026
219 checks passed
@steipete
steipete deleted the hostneutral/scheduler-channel-health-0925 branch September 26, 2026 03:16
@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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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.

1 participant