Skip to content

Commit 78beccf

Browse files
authored
feat: add cloud worker profiles and machine selection (#124864)
* feat(workers): add per-dispatch machine classes * feat(ui): add cloud worker machine picker
1 parent 759e9ca commit 78beccf

68 files changed

Lines changed: 2422 additions & 69 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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7520,24 +7520,28 @@ public struct SessionsDispatchParams: Codable, Sendable {
75207520
public let agentid: String?
75217521
public let profileid: String?
75227522
public let deviceid: String?
7523+
public let machineclass: String?
75237524

75247525
public init(
75257526
key: String,
75267527
agentid: String? = nil,
75277528
profileid: String? = nil,
7528-
deviceid: String? = nil)
7529+
deviceid: String? = nil,
7530+
machineclass: String? = nil)
75297531
{
75307532
self.key = key
75317533
self.agentid = agentid
75327534
self.profileid = profileid
75337535
self.deviceid = deviceid
7536+
self.machineclass = machineclass
75347537
}
75357538

75367539
private enum CodingKeys: String, CodingKey {
75377540
case key
75387541
case agentid = "agentId"
75397542
case profileid = "profileId"
75407543
case deviceid = "deviceId"
7544+
case machineclass = "machineClass"
75417545
}
75427546
}
75437547

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"startupJsGzipBytes": 335452,
3-
"reason": "chat delivery failures surface globally: toast + session-display naming joins startup chat path",
2+
"startupJsGzipBytes": 337511,
3+
"reason": "cloud worker settings navigation and machine selection",
44
"updatedAt": "2026-08-16"
55
}

‎docs/gateway/cloud-workers.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ openclaw gateway call sessions.dispatch \
176176
--params '{"key":"agent:main:big-refactor","profileId":"aws"}'
177177
```
178178

179+
### Choose a machine class per session
180+
181+
A worker profile's `settings.class` remains its default. To choose a different size for one new placement, pass `machineClass` with `profileId`:
182+
183+
```bash
184+
openclaw gateway call sessions.dispatch \
185+
--timeout 1500000 \
186+
--params '{"key":"agent:main:big-refactor","profileId":"aws","machineClass":"large"}'
187+
```
188+
189+
The bundled Crabbox provider advertises `standard` (small repos and smoke checks), `fast` (general testing), `large` (broad test shards or heavy builds), and `beast` (high-core runs) through `environments.list`. You can also pass a provider-native server or instance type such as `c7a.24xlarge`; Crabbox treats any other non-empty class as that exact type. The selected value is fixed for that placement and reused by safe provisioning retries. `machineClass` is valid only with `profileId`, not `deviceId`.
190+
179191
`sessions.dispatch` closes local turn admission, drains active work, validates the eligible Git workspace inventory, provisions the lease, runs setup, bootstraps OpenClaw, syncs the workspace, and returns once the placement reaches `active` ownership. Inventory validation happens before provider allocation and reports an invalid request with an actionable size or entry limit when the workspace cannot be dispatched. Budget several minutes for the first dispatch; leases and installs are cached where the provider supports it. After that, talk to the session as usual. OpenClaw turns route to the worker process; Codex turns use the local harness with the active placement's remote-exec sandbox.
180192

181193
Completed cloud turns reconcile eligible, size-bounded workspace files back into the session's managed worktree before the turn claim is released. Worker-turn uses its terminal worker event to create the durable pending-result fence. Remote-exec waits for workspace quiescence and enters the same reconciliation flow after the local Codex attempt. Before applying the result, the Gateway stages complete authenticated base/current manifests plus each changed resulting blob as a Git ref under `refs/openclaw/worker-results/`; deletions are represented by the manifests and need no blob. This keeps the cloud delta recoverable even if the Gateway stops during the apply without duplicating unchanged baseline content. Workspace results use Git file semantics: regular files, executable bits, symlinks, additions, changes, and deletions are retained, while empty directories and other directory modes are not. The resulting file changes remain in the managed worktree for normal review and commit.

‎docs/plugins/manifest.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ Provider plugins that implement both `resolveUsageAuth` and `fetchUsageSnapshot`
742742

743743
Embedding providers must declare `contracts.embeddingProviders` for each adapter registered with `api.registerEmbeddingProvider(...)`. The same generic contract serves reusable vector generation and memory search. The retired `contracts.memoryEmbeddingProviders` key is no longer accepted.
744744

745-
Worker providers must declare each `api.registerWorkerProvider(...)` id in `contracts.workerProviders`. Core persists durable intent before calling `provision`; providers validate their settings before external allocation, and repeated calls with the same operation id must adopt the same lease. Providers whose bounded provisioning exceeds core's five-minute default may implement `resolveProvisionTimeoutMs(profile)` and include acquisition, provider-owned setup, and cleanup in the returned positive millisecond budget. Core also persists that validated settings snapshot and passes it with `leaseId` to `inspect({ leaseId, profile })` and `destroy({ leaseId, profile })`, including after the named profile is changed or removed. Destruction is idempotent, inspection returns the closed `active` / `destroyed` / `unknown` status union, and SSH private-key material is referenced only through `SecretRef`. Provisioned SSH endpoints must also include a public `hostKey` from trusted provisioning output as exactly `algorithm base64`, without a hostname or comment, so core can pin the host before connecting. They may include up to 10 ordered, unique `fallbackPorts`, excluding the primary `port`; core persists those candidates and rotates among them only 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. Optional desktop metadata may advertise up to eight unique closed apps: `browser` with an absolute `executablePath` and a CDP port from 1 through 65535, or `terminal` with an absolute `executablePath`. Core rejects unknown app ids and fields and persists the validated metadata with the existing desktop record. Providers that mint dynamic identity refs may implement authoritative `resolveSshIdentity({ leaseId, profile, keyRef })`; providers without it use core's generic secret resolver. An authoritative `unknown` orphans an active local record; after a persisted destroy request it confirms teardown.
745+
Worker providers must declare each `api.registerWorkerProvider(...)` id in `contracts.workerProviders`. Core persists durable intent before calling `provision`; providers validate their settings and any optional per-dispatch `machineClass` before external allocation, and repeated calls with the same operation id must adopt the same lease. Providers may implement `listMachineOptions(profile)` to expose process-stable picker metadata; omit it when machine selection is not meaningful. Machine options contain only `id`, `label`, optional `description`, and optional `default`. Providers whose bounded provisioning exceeds core's five-minute default may implement `resolveProvisionTimeoutMs(profile)` and include acquisition, provider-owned setup, and cleanup in the returned positive millisecond budget. Core also persists that validated settings snapshot and passes it with `leaseId` to `inspect({ leaseId, profile })` and `destroy({ leaseId, profile })`, including after the named profile is changed or removed. Destruction is idempotent, inspection returns the closed `active` / `destroyed` / `unknown` status union, and SSH private-key material is referenced only through `SecretRef`. Provisioned SSH endpoints must also include a public `hostKey` from trusted provisioning output as exactly `algorithm base64`, without a hostname or comment, so core can pin the host before connecting. They may include up to 10 ordered, unique `fallbackPorts`, excluding the primary `port`; core persists those candidates and rotates among them only 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. Optional desktop metadata may advertise up to eight unique closed apps: `browser` with an absolute `executablePath` and a CDP port from 1 through 65535, or `terminal` with an absolute `executablePath`. Core rejects unknown app ids and fields and persists the validated metadata with the existing desktop record. Providers that mint dynamic identity refs may implement authoritative `resolveSshIdentity({ leaseId, profile, keyRef })`; providers without it use core's generic secret resolver. An authoritative `unknown` orphans an active local record; after a persisted destroy request it confirms teardown.
746746

747747
`contracts.gatewayMethodDispatch` currently accepts `"authenticated-request"`. It is an API hygiene gate for native plugin HTTP routes that intentionally dispatch Gateway control-plane methods in-process, not a sandbox against malicious native plugins. Use it only for tightly reviewed bundled/operator surfaces that already require Gateway HTTP auth. An entitled route remains reachable while Gateway root-work admission is closed only when it also declares `auth: "gateway"` and the route-specific `gatewayRuntimeScopeSurface: "trusted-operator"`; ordinary sibling routes from the same plugin remain behind the admission boundary. This keeps suspension status and resume reachable without granting the whole plugin an admission bypass. Keep parsing and response shaping bounded outside dispatch; substantive or mutating work must go through Gateway method dispatch, which owns admission and scope enforcement.
748748

‎docs/plugins/sdk-overview.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ persists the start or invokes the provider. Provider aliases are lookup names
131131
only and must not be used for this declaration.
132132

133133
Worker providers must also declare their id in `contracts.workerProviders`.
134-
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. 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.
134+
Core persists durable intent before `provision(profile, operationId, options?)`. Providers validate settings and any optional `options.machineClass` before external allocation and throw `WorkerProviderError` for permanent profile rejection. `provision` must adopt the same lease when the operation id repeats. Providers may expose process-stable picker metadata with `listMachineOptions(profile)`; omit the hook when the profile has no meaningful machine choice. Machine options contain only `id`, `label`, optional `description`, and optional `default` because the host has no authoritative cross-provider CPU, memory, or price source. 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
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.
136136
`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 Gateway reads the password file over the provider's SSH endpoint when needed and never persists the password. `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.
137137
Providers with renewable leases can also implement `renew(leaseId)`.

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ type CrabboxProfile = {
4141
setup?: string;
4242
};
4343

44+
const CRABBOX_MACHINE_OPTIONS = [
45+
{ id: "standard", label: "Standard", description: "Cheap smoke checks and small repos" },
46+
{ id: "fast", label: "Fast", description: "General maintainer testing" },
47+
{ id: "large", label: "Large", description: "Broad test shards or heavy builds" },
48+
{ id: "beast", label: "Beast", description: "High-core changed-test runs" },
49+
] as const;
50+
4451
type IsExecutable = (candidate: string) => boolean;
4552

4653
function requirePositiveDuration(value: unknown, key: string): string {
@@ -139,6 +146,32 @@ export function parseCrabboxProfile(profile: WorkerProfile): CrabboxProfile {
139146
};
140147
}
141148

149+
export function listCrabboxMachineOptions(profile: WorkerProfile) {
150+
const configuredClass = parseCrabboxProfile(profile).class;
151+
const options = CRABBOX_MACHINE_OPTIONS.map((option) =>
152+
option.id === configuredClass
153+
? {
154+
id: option.id,
155+
label: option.label,
156+
description: option.description,
157+
default: true,
158+
}
159+
: option,
160+
);
161+
if (options.some((option) => option.id === configuredClass)) {
162+
return options;
163+
}
164+
return [
165+
...options,
166+
{
167+
id: configuredClass,
168+
label: configuredClass,
169+
description: "Configured instance type",
170+
default: true,
171+
},
172+
];
173+
}
174+
142175
export function buildCrabboxWarmupArgs(
143176
profile: CrabboxProfile,
144177
leaseId: string,

‎extensions/crabbox/src/crabbox-worker-provider.test.ts‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,34 @@ function hasLoneSurrogate(value: string): boolean {
9595
}
9696

9797
describe("Crabbox worker provider", () => {
98+
it("advertises named machine classes and preserves a configured literal default", () => {
99+
const provider = createCrabboxWorkerProvider();
100+
101+
expect(provider.listMachineOptions?.(PROFILE)).toEqual([
102+
{
103+
id: "standard",
104+
label: "Standard",
105+
description: "Cheap smoke checks and small repos",
106+
default: true,
107+
},
108+
{ id: "fast", label: "Fast", description: "General maintainer testing" },
109+
{ id: "large", label: "Large", description: "Broad test shards or heavy builds" },
110+
{ id: "beast", label: "Beast", description: "High-core changed-test runs" },
111+
]);
112+
expect(provider.listMachineOptions?.({ ...PROFILE, class: "c7a.24xlarge" })).toEqual([
113+
{ id: "standard", label: "Standard", description: "Cheap smoke checks and small repos" },
114+
{ id: "fast", label: "Fast", description: "General maintainer testing" },
115+
{ id: "large", label: "Large", description: "Broad test shards or heavy builds" },
116+
{ id: "beast", label: "Beast", description: "High-core changed-test runs" },
117+
{
118+
id: "c7a.24xlarge",
119+
label: "c7a.24xlarge",
120+
description: "Configured instance type",
121+
default: true,
122+
},
123+
]);
124+
});
125+
98126
it("returns a pinned endpoint when inspect exposes provisioned host-key material", async () => {
99127
let warmed = false;
100128
const provider = providerWithRunner(async (argv) => {
@@ -1014,6 +1042,37 @@ describe("Crabbox worker provider", () => {
10141042
]);
10151043
});
10161044

1045+
it("overrides the configured class for one provision operation", async () => {
1046+
const calls: string[][] = [];
1047+
const provider = providerWithRunner(async (argv) => {
1048+
calls.push(argv);
1049+
return argv[1] === "warmup"
1050+
? commandResult()
1051+
: commandResult({ stdout: inspectJson({ sshHostKey: HOST_KEY }) });
1052+
});
1053+
1054+
await provider.provision(PROFILE, OPERATION_ID, { machineClass: "c7a.24xlarge" });
1055+
1056+
const warmup = calls.find((argv) => argv[1] === "warmup");
1057+
expect(warmup?.slice(warmup.indexOf("--class"), warmup.indexOf("--class") + 2)).toEqual([
1058+
"--class",
1059+
"c7a.24xlarge",
1060+
]);
1061+
});
1062+
1063+
it.each([" ", "x".repeat(129)])(
1064+
"rejects an invalid per-operation machine class before allocation",
1065+
async (machineClass) => {
1066+
const runCommand = vi.fn(async () => commandResult());
1067+
const provider = providerWithRunner(runCommand);
1068+
1069+
await expect(
1070+
provider.provision(PROFILE, OPERATION_ID, { machineClass }),
1071+
).rejects.toMatchObject({ code: "invalid_profile" });
1072+
expect(runCommand).not.toHaveBeenCalled();
1073+
},
1074+
);
1075+
10171076
it("replays a committed timed-out warmup through a fresh provider instance", async () => {
10181077
const calls: string[][] = [];
10191078
const live = new Set<string>();

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { parseInspectJson, type ParsedInspect } from "./crabbox-worker-inspect.j
2626
import {
2727
buildCrabboxWarmupArgs,
2828
identityRefId,
29+
listCrabboxMachineOptions,
2930
nonEmptyString,
3031
operationLeaseId,
3132
operationSlug,
@@ -496,11 +497,23 @@ export function createCrabboxWorkerProvider(
496497

497498
return {
498499
id: CRABBOX_WORKER_PROVIDER_ID,
500+
listMachineOptions: listCrabboxMachineOptions,
499501
resolveProvisionTimeoutMs(profile) {
500502
return resolveCrabboxProvisionCallTimeoutMs(parseCrabboxProfile(profile));
501503
},
502-
async provision(profile: WorkerProfile, operationId: string): Promise<WorkerLease> {
503-
const parsed = parseCrabboxProfile(profile);
504+
async provision(
505+
profile: WorkerProfile,
506+
operationId: string,
507+
options: Parameters<WorkerProvider["provision"]>[2],
508+
): Promise<WorkerLease> {
509+
const configured = parseCrabboxProfile(profile);
510+
const requestedClass = nonEmptyString(options?.machineClass);
511+
if (options?.machineClass !== undefined && (!requestedClass || requestedClass.length > 128)) {
512+
throw new WorkerProviderError(
513+
"Crabbox machine class must be a non-empty string of at most 128 characters",
514+
);
515+
}
516+
const parsed = requestedClass ? { ...configured, class: requestedClass } : configured;
504517
const warmupTimeoutMs = parsed.desktop
505518
? CRABBOX_DESKTOP_WARMUP_TIMEOUT_MS
506519
: CRABBOX_WARMUP_TIMEOUT_MS;

0 commit comments

Comments
 (0)