Skip to content

Commit 8fdf757

Browse files
authored
feat(gateway): live Desktop observer for cloud workers (Labs) (#120727)
* feat(gateway): live desktop observer for cloud workers Adds live observation for cloud worker desktops through the gateway and Crabbox plugin, including desktop provisioning, persisted desktop metadata, tunneled WebSocket proxying, and the worker.desktop.observe protocol method. The gateway, Crabbox plugin, and gateway protocol surfaces remain off by default behind the cloudWorkers.desktop Labs flag. * feat(ui): Desktop panel for cloud worker observation * docs(gateway): document cloud worker desktop lab * fix(ci): regenerate contract baselines after rebase * fix(protocol): regenerate Android gateway methods * fix(ci): align rebased SDK and lint baselines * fix(gateway): enforce view-only RFB boundary and fence desktop teardown * fix(gateway): tighten RFB filter surface * fix(state): keep pre-desktop databases readable and harden view-only RFB * fix(gateway): fence desktop observer upgrades behind work admission * fix(gateway): bind desktop observer tokens to their owner epoch * fix(ci): regenerate config and SDK baselines after rebase * fix(ci): regenerate native protocol and SDK baselines * fix(ci): regenerate contracts after main rebase * fix(state): register desktop metadata as lazy additive * fix(ci): regenerate SDK baseline after final direct-merge rebase
1 parent 2f8c950 commit 8fdf757

75 files changed

Lines changed: 3573 additions & 189 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/android/app/src/main/java/ai/openclaw/app/gateway/GatewayProtocol.kt‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,21 @@ data class SessionObserverDigest(
139139
val planProgress: SessionObserverPlanProgress? = null,
140140
)
141141

142+
@Serializable
143+
data class WorkerDesktopObserveParams(
144+
val environmentId: String,
145+
val control: Boolean? = null,
146+
)
147+
148+
@Serializable
149+
data class WorkerDesktopObserveResult(
150+
val transport: String = "rfb",
151+
val wsPath: String,
152+
val expiresAtMs: Long,
153+
val control: Boolean,
154+
val vncPassword: String? = null,
155+
)
156+
142157
@Serializable
143158
data class GatewayEventFrameStateVersion(
144159
val presence: Long,
@@ -511,6 +526,7 @@ enum class GatewayMethod(
511526
SessionsPatchMany("sessions.patchMany"),
512527
UpdateHold("update.hold"),
513528
SessionsCatalogStartTerminal("sessions.catalog.startTerminal"),
529+
WorkerDesktopObserve("worker.desktop.observe"),
514530
}
515531

516532
enum class GatewayEvent(

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

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,7 @@ public struct WorkerEnvironmentMetadata: Codable, Sendable {
18031803
public let attachedsessionids: [String]
18041804
public let tunnelstatus: WorkerTunnelStatus
18051805
public let error: String?
1806+
public let desktop: Bool?
18061807

18071808
public init(
18081809
providerid: String,
@@ -1812,7 +1813,8 @@ public struct WorkerEnvironmentMetadata: Codable, Sendable {
18121813
idlems: Int? = nil,
18131814
attachedsessionids: [String],
18141815
tunnelstatus: WorkerTunnelStatus,
1815-
error: String? = nil)
1816+
error: String? = nil,
1817+
desktop: Bool? = nil)
18161818
{
18171819
self.providerid = providerid
18181820
self.leaseid = leaseid
@@ -1822,6 +1824,7 @@ public struct WorkerEnvironmentMetadata: Codable, Sendable {
18221824
self.attachedsessionids = attachedsessionids
18231825
self.tunnelstatus = tunnelstatus
18241826
self.error = error
1827+
self.desktop = desktop
18251828
}
18261829

18271830
private enum CodingKeys: String, CodingKey {
@@ -1833,6 +1836,7 @@ public struct WorkerEnvironmentMetadata: Codable, Sendable {
18331836
case attachedsessionids = "attachedSessionIds"
18341837
case tunnelstatus = "tunnelStatus"
18351838
case error
1839+
case desktop
18361840
}
18371841
}
18381842

@@ -2042,6 +2046,54 @@ public struct EnvironmentsStatusResult: Codable, Sendable {
20422046
}
20432047
}
20442048

2049+
public struct WorkerDesktopObserveParams: Codable, Sendable {
2050+
public let environmentid: String
2051+
public let control: Bool?
2052+
2053+
public init(
2054+
environmentid: String,
2055+
control: Bool? = nil)
2056+
{
2057+
self.environmentid = environmentid
2058+
self.control = control
2059+
}
2060+
2061+
private enum CodingKeys: String, CodingKey {
2062+
case environmentid = "environmentId"
2063+
case control
2064+
}
2065+
}
2066+
2067+
public struct WorkerDesktopObserveResult: Codable, Sendable {
2068+
public let transport: String
2069+
public let wspath: String
2070+
public let expiresatms: Int
2071+
public let control: Bool
2072+
public let vncpassword: String?
2073+
2074+
public init(
2075+
transport: String,
2076+
wspath: String,
2077+
expiresatms: Int,
2078+
control: Bool,
2079+
vncpassword: String? = nil)
2080+
{
2081+
self.transport = transport
2082+
self.wspath = wspath
2083+
self.expiresatms = expiresatms
2084+
self.control = control
2085+
self.vncpassword = vncpassword
2086+
}
2087+
2088+
private enum CodingKeys: String, CodingKey {
2089+
case transport
2090+
case wspath = "wsPath"
2091+
case expiresatms = "expiresAtMs"
2092+
case control
2093+
case vncpassword = "vncPassword"
2094+
}
2095+
}
2096+
20452097
public struct SystemInfoParams: Codable, Sendable {}
20462098

20472099
public struct SystemInfoResult: Codable, Sendable {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"core": 2326,
2+
"core": 2284,
33
"channel": 3694,
4-
"plugin": 4056
4+
"plugin": 4053
55
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
467b81275246a1512907edb55c00cdb1bfa7b929977cde5c190b97299639249b config-baseline.json
2-
fdcb5717167f7ac0200281a5d0cb5362fbaf8c6b5f51f866958f85683189a46f config-baseline.core.json
1+
0ce08dfbe1fb23bd5bb03ae12f46fccff569b0aaf374b3984f1fbcb61d2f6b66 config-baseline.json
2+
8cbea1bb4c3c0bd933da5641c08a3086e4579d8bcc496468cc951d7e388978c9 config-baseline.core.json
33
d752cf8a7ecd2d31684557aeae4d2c08f2ec4ce5f091bce32d54a4685eefdf45 config-baseline.channel.json
4-
6df755fceeafe28ded568b6f4bb1bd0bd49050a601732e52aacf4ab56e398b19 config-baseline.plugin.json
4+
7ce54344ec431d11f8a1ac92a112a9352fc55a4e43be71a08b91f9a06f924fb6 config-baseline.plugin.json

‎docs/.generated/plugin-sdk-api-baseline.sha256‎

Lines changed: 111 additions & 111 deletions
Large diffs are not rendered by default.

‎docs/concepts/experimental-features.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Experimental features are preview surfaces behind explicit flags. They need more
2121
| Local model runtime | `agents.defaults.experimental.localModelLean`, `agents.entries.*.experimental.localModelLean` | A smaller or stricter local backend chokes on OpenClaw's full default tool surface | [Local Models](/gateway/local-models) |
2222
| Codex harness | `plugins.entries.codex.config.appServer.experimental.sandboxExecServer` | You want native Codex app-server 0.143.0 or newer to target an OpenClaw sandbox-backed exec-server instead of disabling Code Mode | [Codex harness reference](/plugins/codex-harness-reference#sandboxed-native-execution) |
2323
| Code Mode | `tools.codeMode.enabled` | You want compact code-orchestrated access to a hidden OpenClaw tool catalog | [Code Mode](/tools/code-mode) |
24+
| Cloud workers | `cloudWorkers.desktop` | You want to watch or control desktop-capable cloud worker environments from the Control UI | [Cloud Worker Desktop](/gateway/cloud-workers#desktop-interactive) |
2425
| Swarm | `tools.swarm.enabled` | You want Code Mode scripts to orchestrate bounded groups of sub-agents in parallel | [Swarm](/tools/swarm) |
2526

2627
## Control UI Labs
@@ -30,9 +31,11 @@ Control UI switch. Enabling or disabling a lab patches the canonical Gateway
3031
config immediately; the page shows a restart hint only when a feature requires
3132
one.
3233

33-
Code Mode and Swarm are the currently shipped Labs entries. Both switches
34-
write existing validated config keys and normally take effect for future agent
35-
runs without restarting the Gateway.
34+
The currently shipped Labs entries are Code Mode, Swarm, Tool Search,
35+
Tool-loop detection, Lean tools for local models, Message audit metadata, and
36+
Cloud Worker Desktop. Message audit metadata and Cloud Worker Desktop require a
37+
Gateway restart; the other switches normally take effect for future agent runs
38+
without restarting.
3639

3740
## Local model lean mode
3841

‎docs/gateway/cloud-workers.md‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,12 @@ Add a profile under `cloudWorkers.profiles` in `openclaw.json`:
9898

9999
Profile fields:
100100

101-
| Key | Meaning |
102-
| ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
103-
| `provider` | Worker provider id registered by a plugin (`crabbox` for the bundled plugin). |
104-
| `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. |
105-
| `settings` | Provider-owned JSON. For crabbox: `provider` (backend), `class` (machine class), `ttl`, `idleTimeout` (Go durations), optional `setup` and absolute `binary` path. OpenClaw forces public SSH and disables managed Tailscale for these leases. |
101+
| Key | Meaning |
102+
| ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
103+
| `provider` | Worker provider id registered by a plugin (`crabbox` for the bundled plugin). |
104+
| `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. |
105+
| `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. |
106+
| `lifetime` | Optional stored policy (`idleTimeoutMinutes`, `maxLifetimeMinutes`). |
106107

107108
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.
108109

@@ -184,6 +185,18 @@ openclaw gateway call sessions.reclaim \
184185

185186
Placement moves through a durable state machine (`local → requested → provisioning → syncing → starting → active`), so a Gateway restart mid-dispatch reconciles instead of leaking machines. A failed model turn keeps the active placement available for a retry. Workspace path conflicts keep the local version, apply the rest of the cloud result, and preserve the staged cloud ref for inspection; other reconciliation or lifecycle failures retain their durable recovery fence and diagnostic tail until recovery can safely retry or reclaim the environment.
186187

188+
## Desktop (interactive)
189+
190+
Cloud Worker Desktop is an experimental Labs feature and is off by default. Enable **Cloud Worker Desktop** in **Settings → Agents & Tools → Labs**, or set `cloudWorkers.desktop: true`, then restart the Gateway for the Desktop panel to appear.
191+
192+
Set `"desktop": true` in a crabbox profile's `settings` to lease worker boxes with an interactive desktop (TigerVNC on the box loopback with a per-lease password). The Labs gate enables the observer surface and panel; the profile setting gives newly leased workers the desktop capability. Desktop is a warm-time capability: it cannot be added to an already-provisioned environment, so enable it on the profile before dispatching.
193+
194+
Operators with `operator.admin` access watch and control the desktop from the Control UI **Desktop** panel (also in the command palette). The panel lists desktop-capable environments from `environments.list` and connects through the Gateway, which forwards the box's loopback VNC over the same pinned SSH transport used for worker traffic — the desktop is never exposed on the box's network, and the VNC password is delivered only inside the authenticated `worker.desktop.observe` RPC result, never stored by the Gateway.
195+
196+
Connections start view-only. **Take control** requests an input-capable connection; only one controller is active at a time, and taking control disconnects the previous controller (they are downgraded to view-only). Up to 8 observers can watch one environment. The desktop forward starts on first observe and shuts down about a minute after the last observer disconnects; stopping or reclaiming the environment tears it down immediately.
197+
198+
Desktop observe is not supported when the Gateway itself runs on Windows.
199+
187200
## Security model
188201

189202
- **Closed worker ingress.** Workers speak a dedicated protocol on the tunneled socket with a closed method allowlist — a worker cannot call operator RPCs.

‎docs/gateway/protocol.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ methods. Treat this as feature discovery, not a full enumeration of
625625
- `artifacts.list`, `artifacts.get`, and `artifacts.download` expose transcript-derived artifact summaries and downloads for an explicit `sessionKey`, `runId`, or `taskId` scope. Run and task queries resolve the owning session server-side and only return transcript media with matching provenance; unsafe or local URL sources return unsupported downloads instead of fetching server-side.
626626
- `environments.list` and `environments.status` remain available without cloud-worker profiles and preserve gateway-local and node environment discovery. Configured cloud workers and durable records left by earlier profiles add `worker` metadata with `providerId`, optional `leaseId`, `state`, `ageMs`, optional `idleMs`, and `attachedSessionIds`. Worker lifecycle states are `requested`, `provisioning`, `bootstrapping`, `ready`, `attached`, `idle`, `draining`, `destroying`, `destroyed`, `failed`, and `orphaned`.
627627
- `environments.create` (`{ profileId, idempotencyKey }`) provisions a worker from a configured plugin provider profile; retries with the same key reuse the durable operation. `environments.destroy` (`{ environmentId }`) requests idempotent teardown of a durable worker environment. Both require `operator.admin`, are control-plane writes, and return the same environment summary shape used by status responses.
628+
- `worker.desktop.observe` (`{ environmentId, control? }`, `operator.admin`) starts or reuses the environment's desktop forward and returns `{ transport, wsPath, expiresAtMs, control, vncPassword? }`. `wsPath` carries a single-use 60-second token for the Gateway's desktop observer WebSocket; reconnecting requires a fresh observe call. Environments with an observable desktop advertise `worker.desktop: true` in `environments.list`. The method is advertised only when the `cloudWorkers.desktop` lab is enabled. See [Cloud workers](/gateway/cloud-workers#desktop-interactive).
628629
- `agent.identity.get` returns the effective assistant identity for an agent or session.
629630
- `agent.wait` waits for a run to finish and returns the terminal snapshot when available.
630631

‎docs/plugins/sdk-overview.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ and external URLs. Registering another provider replaces the current provider.
120120
Worker providers must also declare their id in `contracts.workerProviders`.
121121
Core persists durable intent before `provision(profile, operationId)`. Providers validate settings before external allocation and throw `WorkerProviderError` for permanent profile rejection. `provision` must adopt the same lease when the operation id repeats.
122122
Core persists the validated profile settings with the lease and supplies that snapshot to `destroy({ leaseId, profile })`, which must be idempotent, and `inspect({ leaseId, profile })`, which returns `active`, `destroyed`, or `unknown`. This lets providers route lifecycle calls after a gateway restart or named-profile removal. SSH endpoints use a `SecretRef` for `keyRef`, never inline key material, and include a `hostKey` from trusted provisioning output as exactly `algorithm base64`, without a hostname or comment. Core pins `hostKey` and never trusts a key from the first connection. Providers may also return up to 10 ordered, unique `fallbackPorts` (integer ports from 1 through 65535, excluding the primary `port`); core validates and persists those advertised candidates for idempotent probes, content-addressed transfers, receipt/lock-guarded artifact installation, convergent managed-worktree mirroring, and tunnel reconnects. Ambiguous unguarded stateful commands fail closed and are not replayed across candidates. A lease may set `sharedHost: true` when the SSH account also owns unrelated processes; core then avoids host-wide process freezing during workspace reconciliation. Omitted or `false` means a dedicated worker host. Active inspection repeats this fact so core can reconcile provider-owned isolation for leases persisted before the field existed; tunnel startup waits for that first authoritative inspection. A provider that mints a dynamic `keyRef` can implement `resolveSshIdentity({ leaseId, profile, keyRef })`; when present, that resolver is authoritative, while providers without it use the configured generic secret resolver.
123+
`WorkerLease.desktop` is optional and has the shape `{ protocol: "rfb"; port: number; passwordFilePath?: string }`; `passwordFilePath`, when present, must be absolute. Providers report this warm-time capability from `provision`; it cannot be retrofitted onto a live lease. The Gateway reads the password file over the provider's SSH endpoint when needed and never persists the password.
123124
Providers with renewable leases can also implement `renew(leaseId)`.
124125
`inspect` must throw on transient or indeterminate failures; return `unknown` only for authoritative absence. Core marks an active local record orphaned, or treats the absence as teardown completion after a persisted destroy request.
125126

‎extensions/crabbox/src/crabbox-worker-profile.ts‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ import fs from "node:fs";
33
import path from "node:path";
44
import { WorkerProviderError, type WorkerProfile } from "openclaw/plugin-sdk/plugin-entry";
55

6-
const PROFILE_KEYS = new Set(["binary", "class", "idleTimeout", "provider", "setup", "ttl"]);
6+
const PROFILE_KEYS = new Set([
7+
"binary",
8+
"class",
9+
"desktop",
10+
"idleTimeout",
11+
"provider",
12+
"setup",
13+
"ttl",
14+
]);
715
const GO_DURATION_PATTERN = /^\+?(?:(?:\d+(?:\.\d*)?|\.\d+)(?:ns|us|µs|μs|ms|s|m|h))+$/u;
816
const GO_DURATION_TOKEN_PATTERN = /(\d+(?:\.\d*)?|\.\d+)(ns|us|µs|μs|ms|s|m|h)/gu;
917
const MAX_GO_DURATION_NANOSECONDS = 9_223_372_036_854_775_807n;
@@ -21,6 +29,7 @@ const DURATION_UNIT_NANOSECONDS: Readonly<Record<string, bigint>> = {
2129
type CrabboxProfile = {
2230
binary?: string;
2331
class: string;
32+
desktop?: boolean;
2433
idleTimeout: string;
2534
provider: string;
2635
ttl: string;
@@ -105,7 +114,35 @@ export function parseCrabboxProfile(profile: WorkerProfile): CrabboxProfile {
105114
if (setupValue !== undefined && !setup) {
106115
throw new WorkerProviderError("Crabbox profile setup must be a non-empty command string");
107116
}
108-
return { binary, class: machineClass, idleTimeout, provider, setup, ttl };
117+
const desktop = profile.desktop;
118+
if (desktop !== undefined && typeof desktop !== "boolean") {
119+
throw new WorkerProviderError("Crabbox profile desktop must be a boolean");
120+
}
121+
return { binary, class: machineClass, desktop, idleTimeout, provider, setup, ttl };
122+
}
123+
124+
export function buildCrabboxWarmupArgs(profile: CrabboxProfile, slug: string): string[] {
125+
const args = [
126+
"warmup",
127+
"--provider",
128+
profile.provider,
129+
"--network",
130+
"public",
131+
"--tailscale=false",
132+
"--class",
133+
profile.class,
134+
"--ttl",
135+
profile.ttl,
136+
"--idle-timeout",
137+
profile.idleTimeout,
138+
"--slug",
139+
slug,
140+
"--keep=true",
141+
];
142+
if (profile.desktop) {
143+
args.push("--desktop");
144+
}
145+
return args;
109146
}
110147

111148
function defaultIsExecutable(candidate: string, platform: NodeJS.Platform): boolean {

0 commit comments

Comments
 (0)