Skip to content

Commit 78502ed

Browse files
authored
feat(workers): run device sessions from Gateway bundles (#124037)
* feat(workers): run device sessions from Gateway bundles Install the current Gateway bundle before a device environment becomes ready, verify it at attach and tunnel boundaries, launch only from the immutable namespaced bundle directory, and retire stale environments for idempotent reprovisioning. Remove the local execution mode and preserve the node-local build claim only as temporary inventory metadata for the final projection/cleanup slice. * docs(runners): record Gateway bundle cutover * test(ci): repair runner validation fixtures # Conflicts: # src/scripts/test-projects.test.ts * fix(workers): surface outdated node recovery Keep legacy runner inventory diagnostic-only while exposing the update-and-reconnect action through node, environment, provider, placement, and Control UI surfaces. * fix(workers): reject legacy inventory with recovery * fix(workers): bundle worker deploy closure * test(workers): close bundle cutover gates * fix(workers): compose browser runtime at build * fix(workers): satisfy bundle cutover gates * fix(workers): route temp runtime through infra * docs(workers): align bundle host guidance * fix(ui): fence outdated session destinations
1 parent eb13f57 commit 78502ed

105 files changed

Lines changed: 1948 additions & 1531 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,7 @@ public struct EnvironmentSummary: Codable, Sendable {
19451945
public let trust: String?
19461946
public let capabilities: [String]?
19471947
public let desktop: Bool?
1948+
public let issues: [[String: AnyCodable]]?
19481949
public let worker: WorkerEnvironmentMetadata?
19491950

19501951
public init(
@@ -1961,6 +1962,7 @@ public struct EnvironmentSummary: Codable, Sendable {
19611962
trust: String? = nil,
19621963
capabilities: [String]? = nil,
19631964
desktop: Bool? = nil,
1965+
issues: [[String: AnyCodable]]? = nil,
19641966
worker: WorkerEnvironmentMetadata? = nil)
19651967
{
19661968
self.id = id
@@ -1976,6 +1978,7 @@ public struct EnvironmentSummary: Codable, Sendable {
19761978
self.trust = trust
19771979
self.capabilities = capabilities
19781980
self.desktop = desktop
1981+
self.issues = issues
19791982
self.worker = worker
19801983
}
19811984

@@ -1993,6 +1996,7 @@ public struct EnvironmentSummary: Codable, Sendable {
19931996
case trust
19941997
case capabilities
19951998
case desktop
1999+
case issues
19962000
case worker
19972001
}
19982002
}
@@ -2029,6 +2033,7 @@ public struct EnvironmentsCreateResult: Codable, Sendable {
20292033
public let trust: String?
20302034
public let capabilities: [String]?
20312035
public let desktop: Bool?
2036+
public let issues: [[String: AnyCodable]]?
20322037
public let worker: WorkerEnvironmentMetadata?
20332038

20342039
public init(
@@ -2045,6 +2050,7 @@ public struct EnvironmentsCreateResult: Codable, Sendable {
20452050
trust: String? = nil,
20462051
capabilities: [String]? = nil,
20472052
desktop: Bool? = nil,
2053+
issues: [[String: AnyCodable]]? = nil,
20482054
worker: WorkerEnvironmentMetadata? = nil)
20492055
{
20502056
self.id = id
@@ -2060,6 +2066,7 @@ public struct EnvironmentsCreateResult: Codable, Sendable {
20602066
self.trust = trust
20612067
self.capabilities = capabilities
20622068
self.desktop = desktop
2069+
self.issues = issues
20632070
self.worker = worker
20642071
}
20652072

@@ -2077,6 +2084,7 @@ public struct EnvironmentsCreateResult: Codable, Sendable {
20772084
case trust
20782085
case capabilities
20792086
case desktop
2087+
case issues
20802088
case worker
20812089
}
20822090
}
@@ -2113,6 +2121,7 @@ public struct EnvironmentsDestroyResult: Codable, Sendable {
21132121
public let trust: String?
21142122
public let capabilities: [String]?
21152123
public let desktop: Bool?
2124+
public let issues: [[String: AnyCodable]]?
21162125
public let worker: WorkerEnvironmentMetadata?
21172126

21182127
public init(
@@ -2129,6 +2138,7 @@ public struct EnvironmentsDestroyResult: Codable, Sendable {
21292138
trust: String? = nil,
21302139
capabilities: [String]? = nil,
21312140
desktop: Bool? = nil,
2141+
issues: [[String: AnyCodable]]? = nil,
21322142
worker: WorkerEnvironmentMetadata? = nil)
21332143
{
21342144
self.id = id
@@ -2144,6 +2154,7 @@ public struct EnvironmentsDestroyResult: Codable, Sendable {
21442154
self.trust = trust
21452155
self.capabilities = capabilities
21462156
self.desktop = desktop
2157+
self.issues = issues
21472158
self.worker = worker
21482159
}
21492160

@@ -2161,6 +2172,7 @@ public struct EnvironmentsDestroyResult: Codable, Sendable {
21612172
case trust
21622173
case capabilities
21632174
case desktop
2175+
case issues
21642176
case worker
21652177
}
21662178
}
@@ -2213,6 +2225,7 @@ public struct EnvironmentsStatusResult: Codable, Sendable {
22132225
public let trust: String?
22142226
public let capabilities: [String]?
22152227
public let desktop: Bool?
2228+
public let issues: [[String: AnyCodable]]?
22162229
public let worker: WorkerEnvironmentMetadata?
22172230

22182231
public init(
@@ -2229,6 +2242,7 @@ public struct EnvironmentsStatusResult: Codable, Sendable {
22292242
trust: String? = nil,
22302243
capabilities: [String]? = nil,
22312244
desktop: Bool? = nil,
2245+
issues: [[String: AnyCodable]]? = nil,
22322246
worker: WorkerEnvironmentMetadata? = nil)
22332247
{
22342248
self.id = id
@@ -2244,6 +2258,7 @@ public struct EnvironmentsStatusResult: Codable, Sendable {
22442258
self.trust = trust
22452259
self.capabilities = capabilities
22462260
self.desktop = desktop
2261+
self.issues = issues
22472262
self.worker = worker
22482263
}
22492264

@@ -2261,6 +2276,7 @@ public struct EnvironmentsStatusResult: Codable, Sendable {
22612276
case trust
22622277
case capabilities
22632278
case desktop
2279+
case issues
22642280
case worker
22652281
}
22662282
}

‎config/env-var-count-budget.txt‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Distinct OPENCLAW_* names in production source under src, packages, and extensions.
22
# Ratchet: lower this number when cleanup removes names; never raise it without owner approval.
3-
# One-time owner-approved increase: 502 -> 503.
4-
# One atomic private CUA driver endpoint replaces two uncounted split facts.
5-
503
3+
# Worker bundle installation no longer injects OPENCLAW_STATE_DIR into a remote npm process.
4+
502

‎docs/gateway/cloud-workers.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Profile fields:
107107
| Key | Meaning |
108108
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
109109
| `provider` | Worker provider id registered by a plugin (`crabbox` for the bundled plugin). |
110-
| `install` | `bundle` (default) ships the running Gateway's build; `npm` installs the exact released Gateway version with pinned integrity. `npm` requires the Gateway to run from a packaged release. |
110+
| `install` | `bundle` (default) ships the running Gateway's worker executable; `npm` derives the same executable from the exact released Gateway package with pinned integrity. `npm` requires the Gateway to run from a packaged release. |
111111
| `settings` | Provider-owned JSON. For crabbox: `provider` (backend), `class` (machine class), `ttl`, `idleTimeout` (Go durations), optional `setup`, optional `desktop` (boolean), and absolute `binary` path. OpenClaw forces public SSH and disables managed Tailscale for these leases. |
112112

113113
Crabbox inspect reports a primary SSH port and may advertise ordered fallback ports. OpenClaw persists that order across Gateway restarts. Its shared pinned SSH transport rotates candidates only for replay-safe operations: idempotent probes, content-addressed transfers, receipt/lock-guarded artifact installation, convergent managed-worktree mirroring, and tunnel reconnects. Ambiguous unguarded stateful commands fail closed on their current candidate and are not replayed on another port. OpenClaw never invents an unadvertised port. If your network policy pins SSH ingress, allow at least one advertised Crabbox candidate.
@@ -120,8 +120,8 @@ OpenClaw derives one canonical `cbx_...` lease ID from the durable provision ope
120120

121121
### Install channels
122122

123-
- **`bundle`** packs the running Gateway's `dist`, a pruned `package.json`, and any workspace packages the build references, all covered by a content hash. The box verifies the pristine bundle against that hash, then installs production npm dependencies (scripts disabled). This is how you run a dev build on a worker.
124-
- **`npm`** proves the release exists on the public registry, pins its SHA-512 integrity, and installs `openclaw@<version>` matching the Gateway exactly.
123+
- **`bundle`** ships one dedicated worker executable whose complete JavaScript dependency closure is bundled and content-hashed by the Gateway. It does not ship the normal OpenClaw package manifest or a dependency-install recipe. The box verifies and publishes those exact bytes without installing packages or running lifecycle scripts. This is how you run a dev build on a worker.
124+
- **`npm`** proves the release exists on the public registry, pins its SHA-512 integrity, and extracts the same dedicated worker executable from `openclaw@<version>` without materializing the package's dependency tree.
125125

126126
### Verify the profile
127127

‎docs/nodes/index.md‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,7 @@ node does not advertise this command yet, so its rows remain view-only.
420420

421421
### Host OpenClaw sessions
422422

423-
A headless node host can separately opt into full OpenClaw session hosting from
424-
its local installation:
423+
A headless node host can separately opt into full OpenClaw session hosting:
425424

426425
```json5
427426
{
@@ -431,13 +430,20 @@ its local installation:
431430
}
432431
```
433432

434-
Restart the node host after enabling this setting. At startup it freezes the
435-
exact OpenClaw version, worker-bundle hash, and worker protocol features of its
436-
own installation in the connection handshake, then repeats that build in its
437-
live runner inventory. The Gateway reports prepared session-host eligibility
438-
only while those declarations match, and provisioning requires the node and
439-
Gateway versions to match exactly. If they differ, update the node before
440-
retrying.
433+
Restart the node host after enabling this setting. On the first session dispatch
434+
for a Gateway build, the node downloads one sealed worker artifact from that
435+
paired Gateway, verifies its exact content hash, and publishes it atomically
436+
under the Gateway-namespaced node-host bundle root. The artifact already
437+
contains its complete JavaScript dependency closure; the node does not install
438+
packages or execute lifecycle scripts. Later turns reuse the immutable artifact
439+
while its receipt still matches the Gateway's current build.
440+
441+
Node hosts must support the current private worker-supervisor dialect before
442+
they can host sessions. An older connected host remains visible but disabled in
443+
the session picker. Update OpenClaw on that device and reconnect it; for a
444+
headless node, run `openclaw update` followed by `openclaw node restart`. The
445+
Gateway does not fall back to the node's local OpenClaw package or an older
446+
supervisor dialect.
441447

442448
This setting enables supervised session turns on the paired device, including
443449
Gateway-owned workspace transfer and result reconciliation. Each node runs at

‎docs/plan/runners.md‎

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ advances a milestone.
2525
| F | Real-wire session boundary harness | landed | #121212 |
2626
| 5 | Public worker ingress path | landed | #122578, #122643 |
2727
| 6 | Node worker provider (device runners) | in progress | #122683, #122769, #122829, #122939, #123013, #123033, #122966, #123157, #123280, #123612, #123641, #123665, #123673, #123700, #123696, #123785, #123859, #123889, #123901 |
28-
| 7 | Bundle push consent + runner updates | in progress | #123985 |
28+
| 7 | Bundle push consent + runner updates | in progress | #123985, #124037 |
2929
| 8 | Stop-and-continue moves | not started | — |
3030
| 9 | Deletions (ssh sandbox, openshell, exec-host clones, …) | not started | — |
3131
| 10 | Cloud convergence (provisioners run `openclaw connect`) | not started | — |
@@ -230,26 +230,25 @@ box (the machine is the boundary).
230230
Milestone 6 now has the public worker ingress, transport-neutral launch
231231
descriptor, durable node-host supervisor, private launch/status/cancel dialect,
232232
bounded terminal receipts, and the Gateway launch replay/poll/cancel adapter.
233-
A node freezes its optional local worker build in the connection handshake and
234-
repeats it in one atomic, reconnect-scoped private runner inventory with the
235-
supervisor dialect. The Gateway requires those semantic build identities to
236-
match. Public node and environment projections expose only `sessionHost`; a
237-
read-scoped topology invalidation makes clients refetch without exposing the
238-
build. Provider eligibility and new launch selection require the exact handshake,
239-
while status and cancellation reacquire only the current supervisor proof and use
240-
the durable launch identity so an upgrade cannot strand an existing worker.
241-
Node-local opt-in advertises the current installation; default nodes remain
242-
non-hosts. The supervisor now owns two atomic durable capacity slots, bounded
233+
A node publishes one atomic, reconnect-scoped private runner inventory with the
234+
supervisor dialect and current capacity. The temporary local build claim remains
235+
inventory metadata only; milestone 7 makes the durable Gateway bundle receipt
236+
the sole execution authority. Public node and environment projections expose
237+
only `sessionHost`; a read-scoped topology invalidation makes clients refetch
238+
without exposing build identity. Status and cancellation reacquire the current
239+
supervisor proof and use the durable launch identity so an upgrade cannot strand
240+
an existing worker. Node-local opt-in advertises capacity; default nodes remain
241+
non-hosts. The supervisor owns two atomic durable capacity slots, bounded
243242
10-second admission, restart reconciliation, and full/free inventory edges.
244243
Device dormancy expiry and terminal launch/environment retention bound durable
245244
rows. Node workspace cleanup waits for a full reconnect-scoped Gateway retain
246245
snapshot, unions that authority with node-local launch and operation ownership,
247246
and then removes retired generations, transfer siblings, unreachable manifests,
248247
and empty workspace parents in bounded passes. The Gateway bundle producer
249248
also prunes unreferenced local tarballs only after a successful current build,
250-
while preserving hashes named by durable environments and placements. Milestone
251-
7 upgrades this to Gateway-pinned, namespaced bundle bytes. Isolation, checkout ownership, and
252-
durable offline recovery actions remain milestone 6 work.
249+
while preserving hashes named by durable environments and placements. Isolation,
250+
checkout ownership, and durable offline recovery actions remain milestone 6
251+
work.
253252

254253
### Trust model (operator-decided, v1)
255254

@@ -318,10 +317,15 @@ it cannot rot into approval fatigue or silent surprise:
318317
silently.
319318

320319
The first milestone 7 slice (#123985) adds the private paired-channel install
321-
command, one-use Gateway download capability, bounded archive validation,
322-
script-disabled dependency materialization, and atomic namespaced publication.
323-
Device provisioning continues to use the local-build claim until the next slice
324-
cuts it over and removes that temporary path.
320+
command, one-use Gateway download capability, bounded archive validation, and
321+
atomic namespaced publication. The cutover slice (#124037) packages the complete
322+
worker JavaScript dependency closure into one dedicated, hash-covered executable,
323+
installs that exact Gateway artifact before device environments become ready,
324+
requires its durable receipt across attach, admission, placement, tunnel, and
325+
launch, retires stale environments for idempotent reprovisioning, and removes
326+
local-package execution. The remaining
327+
slice separates inventory consent/capacity from installed bundle status, exposes
328+
the installed version on the devices page, and bounds superseded node bundle GC.
325329

326330
### Projects read model (milestone 4 foundation)
327331

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare const coreBundle: {
2+
getUserAgent(): string;
3+
};
4+
5+
export default coreBundle;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Build-visible bridge for playwright-core's private User-Agent helper.
2+
import coreBundle from "playwright-core/lib/coreBundle";
3+
4+
export default coreBundle;
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
/**
22
* Playwright runtime loader.
33
*
4-
* Loads playwright-core through CommonJS require so the browser plugin can use
5-
* the dependency from the packaged runtime boundary.
4+
* Static package imports keep the worker deploy build's executable closure visible
5+
* to the bundler while normal package builds may still externalize the dependency.
66
*/
7-
import { createRequire } from "node:module";
7+
import playwrightCoreDefault from "playwright-core";
88
import type * as PlaywrightCore from "playwright-core";
9-
10-
const require = createRequire(import.meta.url);
11-
const playwrightCoreBundle = require("playwright-core/lib/coreBundle") as {
12-
getUserAgent: () => string;
13-
};
9+
import coreBundle from "./playwright-core-bundle.runtime.mjs";
1410

1511
/** Runtime playwright-core module instance. */
16-
export const playwrightCore = require("playwright-core") as typeof PlaywrightCore;
12+
export const playwrightCore = playwrightCoreDefault as typeof PlaywrightCore;
1713

1814
/** Dependency-owned User-Agent used by Playwright's native CDP WebSocket transport. */
19-
export const getPlaywrightUserAgent = playwrightCoreBundle.getUserAgent;
15+
export const getPlaywrightUserAgent = (coreBundle as { getUserAgent: () => string }).getUserAgent;

‎packages/gateway-protocol/src/schema/environments.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,29 @@ describe("worker environment protocol schemas", () => {
187187
status: "available",
188188
}),
189189
).toBe(true);
190+
expect(
191+
Value.Check(EnvironmentSummarySchema, {
192+
id: "node:outdated",
193+
type: "node",
194+
status: "available",
195+
issues: [
196+
{
197+
code: "update-required",
198+
action: "update-and-reconnect",
199+
updateCommand: "openclaw update",
200+
headlessReconnectCommand: "openclaw node restart",
201+
},
202+
],
203+
}),
204+
).toBe(true);
205+
expect(
206+
Value.Check(EnvironmentSummarySchema, {
207+
id: "node:outdated",
208+
type: "node",
209+
status: "available",
210+
issues: [{ code: "update-required", action: "run-legacy-worker" }],
211+
}),
212+
).toBe(false);
190213
expect(
191214
Value.Check(EnvironmentSummarySchema, {
192215
...workerSummary("ready", "available"),

0 commit comments

Comments
 (0)