Skip to content

Commit f76b7ff

Browse files
authored
fix: cloud sessions fail when source builds and worker packages differ (#133037)
* fix: automatically align cloud nodes with the running build * test: stop cloud bootstrap fixtures gracefully * test: preserve updater fixture build metadata after postbuild
1 parent b111319 commit f76b7ff

56 files changed

Lines changed: 3541 additions & 833 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-workers.md‎

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

‎docs/plugins/sdk-overview.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ Worker providers must also declare their id in `contracts.workerProviders`.
134134
Core persists durable intent before `provision(profile, operationId, options?)`. Providers validate settings and any optional `options.machineClass` and `options.executionMode` before external allocation and throw `WorkerProviderError` for permanent profile rejection. `provision` must adopt the same lease for the same operation id and selected execution mode; a retry cannot silently change modes. If provider-owned setup fails after allocation and cleanup is indeterminate, throw `WorkerProviderError.cleanupIndeterminate(leaseId, provisionError, cleanupError)` so core persists the known lease and reconciles teardown instead of replaying provision. Providers may expose process-stable picker metadata with asynchronous `listMachineOptions(profile)`; omit the hook when the profile has no meaningful machine choice. Machine options contain only `id`, `label`, optional positive-integer `cpu` and `memoryGb`, and optional `default`. Session-placement providers declare one or both current `supportedExecutionModes` values in deterministic canonical order: `["worker-turn"]`, `["remote-exec"]`, or `["worker-turn", "remote-exec"]`. Empty lists, duplicate values, unknown modes, and noncanonical order are rejected. `worker-turn` requires a node lease; `remote-exec` accepts either a node lease or an existing SSH lease. Omission advertises no placement modes while preserving direct environment lifecycle calls. Direct environment creation without a session supplies no execution mode, so providers retain their intentional default setup; the bundled Crabbox provider defaults to `worker-turn`. Providers whose provisioning can legitimately exceed core's five-minute default may return a positive millisecond budget from `resolveProvisionTimeoutMs(profile)`; include acquisition, provider-owned setup, and cleanup in that bound.
135135
Every worker provider must implement `resolveAllocation(profile, operationId)`, returning `{ leaseId: string; sharedHost: boolean }` for the exact operation. Core passes the frozen settings snapshot, even after the named profile changes or is removed. The handle identifies the cleanup target; it does not prove a machine was created or a transport is ready. Resolution must not allocate, start, renew, run setup, read setup secrets, enroll nodes, or wait for availability. Throw if the identity cannot be resolved safely. When destruction is requested before a provision result is recorded, core persists this handle with the existing teardown state and calls `destroy`, without replaying `provision`. `destroy` still must prove release or authoritative absence. Both calls remain serialized behind any earlier provider operation until it actually settles, including after a caller-visible timeout.
136136

137+
Providers that enroll cloud nodes set `requiresNodeEnrollment: true` and call `options.beginNodeEnrollment()` after allocating the machine. The returned `WorkerNodeEnrollment` supplies `displayName`, `openclawVersion`, an optional shutdown `signal`, `waitForDeviceId()`, and either `mode: "connect"` with `setupCode` and `setupId`, or `mode: "resume"` with the bound `deviceId`. Its required `nodeBootstrap` contains the Gateway-prepared runtime archive's `url`, secret bearer `token`, `sha256`, `bytes`, `openclawVersion`, `enabledPluginIds`, and optional `tlsFingerprint`. Download that exact archive, verify its size and digest, install its target-platform dependencies, and enable the listed plugins in the node's isolated state before connecting. Do not substitute a global or registry package based only on a matching version. Keep download and enrollment credentials out of command arguments, logs, npm, and the launched node's environment; cancel work when `signal` aborts. Download authority belongs to the live enrollment attempt, not the URL or digest alone. After connection, return the device identity from `waitForDeviceId()` in the node lease. See [Bundle installation](/gateway/cloud-workers#bundle-installation) for source builds, artifact reuse, and proxy requirements. Bootstrap installation does not authorize node commands or replace invocation policy.
138+
137139
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`, `dormant`, `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.
138140
`WorkerLease.desktop` is optional and has the shape `{ protocol: "rfb"; port: number; passwordFilePath?: string; apps?: WorkerDesktopApp[] }`; `passwordFilePath`, when present, must be absolute. Providers report this warm-time capability from `provision`; it cannot be retrofitted onto a live lease. The owning SSH or node carrier reads the password on the worker when needed and never persists it in the Gateway store. `WorkerDesktopApp` is a closed union: `{ id: "browser"; executablePath: string; cdpPort: number }` or `{ id: "terminal"; executablePath: string }`. App ids must be unique, executable paths must be absolute, browser CDP ports must be integers from 1 through 65535, and the list accepts at most eight entries. Core rejects unknown ids and fields.
139141
Providers with renewable leases can also implement `renew(leaseId)`.

‎extensions/crabbox/index.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as processRuntime from "openclaw/plugin-sdk/process-runtime";
1111
import type { SpawnResult } from "openclaw/plugin-sdk/process-runtime";
1212
import { afterEach, describe, expect, it, vi } from "vitest";
1313
import plugin from "./index.js";
14+
import { createNodeBootstrapFixture } from "./src/crabbox-worker-node-enrollment.test-support.js";
1415

1516
const PROFILE = {
1617
binary: "/mock/crabbox",
@@ -144,7 +145,7 @@ describe("Crabbox plugin generation lifecycle", () => {
144145
}
145146
: { mode: "resume" as const, deviceId: "device-classless" }),
146147
openclawVersion: "2026.8.1",
147-
packageSpecs: ["[email protected]"],
148+
nodeBootstrap: createNodeBootstrapFixture(),
148149
displayName: "Classless worker",
149150
waitForDeviceId,
150151
}),

‎extensions/crabbox/src/crabbox-worker-node-enrollment-diagnostics.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export async function collectCrabboxNodeEnrollmentEvidence(params: {
2222
binary: params.binary,
2323
input: [
2424
`state_dir="$HOME/.openclaw/cloud-workers/${params.id}"`,
25-
'printf "package-spec="',
26-
'if [ -s "$state_dir/package-spec" ]; then head -c 256 "$state_dir/package-spec"; else printf absent; fi',
25+
'printf "node-runtime="',
26+
'if [ -L "$state_dir/runtime" ]; then readlink "$state_dir/runtime"; else printf absent; fi',
2727
'printf " node-pid="',
2828
'if [ -s "$state_dir/node.pid" ] && kill -0 "$(head -c 32 "$state_dir/node.pid")" 2>/dev/null; then printf alive; else printf dead-or-absent; fi',
2929
'printf " node.log tail: "',
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { CrabboxWorkerNodeEnrollment } from "./crabbox-worker-node-enrollment.js";
2+
3+
export function createNodeBootstrapFixture(
4+
overrides: Partial<CrabboxWorkerNodeEnrollment["nodeBootstrap"]> = {},
5+
): CrabboxWorkerNodeEnrollment["nodeBootstrap"] {
6+
return {
7+
url: "https://gateway.example.test/__openclaw__/node-bootstrap/v1/artifact",
8+
token: "synthetic-bootstrap-token",
9+
sha256: "a".repeat(64),
10+
bytes: 100,
11+
openclawVersion: "2026.8.1",
12+
enabledPluginIds: ["demo"],
13+
...overrides,
14+
};
15+
}

0 commit comments

Comments
 (0)