Skip to content

fix(gateway): recover cloud workers without blocking paired-node startup - #126641

Merged
steipete merged 2 commits into
mainfrom
steipete/worker-startup-provision-recovery
Aug 20, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/worker-startup-provision-recovery

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where operators restarting a Gateway with cloud workers still provisioning could encounter a startup deadlock: startup recovery waited for a worker node connection while startup admission rejected the connection needed to finish recovery. Interrupted or competing recovery could also replay the wrong owner, duplicate a provider lease, or destroy work belonging to a newer placement.

Preserves the authenticated, already-paired node startup reconnect shipped by #126601. Closed issue #125157 is rollout context only; this PR does not close, reopen, or claim to resolve that issue.

Why This Change Was Made

Startup admission now allows both existing authenticated paired-node reconnects and the exact first-time cloud-worker bootstrap handshake, while continuing to reject unrelated operator, browser, unpaired-node, raw-worker, and mixed-credential traffic. Worker recovery is owned by the existing session/placement/environment lifecycle boundaries: replay revalidates the exact session, placement generation, environment, owner epoch, and live authority; provider operations deterministically reuse their exact durable lease; cancellation and shutdown fence/drain recovery without releasing a lease that remains eligible for replay.

The change introduces no SQLite schema-version change, Gateway protocol-version change, or new configuration surface. Production growth is intentional because exact startup admission, closure-bound lifecycle ownership, deterministic lease replay, and non-destructive cancellation are distinct missing capabilities/security invariants, not compatibility shims or downstream guards.

User Impact

Gateway restarts can finish recovering in-flight cloud workers without blocking startup, existing approved nodes keep reconnecting during startup, and interrupted/replayed provisioning resumes the correct lease without duplicating infrastructure or destroying a replacement session. Unauthorized or stale recovery attempts remain closed.

Evidence

Pre-fix sibling regression reproduced against the current-main behavior preserved by #126601:

node scripts/run-vitest.mjs src/gateway/server.node-pairing-rate-limit.test.ts -t 'admits an authenticated paired node while gateway startup is pending'
AssertionError: expected false to be true

The integrated worker/placement/provider regression suite passed 740 tests across 37 files and four Vitest shards:

node scripts/run-vitest.mjs src/gateway/server.node-pairing-rate-limit.test.ts src/gateway/server/ws-connection.startup.test.ts src/gateway/server/ws-connection/message-handler.suspension-admission.test.ts src/gateway/server/ws-connection/message-handler.worker.test.ts src/gateway/server.preauth-hardening.test.ts src/process/gateway-work-admission.test.ts src/gateway/server-worker-placement-startup.test.ts src/gateway/server.sessions.worker-original-order.test.ts src/gateway/worker-environments/provider-provisioning.shutdown-replay.test.ts src/gateway/worker-environments/provider-provisioning.replay.test.ts src/gateway/worker-environments/provider-bootstrap.test.ts src/gateway/worker-environments/placement-dispatch-coordinator.test.ts src/gateway/worker-environments/placement-dispatch-recovery.test.ts src/gateway/worker-environments/placement-dispatch.test.ts src/gateway/worker-environments/service-lifetime.test.ts src/gateway/worker-environments/node-enrollment.test.ts src/gateway/worker-environments/store-node-enrollment.test.ts src/gateway/worker-environments/worker-turn-launcher-failure-recovery.test.ts src/infra/device-bootstrap.test.ts extensions/crabbox/src/crabbox-worker-provider.test.ts

The earlier combined startup proof passed 115 tests. An additional fresh exact-head real-Gateway/startup/bootstrap rerun passed 226 tests across 11 files and two Vitest shards:

node scripts/run-vitest.mjs src/gateway/server.node-pairing-rate-limit.test.ts src/gateway/server/ws-connection.startup.test.ts src/gateway/server/ws-connection/message-handler.suspension-admission.test.ts src/gateway/server/ws-connection/message-handler.worker.test.ts src/gateway/server.preauth-hardening.test.ts src/infra/device-bootstrap.test.ts

Additional complete green verification:

node scripts/check-changed.mjs
node --max-old-space-size=8192 --import tsx scripts/plugin-sdk-surface-report.mts --check
node --import tsx scripts/build-all.mts
git diff --check origin/main...HEAD

Fresh independent autoreview: no actionable findings, overall confidence 0.88. Exact origin/main...HEAD change accounting: production +985/-289 (net +696; 30 files); regression tests +2905/-41 (net +2864; 20 files); test support +23/-4 (net +19; 3 files); combined tests/test support +2928/-45 (net +2883; 23 files).

Authenticated live team-environment recovery is intentionally deferred until after merge because deployment is outside this PR's authorization; no live deployment is claimed or performed.

Resume exact provider operations and leases under closure-bound placement and
session authority. Bound startup admission to the exact cloud setup worker and
preserve enrollment leases across non-destructive shutdown cancellation.
@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime extensions: crabbox size: XL maintainer Maintainer-authored PR labels Aug 20, 2026
@steipete
steipete marked this pull request as ready for review August 20, 2026 10:50
@steipete
steipete requested a review from a team as a code owner August 20, 2026 10:50
@steipete

steipete commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Land-ready proof for head 818cbcbfb92e4a3e541ac9e5a981f2760cdf307f:

  • Exact-head pull-request CI: https://github.com/openclaw/openclaw/actions/runs/32360887594
  • Existing broad worker/startup/provider proof: 740 tests passed across 37 files and four Vitest shards.
  • Existing combined startup proof: 115 tests passed; independent final startup-focused rerun after review fixes: 44 tests passed.
  • Fresh exact-head real-Gateway/startup/bootstrap proof: 226 tests passed across 11 files and two Vitest shards (172 Gateway tests + 54 infrastructure/bootstrap tests).
  • Full changed-file formatting/typecheck/lint/guard gate, plugin SDK surface, full build, and git diff --check: passed.
  • Fresh independent autoreview: no actionable findings, overall confidence 0.88.
  • Exact production LOC: +985/-289 (net +696; 30 files). Regression tests: +2905/-41 (net +2864; 20 files). Test support: +23/-4 (net +19; 3 files). Tests plus support: +2928/-45 (net +2883; 23 files). Production growth implements missing exact startup admission, closure-bound placement/session/environment authority, durable exact-lease replay, and non-destructive recovery cancellation.
  • Preserves merged fix(gateway): prevent enrolled node recovery from blocking startup #126601: authenticated, previously paired nodes still reconnect while startup is pending; first-time enrollment is limited to the exact pending cloud-worker bootstrap. Closed [Feature]: Add system and per-agent GitHub tool identities #125157 is rollout context only.
  • SQLite schema, Gateway protocol version, and configuration surface: unchanged.
  • ClawSweeper review status: the exact-head review has started at fix(gateway): recover cloud workers without blocking paired-node startup #126641 (comment); its comment is still a placeholder and publishes no substantive findings or Rank-up moves:. No actionable move exists to apply or skip, and the queued publisher is not an independent landing gate when exact-head CI and native proof are green.
  • Proof gap: authenticated live team-environment recovery is deferred until after merge; deployment is outside the authorized scope and no live deployment proof is claimed.

Exact broad worker regression command:

node scripts/run-vitest.mjs src/gateway/server.node-pairing-rate-limit.test.ts src/gateway/server/ws-connection.startup.test.ts src/gateway/server/ws-connection/message-handler.suspension-admission.test.ts src/gateway/server/ws-connection/message-handler.worker.test.ts src/gateway/server.preauth-hardening.test.ts src/process/gateway-work-admission.test.ts src/gateway/server-worker-placement-startup.test.ts src/gateway/server.sessions.worker-original-order.test.ts src/gateway/worker-environments/provider-provisioning.shutdown-replay.test.ts src/gateway/worker-environments/provider-provisioning.replay.test.ts src/gateway/worker-environments/provider-bootstrap.test.ts src/gateway/worker-environments/placement-dispatch-coordinator.test.ts src/gateway/worker-environments/placement-dispatch-recovery.test.ts src/gateway/worker-environments/placement-dispatch.test.ts src/gateway/worker-environments/service-lifetime.test.ts src/gateway/worker-environments/node-enrollment.test.ts src/gateway/worker-environments/store-node-enrollment.test.ts src/gateway/worker-environments/worker-turn-launcher-failure-recovery.test.ts src/infra/device-bootstrap.test.ts extensions/crabbox/src/crabbox-worker-provider.test.ts

Exact fresh startup/paired-node/bootstrap proof:

node scripts/run-vitest.mjs src/gateway/server.node-pairing-rate-limit.test.ts src/gateway/server/ws-connection.startup.test.ts src/gateway/server/ws-connection/message-handler.suspension-admission.test.ts src/gateway/server/ws-connection/message-handler.worker.test.ts src/gateway/server.preauth-hardening.test.ts src/infra/device-bootstrap.test.ts

Exact additional checks:

node scripts/check-changed.mjs
node --max-old-space-size=8192 --import tsx scripts/plugin-sdk-surface-report.mts --check
node --import tsx scripts/build-all.mts
git diff --check origin/main...HEAD

@steipete
steipete merged commit 755dad7 into main Aug 20, 2026
292 checks passed
@steipete
steipete deleted the steipete/worker-startup-provision-recovery branch August 20, 2026 11:03
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 21, 2026
…tup (openclaw#126641)

* fix(gateway): recover provisioning workers during startup

Resume exact provider operations and leases under closure-bound placement and
session authority. Bound startup admission to the exact cloud setup worker and
preserve enrollment leases across non-destructive shutdown cancellation.

* fix(gateway): preserve paired node startup recovery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: crabbox gateway Gateway runtime maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant