Skip to content

Commit 6cd1133

Browse files
authored
feat(cloud-workers): openclaw worker mode running the embedded loop on the box (#105865)
* feat(cloud-workers): add restricted worker runtime * test(cloud-workers): cover worker runtime contracts * docs(cloud-workers): document worker mode * fix(worker): bound connection lifecycle * fix(worker): serialize transcript flushes * fix(worker): fail stop stale transcript bases * fix(worker): degrade lossy live streaming * test(worker): cover inference reconnect fencing * refactor(worker): split RPC clients * refactor(worker): split connection transport * refactor(worker): split embedded runtime * refactor(worker): narrow worker module exports
1 parent 9b565e8 commit 6cd1133

32 files changed

Lines changed: 5714 additions & 8 deletions

‎docs/cli/index.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Setup commands by intent:
2727
| Health and sessions | [`status`](/cli/status) · [`health`](/cli/health) · [`sessions`](/cli/sessions) · [`audit`](/cli/audit) |
2828
| Gateway and logs | [`gateway`](/cli/gateway) · [`logs`](/cli/logs) · [`system`](/cli/system) |
2929
| Models and inference | [`models`](/cli/models) · [`promos`](/cli/promos) · [`infer`](/cli/infer) · `capability` (alias for [`infer`](/cli/infer)) · [`memory`](/cli/memory) · [`commitments`](/cli/commitments) · [`wiki`](/cli/wiki) |
30-
| Network and nodes | [`directory`](/cli/directory) · [`nodes`](/cli/nodes) · [`devices`](/cli/devices) · [`node`](/cli/node) |
30+
| Network and nodes | [`directory`](/cli/directory) · [`nodes`](/cli/nodes) · [`devices`](/cli/devices) · [`node`](/cli/node) · [`worker`](/cli/worker) |
3131
| Runtime and sandbox | [`approvals`](/cli/approvals) · `exec-policy` (see [`approvals`](/cli/approvals)) · [`sandbox`](/cli/sandbox) · [`tui`](/cli/tui) · `chat`/`terminal` (aliases for [`tui --local`](/cli/tui)) · [`browser`](/cli/browser) |
3232
| Automation | [`cron`](/cli/cron) · [`tasks`](/cli/tasks) · [`hooks`](/cli/hooks) · [`webhooks`](/cli/webhooks) · [`transcripts`](/cli/transcripts) |
3333
| Discovery and docs | [`dns`](/cli/dns) · [`docs`](/cli/docs) |
@@ -344,6 +344,7 @@ openclaw [--dev] [--profile <name>] <command>
344344
uninstall
345345
stop
346346
restart
347+
worker
347348
approvals
348349
get
349350
set

‎docs/cli/worker.md‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
summary: "Internal operator reference for the restricted cloud worker runtime"
3+
read_when:
4+
- Operating or debugging gateway-launched cloud workers
5+
- Verifying worker admission, session assignment, or local tool isolation
6+
title: "Worker"
7+
---
8+
9+
# `openclaw worker`
10+
11+
`openclaw worker` is the restricted runtime entry point for a cloud worker
12+
orchestrator to launch inside a prepared worker environment. It is not a
13+
general-purpose command for manual worker registration.
14+
15+
The gateway installs the matching OpenClaw bundle and opens the host-key-pinned
16+
reverse SSH tunnel. The worker launcher starts this command with a prepared
17+
assignment. The command connects through the tunnel-forwarded local socket and
18+
admits as the dedicated `worker` role.
19+
20+
## Launch contract
21+
22+
The command reads exactly one bounded JSON launch envelope from standard input.
23+
The envelope carries the local socket location, minted worker credential, bundle
24+
and protocol identity, owner epoch, and the single assigned session and turn.
25+
The credential is never accepted through command-line arguments, and this page
26+
intentionally provides no credential or hand-authored envelope example.
27+
28+
Admission fails closed if the envelope is invalid, the credential is rejected,
29+
the bundle or protocol features do not match, or the session and owner epoch are
30+
no longer current. Operators should start workers through the cloud worker
31+
orchestrator rather than invoke this entry point directly.
32+
33+
## Runtime boundary
34+
35+
The process runs the normal embedded agent loop with a restricted backend:
36+
37+
- The `read`, `write`, `edit`, `apply_patch`, `exec`, and `process` coding tools
38+
run locally in the worker workspace.
39+
- Model calls use the gateway inference proxy. No local model auth profile is
40+
loaded.
41+
- Transcript writes use the gateway transcript-commit RPC.
42+
- Streaming and tool lifecycle updates use the gateway live-event RPC.
43+
- Only the assigned session and turn are accepted.
44+
45+
Worker mode does not start channels, Gateway HTTP surfaces, or plugin auto-start
46+
beyond the assigned session toolset. It uses a throwaway state directory and has
47+
no standing provider or forge credentials.
48+
49+
Worker-to-worker session dispatch is not exposed in this mode. Agent dispatch
50+
and placement remain gateway-owned milestone-3 surfaces.
51+
52+
The prepared assignment carries the transcript context, accepted base leaf,
53+
commit sequence, and live-event cursor. On a tunnel reconnect, the process
54+
re-admits with the same credential and owner epoch, retains the accepted
55+
transcript base, replays its unacknowledged live-event tail, and reattaches an
56+
in-flight inference turn with the same identity. The terminal inference message
57+
is authoritative if streamed deltas were missed. A superseding owner epoch
58+
fences the process and causes a clean exit.
59+
60+
A `stale-base-leaf` transcript rejection fail-stops the current run. Worker
61+
mode does not retry the rejected sequence against a different leaf, so no
62+
duplicate commit is produced; any still-uncommitted in-memory tail from that
63+
run is lost. Relaunch belongs to the milestone-3 placement owner, which must
64+
create a fresh assignment from the gateway's authoritative transcript and
65+
commit ledger. Likewise, a gateway process restart terminates a pending
66+
inference turn with a provider error; only a tunnel or worker WebSocket
67+
reconnect can reattach to an active same-process inference stream.
68+
69+
See [Gateway protocol](/gateway/protocol#worker-role-and-closed-protocol) for the
70+
closed worker RPC surface and [Cloud workers plan](/plan/cloud-workers) for the
71+
architecture and security model.

‎docs/docs.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,8 @@
18051805
"cli/flows",
18061806
"cli/node",
18071807
"cli/nodes",
1808-
"cli/sandbox"
1808+
"cli/sandbox",
1809+
"cli/worker"
18091810
]
18101811
},
18111812
{

‎docs/docs_map.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,6 +2159,14 @@ Do not edit it by hand; run `pnpm docs:map:gen`.
21592159
- H3: Dispatch starts nothing
21602160
- H2: Related
21612161

2162+
## cli/worker.md
2163+
2164+
- Route: /cli/worker
2165+
- Headings:
2166+
- H1: openclaw worker
2167+
- H2: Launch contract
2168+
- H2: Runtime boundary
2169+
21622170
## concepts/active-memory.md
21632171

21642172
- Route: /concepts/active-memory

‎docs/gateway/protocol.md‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,15 @@ verifies a hash-at-rest, short-lived credential bound to the environment, bundle
176176
hash, owner epoch, RPC-set version, expiry, and one nullable session; it
177177
separately checks the current version and feature set. Success returns minimal
178178
`worker-hello-ok`; feature negotiation is independent of the general protocol
179-
version. Frames stay under 64 KiB. The closed allowlist contains
180-
`worker.heartbeat`, `worker.transcript.commit`, and `worker.live-event`.
181-
Transcript commits use owner-epoch fencing, a gateway-owned session binding, base-leaf
182-
compare-and-swap, and durable sequence replay; the gateway generates transcript
183-
entry and parent IDs through the normal session writer. Ownership and expiry are
184-
rechecked on each RPC.
179+
version. Frames stay under 64 KiB, except a negotiated `worker.inference.start`
180+
frame may be up to 25 MiB. The closed allowlist contains `worker.heartbeat`,
181+
`worker.transcript.commit`, `worker.live-event`, `worker.inference.start`, and
182+
`worker.inference.cancel`.
183+
184+
Transcript commits use owner-epoch fencing, a gateway-owned session binding,
185+
base-leaf compare-and-swap, and durable sequence replay; the gateway generates
186+
transcript entry and parent IDs through the normal session writer. Ownership and
187+
expiry are rechecked on each RPC.
185188

186189
### Client capabilities
187190

‎src/cli/command-catalog.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,16 @@ export const cliCommandCatalog: readonly CliCommandCatalogEntry[] = [
316316
exact: true,
317317
policy: { networkProxy: "default" },
318318
},
319+
{
320+
commandPath: ["worker"],
321+
exact: true,
322+
policy: {
323+
bypassConfigGuard: true,
324+
hideBanner: true,
325+
loadPlugins: "never",
326+
networkProxy: "bypass",
327+
},
328+
},
319329
{ commandPath: ["nodes"], policy: { networkProxy: "bypass" } },
320330
{ commandPath: ["pairing"], policy: { networkProxy: "bypass" } },
321331
{ commandPath: ["proxy"], policy: { networkProxy: "bypass" } },

‎src/cli/command-path-policy.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ describe("command-path-policy", () => {
187187
});
188188

189189
it("resolves mixed startup-only rules", () => {
190+
expectResolvedPolicy(["worker"], {
191+
bypassConfigGuard: true,
192+
loadPlugins: "never",
193+
hideBanner: true,
194+
networkProxy: "bypass",
195+
});
190196
expectResolvedPolicy(["configure"], {
191197
bypassConfigGuard: true,
192198
loadPlugins: "never",

‎src/cli/command-startup-policy.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ describe("command-startup-policy", () => {
248248
expect(policy.suppressDoctorStdout).toBe(true);
249249
});
250250

251+
it("isolates cloud worker startup", () => {
252+
const policy = resolvePolicy({ commandPath: ["worker"] });
253+
254+
expect(shouldBypassConfigGuardForCommandPath(["worker"])).toBe(true);
255+
expect(policy.hideBanner).toBe(true);
256+
expect(policy.loadPlugins).toBe(false);
257+
});
258+
251259
it("suppresses startup stdout for the bare acp protocol", () => {
252260
expect(resolvePolicy({ commandPath: ["acp"] }).suppressDoctorStdout).toBe(true);
253261
});

‎src/cli/program/register.subclis-core.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ const entrySpecs: readonly CommandGroupDescriptorSpec<SubCliRegistrar>[] = [
159159
loadModule: () => import("../node-cli.js"),
160160
exportName: "registerNodeCli",
161161
},
162+
{
163+
commandNames: ["worker"],
164+
loadModule: () => import("../worker-cli.js"),
165+
exportName: "registerWorkerCli",
166+
},
162167
{
163168
commandNames: ["sandbox"],
164169
loadModule: () => import("../sandbox-cli.js"),

‎src/cli/program/subcli-descriptors.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ const subCliCommandCatalog = defineCommandDescriptorCatalog([
7676
description: "Run and manage the headless node host service",
7777
hasSubcommands: true,
7878
},
79+
{
80+
name: "worker",
81+
description: "Run the restricted cloud worker runtime",
82+
hasSubcommands: false,
83+
},
7984
{
8085
name: "sandbox",
8186
description: "Manage sandbox containers (Docker-based agent isolation)",

0 commit comments

Comments
 (0)