Skip to content

Commit 49a8b1c

Browse files
authored
fix(cloud): bind computer control to session desktops (#132374)
* fix(cloud): bind computer control to session desktops Route the shared computer tool through the exact admitted session placement for OpenClaw workers and Codex remote execution. Keep disposable desktop commands private, settle native provider readiness before enrollment, and preserve screenshot media through bounded worker transport and replay. Close owned native executions before terminal delivery and allow exact pending node replies to complete during Gateway shutdown. Serialize cloud workspace result ref mutations across linked worktrees without serializing uploads, and preserve durable result recovery with atomic Git ref moves. Document tool policy, desktop setup, image limits, and operator handoff. Related UI integration landed in #132255. * test(worker): own computer observation persistence coverage * fix(cloud): preserve native workspace lifetime beyond RPC expiry * fix(cloud): close computer execution with worker connection Keep prepared computer state, its bound connection and cleanup promise under one Gateway owner. An idle disconnect now closes the captured native execution, fences reconnect input, and lets shutdown join the native ACK. Reject missing or competing connection lifetimes without affecting durable session RPCs or Codex's local host binding. Cover the actual WebSocket completed-action disconnect, same-claim owner replacement, fresh-turn recovery, retained handles and concurrent cleanup. Document the recovery action and add the cloud computer control changelog. * fix(codex): keep computer tools outside native code mode * fix(cloud): retain shared desktop cleanup completion ownership * test(codex): refresh direct-only feature prompt snapshots * fix(gateway): keep idle desktop streams alive Share the control connection's WebSocket keepalive scheduler with desktop observers and node desktop/portal streams. Preserve the main connection's missed-pong policy without treating remote stream backpressure as revocation. Retire auxiliary timers with their existing transport owners. Cover idle control frames, exact stream bytes after remote pause/resume, and owner-driven close cleanup with real WebSocket regression tests. * test(cloud): clear stale desktop runtime during bootstrap * docs: leave cloud release notes to release automation
1 parent 475f979 commit 49a8b1c

123 files changed

Lines changed: 6999 additions & 873 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.

‎docs/gateway/cloud-sessions.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ Open **Desktop** from a session to view its execution machine. Cloud sessions se
6161

6262
The machine must already support desktop viewing. For cloud workers, enable the [Cloud Worker Desktop lab and desktop profile setting](/gateway/cloud-workers#desktop-interactive). Opening Desktop starts in view-only mode and does not change the machine's permissions or the agent's tool policy. The global Desktop command in the command palette still opens the machine picker, including on chat pages.
6363

64+
## Desktop and computer control
65+
66+
A desktop-enabled cloud session uses the same machine for the chat Desktop panel and the agent's `computer` tool. Enable the **Cloud Worker Desktop** lab and provision a Crabbox profile with `settings.desktop: true`. OpenClaw starts the worker's CUA provider inside the provisioned desktop session; the agent does not need to discover or choose a paired computer. Both OpenClaw and Codex sessions use this binding. A paired-device session instead uses that device's enabled Computer Control provider.
67+
68+
Use a vision-capable model and a tool profile that permits `computer`. For the `coding` profile, add `computer` to `tools.alsoAllow`. The bound desktop is available under default remote-session sandbox policy; explicit sandbox allowlists and denies still apply. Observe the Desktop panel while the agent works, and pause the agent before taking manual control to avoid competing input.
69+
70+
Worker transcripts retain screenshots. Codex exposes the computer tool directly, outside code mode, so screenshot results reach the model as images. To keep later model requests within the transport limit, OpenClaw can replace older, already processed images with a text marker in the model context while preserving the current computer frame and unprocessed images. Opaque provider replay remains unchanged; if its required context cannot fit, the turn fails with recovery guidance.
71+
72+
Computer control stays bound to the admitted turn, placement, node connection, and provider. If an OpenClaw worker disconnects, its computer execution closes even between tool calls; start a new turn to regain computer control after reconnecting. Other durable session operations can still finish. Stopping or replacing the machine invalidates old tool handles; an unavailable desktop never selects another connected computer. Disposable cloud desktops remain absent from the ordinary paired-computer picker. See [Computer use](/nodes/computer-use) for supported actions and [Cloud Worker Desktop](/gateway/cloud-workers#desktop-interactive) for setup and viewing permissions.
73+
6474
## Automatic load balancing across devices
6575

6676
You do not have to pick a device. Choosing **Auto** (least-busy device) in the Place picker — or dispatching with `autoDevice: true` — selects a paired session host automatically and retries up to three ranked hosts if provisioning fails before a machine is allocated. OpenClaw `worker-turn` placements rank hosts by most free worker slots, breaking ties by device ID; Codex `remote-exec` placements do not consume worker slots, so eligible hosts are ranked by device ID alone. When no host qualifies, the error says exactly why: no session hosts paired, all disconnected, or all at capacity.

‎docs/gateway/cloud-workers.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ For a loopback Gateway behind public HTTPS ingress, set `gateway.publicOrigin` t
3939

4040
The proxy must also forward `/__openclaw__/worker-bootstrap/artifacts/<sha256>` to the Gateway, alongside its public node and worker routes. A new cloud node downloads its runtime over this authenticated HTTP route before it can connect over WebSocket. Preserve the `Authorization` header; do not expose these archives through an unauthenticated static-file route.
4141

42+
Native node workspace access and reconciliation outlive worker RPC credential expiry; each transfer retains its own ten-minute expiry and the existing revocation and session-ownership checks.
43+
4244
## Requirements
4345

4446
- A worker provider plugin. The bundled `crabbox` plugin drives the [Crabbox](https://crabbox.sh/) CLI; Crabbox owns the supported cloud backends and their configuration. Install Crabbox 0.41.1 or newer for the operating-system user that runs the Gateway and put it on that user's `PATH`, or set `settings.binary` to its absolute path. Keeping placed workers alive also requires a release that includes `crabbox heartbeat` (added after v0.43.0). Versions through 0.43.0 can allocate fixed-ID worker leases but lack heartbeat support; OpenClaw continues operating with one warning, and the coordinator may reap a placed worker after its `idleTimeout`.
@@ -426,8 +428,12 @@ The bundled Crabbox plugin supports direct AWS profiles. Coordinator-backed AWS
426428

427429
Crabbox provisions XFCE on display `:99`, an authenticated RFB server on `127.0.0.1:5900`, a fresh lease-scoped browser profile with CDP on `127.0.0.1:9222`, and fixed zero-argument Browser and Terminal launchers. The provider also installs an OpenClaw worker wallpaper so the disposable desktop is easy to identify. Setup is idempotent and runs before node enrollment on every provisioning replay.
428430

431+
The enrolled node starts CUA inside that same XFCE session. A vision-capable agent whose tool policy permits `computer` controls this desktop through the session's exact placement; it cannot select another node. This works for both OpenClaw workers and Codex remote execution. See [Desktop and computer control](/gateway/cloud-sessions#desktop-and-computer-control) for tool enablement and manual-control guidance.
432+
429433
The desktop never gains public ingress. The node reads `/var/lib/crabbox/vnc.password` locally, probes the authenticated loopback RFB server, and redeems a single-use Gateway broker ticket over the node's already-connected origin. TLS deployments pin the same Gateway certificate used by the node connection. The Gateway revalidates the durable environment, lease, node, owner epoch, desktop descriptor, connection, and pairing both before dispatch and after attach; drain, replacement, or teardown aborts the stream and any pending app launch. The shared desktop session owner performs RFB preauthentication, view-only input filtering, and single-controller arbitration.
430434

435+
The Gateway sends WebSocket keepalives on desktop observer and node desktop or portal streams while idle, so an unchanged screen or quiet preview does not go silent behind a proxy. Backpressure may delay pong replies without revoking the stream; the owning session and control connection still govern teardown.
436+
431437
## Security model
432438

433439
- **Closed worker ingress.** In worker-turn mode, the enrolled node launches the worker child, which dials the Gateway's authenticated public worker route and speaks a dedicated protocol with a closed method allowlist — a worker cannot call operator RPCs.

‎docs/nodes/computer-use.md‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ title: "Computer use"
99

1010
Computer use lets the gateway agent see and control a capable paired desktop. Eligibility is capability-based: the connected node must advertise both `computer.act` and `screen.snapshot`. The node's descriptor identifies the supported v2 action, target, observation, and delivery families, so the built-in `computer` tool exposes only what that provider can faithfully execute. Coordinate actions bind to a node-issued reference frame; capable providers can also address windows and elements, request background delivery, and return structured effect or refusal evidence. A vision-capable model drives the surface through the built-in `computer` agent tool.
1111

12+
For [cloud sessions](/gateway/cloud-sessions#desktop-and-computer-control), the tool is bound to the session's own desktop instead of searching paired nodes. Desktop-enabled Crabbox workers provision CUA in the same desktop session shown by the web Desktop panel. Their private computer endpoint is not exposed as an ordinary paired computer, and tool arguments cannot change its node or Gateway.
13+
1214
The agent emits one uniform command, `computer.act`; it cannot choose how a node fulfills it. On macOS, **Settings → General → Capabilities** selects the node-local provider: Peekaboo is the default and preserves the existing in-process coordinate-action path, while CUA uses a driver daemon embedded in `OpenClaw.app`. The app spawns that daemon directly so it inherits OpenClaw's Accessibility and Screen Recording grants, and the app-owned node worker connects through a private socket. Windows and Linux can use the optional, experimental `cua-computer` plugin, which calls the packaged CUA Driver SDK directly.
1315

1416
Provider selection never falls back per action. Switching providers closes the active execution surface, rotates the provider generation, and re-advertises the node commands. A CUA failure therefore becomes an unavailable result instead of silently running the same action through Peekaboo.
@@ -22,7 +24,7 @@ Provider selection never falls back per action. Switching providers closes the a
2224
- **Windows/Linux fulfiller:** bundled `cua-computer` plugin enabled on Windows x64/ARM64 or glibc-based Linux x64/ARM64. Its package includes the pinned CUA Driver SDK 0.21.0 runtime; no `cua-driver` executable, daemon, or MCP server is configured.
2325
- The pairing update that includes `computer.act` approved on the gateway.
2426
- A vision-capable agent model.
25-
- Tool policy that exposes `computer`. The default `coding` profile does not. Add `computer` to `tools.alsoAllow`; sandboxed agents also need it in `tools.sandbox.tools.alsoAllow`.
27+
- Tool policy that exposes `computer`. The default `coding` profile does not. Add `computer` to `tools.alsoAllow`; ordinary sandboxed agents also need it in `tools.sandbox.tools.alsoAllow`. A cloud session's bound desktop is included in its default sandbox policy, while explicit allowlists and denies still apply.
2628

2729
## The `computer` agent tool
2830

@@ -134,7 +136,9 @@ The result and `window-before.png` / `window-after.png` stay under the scratch d
134136

135137
### Windows and Linux (experimental, direct SDK)
136138

137-
The bundled `cua-computer` plugin provides an experimental fulfiller for Windows and Linux node hosts. It is disabled by default on those platforms (macOS enables it by default for the CUA fulfiller above) and uses the pinned CUA Driver SDK 0.21.0 contract directly:
139+
The bundled `cua-computer` plugin loads its Gateway policy by default on every platform. Local computer control remains opt-in on Windows and Linux; loading the policy alone does not start a native driver, register local computer commands, or probe local driver artifacts. macOS keeps its default CUA integration with the app-owned daemon. Explicitly disabling the plugin also disables its cloud computer policy.
140+
141+
To enable the experimental Windows or Linux node fulfiller, which uses the pinned CUA Driver SDK 0.21.0 contract directly:
138142

139143
1. Enable the plugin:
140144

@@ -150,7 +154,7 @@ The bundled `cua-computer` plugin provides an experimental fulfiller for Windows
150154

151155
OpenClaw checks the SDK package version, the selected OS/CPU package version, regular-file identity, and the pinned SHA-256 digest of the native library and Node runtime. A clean check prints `no findings`. If it reports a `COMPUTER_DRIVER_*` error, reinstall or update OpenClaw on this node host and run the check again. Do not download a standalone `cua-driver` executable or add one to `PATH`; Windows and Linux use the npm-installed in-process SDK.
152156

153-
3. Start `openclaw node run` from the interactive desktop session. The plugin repeats artifact verification at startup before importing native code, then lazily creates its configured SDK runtime and one trusted lifecycle session for each provider execution. Window and desktop targets are supplied per action; `escalate_scope` reads the existing session state without widening its authority. Completion, cancellation, Gateway disconnect, provider switching, local Stop, and command-host shutdown all close that exact execution, finalize or discard its recording resources, close its session, and shut down its runtime.
157+
3. Start `openclaw node run` from the interactive desktop session. The plugin repeats artifact verification and settles SDK availability before the node's first capability declaration. It lazily creates one configured SDK runtime and trusted lifecycle session for each provider execution. Window and desktop targets are supplied per action; `escalate_scope` reads the existing session state without widening its authority. Completion, cancellation, Gateway disconnect, provider switching, local Stop, and command-host shutdown all close that exact execution, finalize or discard its recording resources, close its session, and shut down its runtime.
154158

155159
4. Approve the pairing update that includes `computer.act`. Desktop `computer.act` is a built-in platform default, so plugin enablement plus that approval is the whole grant; no `gateway.nodes.commands.allow` entry is required. An operator who wants the command off can deny it:
156160

‎docs/plugins/sdk-overview.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ Computer Use providers use `registerComputerUseProvider(api, provider)` from
178178
`openclaw/plugin-sdk/computer-use`. It registers the shared
179179
`screen.snapshot`/`computer.act` node-host envelope once while the provider
180180
keeps its driver, frame, availability, and execution lifecycle local.
181+
Its optional `prepare(context)` hook settles native startup before the node's
182+
first capability declaration, without opening a Computer Use execution.
181183

182184
Plugin commands can set `agentPromptGuidance` when the agent needs a short,
183185
command-owned routing hint. Keep that text about the command itself; do not add

‎docs/plugins/sdk-runtime.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,15 @@ snapshots; OpenClaw owns all persistence and lifecycle coordination.
669669

670670
Plugins that expose node-hosted agent tools can set `agentTool.defaultPlatforms` for non-dangerous commands that should be allowlisted by default. Omit it when operators must opt in with `gateway.nodes.commands.allow`. Dangerous node-host commands should register a node-invoke policy with `api.registerNodeInvokePolicy(...)`; the policy runs in the Gateway after command allowlist checks and before the command is forwarded to the node, so direct `node.invoke` calls, node-hosted plugin tools, and higher-level plugin tools share the same enforcement path.
671671

672+
A node command may declare `prepare(context)` for asynchronous native startup.
673+
Node-host initialization awaits it before publishing the initial manifest or
674+
connecting to the Gateway; plugin registration itself stays synchronous.
675+
Shared preparation callbacks run once per node registry initialization, not
676+
per invocation or reconnect. Optional providers should retain a known
677+
unavailable state on expected preparation failure and let `isAvailable`
678+
withhold their commands; throwing aborts node startup. Use `watchAvailability`
679+
for later availability changes and `onDisconnect` for execution cleanup.
680+
672681
<Warning>
673682
The optional `scopes` field requests Gateway operator scopes for the invocation. OpenClaw honors it only for bundled plugins and trusted official plugin installations; requests from other plugins do not elevate the call. When `openDuplex` runs inside an authenticated Gateway request, its effective scopes never exceed that authenticated caller's actual scopes, even if a trusted plugin requests stronger scopes. Without an authenticated incoming client, existing trusted-plugin scope behavior applies. Use requested scopes only when a trusted plugin must invoke a node command with a stricter Gateway scope, such as `operator.admin`.
674683
</Warning>

‎extensions/codex/src/app-server/thread-lifecycle.test.ts‎

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,9 +1843,14 @@ describe("Codex app-server native code mode config", () => {
18431843
});
18441844
});
18451845

1846-
it.each([false, true])(
1847-
"keeps direct-only dynamic namespaces model-visible when code-mode-only=%s",
1848-
(nativeCodeModeOnlyEnabled) => {
1846+
it.each([
1847+
{ nativeCodeModeOnlyEnabled: false, configured: false },
1848+
{ nativeCodeModeOnlyEnabled: true, configured: false },
1849+
{ nativeCodeModeOnlyEnabled: false, configured: true },
1850+
{ nativeCodeModeOnlyEnabled: true, configured: true },
1851+
])(
1852+
"keeps direct-only dynamic namespaces model-visible when code-mode-only=$nativeCodeModeOnlyEnabled, configured=$configured",
1853+
({ nativeCodeModeOnlyEnabled, configured }) => {
18491854
const dynamicTools = [
18501855
{
18511856
type: "namespace" as const,
@@ -1854,9 +1859,16 @@ describe("Codex app-server native code mode config", () => {
18541859
tools: [],
18551860
},
18561861
];
1857-
const config = {
1858-
"code_mode.direct_only_tool_namespaces": ["vendor_direct"],
1859-
};
1862+
const config = configured
1863+
? {
1864+
"features.code_mode": {
1865+
enabled: true,
1866+
default_exec_yield_time_ms: 10000,
1867+
excluded_tool_namespaces: ["vendor_excluded"],
1868+
direct_only_tool_namespaces: ["vendor_direct"],
1869+
},
1870+
}
1871+
: undefined;
18601872
const startRequest = buildThreadStartParams(createAttemptParams({ provider: "openai" }), {
18611873
cwd: "/repo",
18621874
dynamicTools,
@@ -1875,10 +1887,20 @@ describe("Codex app-server native code mode config", () => {
18751887
});
18761888

18771889
for (const request of [startRequest, resumeRequest]) {
1878-
expect(request.config?.["code_mode.direct_only_tool_namespaces"]).toEqual([
1879-
"vendor_direct",
1880-
CODEX_OPENCLAW_DIRECT_DYNAMIC_TOOL_NAMESPACE,
1881-
]);
1890+
expect(request.config?.["features.code_mode"]).toEqual({
1891+
enabled: true,
1892+
...(configured
1893+
? {
1894+
default_exec_yield_time_ms: 10000,
1895+
excluded_tool_namespaces: ["vendor_excluded"],
1896+
}
1897+
: {}),
1898+
direct_only_tool_namespaces: [
1899+
...(configured ? ["vendor_direct"] : []),
1900+
CODEX_OPENCLAW_DIRECT_DYNAMIC_TOOL_NAMESPACE,
1901+
],
1902+
});
1903+
expect(request.config?.["code_mode.direct_only_tool_namespaces"]).toBeUndefined();
18821904
expect(request.config?.["features.code_mode_only"]).toBe(nativeCodeModeOnlyEnabled);
18831905
}
18841906
},

0 commit comments

Comments
 (0)