Skip to content

Commit b89c803

Browse files
authored
feat(crabbox): allow profiles without a default machine class (#131009)
* feat(crabbox): allow profiles without a default machine class Preserve class omission through provisioning, advertised machine choices, and Advanced editing while requiring an effective class for warm-image reuse. Keep explicit classes and placement overrides unchanged, reject stale rich editor saves, and document the remaining managed-session acceptance boundary. Fixes #130966. * fix(crabbox): preserve unsupported backend diagnostics Keep native fixed-ID backend rejection separate from obsolete-CLI flag errors. Classless unsupported profiles now report their actual backend incompatibility before enrollment, without an incorrect upgrade-only instruction. Extend the existing boundary regression, replace the misleading Daytona success fixture, and clarify native coordinator routing in the docs. Follow-up for #131009 (class-optional Crabbox profiles). * docs(crabbox): keep backend setup in Crabbox documentation Apply the maintainer-approved documentation correction for PR #131009. Keep OpenClaw's fixed-ID, setup, inspection, cleanup, and AWS instance-role requirements while directing backend configuration and tutorials to Crabbox. Require complete session-flow verification before relying on a new profile; standalone readiness does not establish OpenClaw worker compatibility. * fix(crabbox): resolve warm defaults after effective sizing Preserve cold classless omission while retaining warm defaults for known configured or placement classes without forwarded setup environment names. Explicit warm-image flags retain priority and warm provisioning requires a known effective class before commands. Share the pure policy across provision and teardown, using the successfully enrolled class after reconstruction without resolving setup environment values. Keep cold teardown from creating warm state and document the conditional default without restoring backend-specific tutorials. Reuse the existing lifecycle-timeout stop helper for normal teardown. * fix(crabbox): require confirmed worker lease cleanup Treat known non-runnable Crabbox states as loss of a usable lease, so core fences the worker and requests explicit teardown instead of assuming the machine is gone. Stop renewing those leases and share the classification with provisioning, including archived resources. Only normal zero-exit stop results prove provider-owned cleanup. Preserve failed release diagnostics even after an earlier missing-lease warning, and reconcile AWS profile rejections through stop when recognition is lost. Clarify the existing inspection contract without changing its SDK shape. Preserves the optional-class and warm-image policy in #131009.
1 parent e188dea commit b89c803

14 files changed

Lines changed: 912 additions & 551 deletions

‎docs/gateway/cloud-workers.md‎

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

‎docs/gateway/configuration-reference.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,15 +1001,15 @@ The bundled `crabbox` provider provisions a disposable machine through the local
10011001
}
10021002
```
10031003

1004-
- `settings.provider` (required): Crabbox backend passed through `--provider`; `aws` selects the direct AWS backend.
1005-
- `settings.class` (required): Crabbox machine class passed to `--class`.
1004+
- `settings.provider` (required): backend from the [Crabbox provider reference](https://crabbox.sh/providers/index.html), passed through `--provider`. Direct or coordinator-backed operation follows Crabbox's configuration.
1005+
- `settings.class`: optional Crabbox machine class passed to `--class`. Omission leaves selection to Crabbox unless the placement supplies `machineClass`; OpenClaw does not invent a default or hardware size. Explicit `null`, empty or whitespace strings, and nonstring values are invalid. Edit classless profiles through **Settings → Advanced**.
10061006
- `settings.ttl` and `settings.idleTimeout` (required): positive Go duration strings passed to `--ttl` and `--idle-timeout` as provider-side failsafes.
1007-
- `settings.warmImage`: captures a reusable machine image at each stop and starts later workers with the same profile from it; pair with `suspendAfter` so suspended sessions wake warm. Enabled by default, except for profiles that set `setupEnv`, whose forwarded host environment could leave setup-derived credentials in a shared image; set `true` or `false` to choose explicitly. Images incur provider snapshot storage charges and retain machine-level caches, including per-repository Git seeds, alongside whatever `setup` wrote outside the scrubbed worker state. Capture adds at most about three minutes to a stop on providers with slow native snapshots, ten on `machine0`, then degrades to cold-only provisioning.
1007+
- `settings.warmImage`: captures a reusable machine image at each stop and starts later workers with the same profile from it; pair with `suspendAfter` so suspended sessions wake warm. Enabled by default when a configured or placement class is known and `setupEnv` is empty or omitted. Without an effective class, omission stays cold. A nonempty `setupEnv` keeps the default cold because forwarded host environment could leave setup-derived credentials in a shared image. Explicit `true` opts in but requires a known effective class before provider commands; explicit `false` always stays cold. Placement overrides determine the effective class; reuse and capture remain tied to the successfully enrolled class, including after restart. Images incur provider snapshot storage charges and retain machine-level caches, including per-repository Git seeds, alongside whatever `setup` wrote outside the scrubbed worker state. Scrubbing has a three-minute timeout; checkpoint creation has a separate three-minute timeout, ten on `machine0`. Capture failure does not prevent teardown; later workers provision cold without a usable image.
10081008
- `settings.binary`: optional absolute Crabbox executable path. Without it, OpenClaw checks the sibling Crabbox checkout, then executable entries on `PATH`, and finally invokes `crabbox` so a missing CLI remains a visible provider error.
10091009

10101010
Unknown settings are rejected. Crabbox credentials and backend-specific account configuration remain owned by Crabbox; do not place them in `settings`. OpenClaw invokes only the local CLI and makes no provider network calls from this plugin. Provisioning passes one deterministic canonical lease ID through `--lease-id`, keeps `--slug` as display metadata only, and always passes `--keep=true`; OpenClaw owns the external lifecycle and destroys the lease with `crabbox stop --id <canonical-id>`. After an ambiguous result, Gateway reconciliation repeats the same fixed-ID operation. Crabbox must return the exactly attested lease or fail closed; OpenClaw never falls back to slug adoption or replacement allocation.
10111011

1012-
For coordinator-backed AWS, Crabbox's own `aws.sshCIDRs` should include the Gateway host's outbound IPv4 as a `/32`. Verify it with `crabbox config show --json` and `crabbox doctor --provider aws --json` before provisioning; do not place this provider-ingress setting in OpenClaw `settings`. See [Coordinator-backed Crabbox](/gateway/cloud-workers#coordinator-backed-crabbox).
1012+
Provider support and backend-specific setup belong to [Crabbox](https://crabbox.sh/providers/index.html). Configure credentials, coordinator access, networking, and snapshots there rather than duplicating them in OpenClaw settings. The installed backend must satisfy OpenClaw's [cloud-worker lifecycle requirements](/gateway/cloud-workers#crabbox-provider-support).
10131013

10141014
Crabbox setup uses an environment-owned one-use pairing credential and the configured public Gateway URL. The provider returns the exact authenticated node id; the Gateway then installs its current bundle and transfers the workspace through authenticated node routes. For Codex remote execution, Crabbox prepares the bundled Codex plugin and pinned managed binary in the node's private state, and the Gateway requires the explicitly allowed `codex.exec-server.stdio.v1` command plus critical allow-once approval for each attempt. No OpenClaw worker child or worker slot is used in that mode. OpenClaw does not persist Crabbox SSH endpoint, key, host-key, or fallback-port output.
10151015

‎extensions/crabbox/index.test.ts‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function inspectResult(leaseId: string): SpawnResult {
3636
host: "worker.example.test",
3737
id: leaseId,
3838
ready: true,
39+
providerMetadata: { instanceProfileAttached: false },
3940
sshHost: "worker.example.test",
4041
sshKey: "/mock/worker-key",
4142
sshPort: 2222,
@@ -69,6 +70,90 @@ describe("Crabbox plugin generation lifecycle", () => {
6970
vi.restoreAllMocks();
7071
});
7172

73+
it.each([
74+
{ backend: "aws", executionMode: "worker-turn" },
75+
{ backend: "hetzner", executionMode: "remote-exec" },
76+
] as const)(
77+
"supports a classless $backend profile through $executionMode lifecycle",
78+
async ({ backend, executionMode }) => {
79+
const runCommand = vi
80+
.spyOn(processRuntime, "runCommandWithTimeout")
81+
.mockImplementation(async (argv) => {
82+
if (argv[1] === "config") {
83+
return commandResult({ stdout: JSON.stringify({ aws: { instanceProfile: "" } }) });
84+
}
85+
if (argv[1] === "providers") {
86+
return commandResult({
87+
stdout: JSON.stringify([
88+
{ provider: backend, classCatalog: { disposition: "unmapped" } },
89+
]),
90+
});
91+
}
92+
return argv[1] === "inspect"
93+
? inspectResult(argv[argv.indexOf("--id") + 1]!)
94+
: commandResult();
95+
});
96+
const generation = registerCrabboxGeneration();
97+
const profile = {
98+
binary: PROFILE.binary,
99+
idleTimeout: PROFILE.idleTimeout,
100+
ttl: PROFILE.ttl,
101+
provider: backend,
102+
};
103+
try {
104+
expect(generation.provider.resolveProvisionTimeoutMs?.(profile)).toBe(67 * 60_000);
105+
expect(await generation.provider.listMachineOptions?.(profile)).toEqual([]);
106+
const waitForDeviceId = vi.fn(async () => "device-classless");
107+
const lease = await generation.provider.provision(profile, "classless-operation", {
108+
executionMode,
109+
beginNodeEnrollment: async () => ({
110+
...(executionMode === "worker-turn"
111+
? {
112+
mode: "connect" as const,
113+
setupCode: "fixture-setup-code",
114+
setupId: "fixture-setup-id",
115+
}
116+
: { mode: "resume" as const, deviceId: "device-classless" }),
117+
openclawVersion: "2026.8.1",
118+
packageSpecs: ["[email protected]"],
119+
displayName: "Classless worker",
120+
waitForDeviceId,
121+
}),
122+
});
123+
expect(lease.node).toEqual({ deviceId: "device-classless" });
124+
expect(waitForDeviceId).toHaveBeenCalledOnce();
125+
await expect(
126+
generation.provider.inspect({ leaseId: lease.leaseId, profile }),
127+
).resolves.toEqual({ status: "active" });
128+
await expect(
129+
generation.provider.destroy({ leaseId: lease.leaseId, profile }),
130+
).resolves.toBeUndefined();
131+
const calls = runCommand.mock.calls.map(([argv]) => argv);
132+
expect(calls.map((argv) => argv[1])).toEqual([
133+
"providers",
134+
...(backend === "aws" ? ["config"] : []),
135+
"warmup",
136+
"inspect",
137+
"run",
138+
"inspect",
139+
"inspect",
140+
"stop",
141+
]);
142+
expect(calls.flat()).not.toContain("--class");
143+
expect(calls.at(-1)).toEqual([
144+
PROFILE.binary,
145+
"stop",
146+
"--provider",
147+
backend,
148+
"--id",
149+
lease.leaseId,
150+
]);
151+
} finally {
152+
await stopGeneration(generation.services);
153+
}
154+
},
155+
);
156+
72157
it("registers cleanup that fences pending heartbeats and late starts", async () => {
73158
vi.useFakeTimers();
74159
const runCommand = vi

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

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,18 @@ export function provisionProfileError(result: SpawnResult): WorkerProviderError
5050
}
5151
const output = `${result.stderr}\n${result.stdout}`;
5252
if (
53-
/\bprovider=\S+\s+does not support fixed idempotent lease IDs\b/u.test(output) ||
5453
/(?:unknown|unrecognized) (?:flag|option)[^\r\n]*--lease-id/iu.test(output) ||
5554
/flag provided but not defined:\s*-lease-id/iu.test(output)
5655
) {
5756
return new WorkerProviderError(
5857
"Crabbox 0.41.1 or newer with fixed lease ID support is required",
5958
);
6059
}
60+
// A backend capability rejection is not evidence of an obsolete CLI.
6161
if (
62-
/\blease_id_conflict\b/u.test(output) &&
63-
!/\bretry after provider inventory converges\b/iu.test(output)
62+
/\bprovider=\S+\s+does not support fixed idempotent lease IDs\b/u.test(output) ||
63+
(/\blease_id_conflict\b/u.test(output) &&
64+
!/\bretry after provider inventory converges\b/iu.test(output))
6465
) {
6566
return permanentCrabboxCommandError("warmup", result);
6667
}
@@ -93,7 +94,8 @@ export function provisionProfileError(result: SpawnResult): WorkerProviderError
9394
return undefined;
9495
}
9596

96-
export function isAuthoritativeLeaseAbsence(result: SpawnResult, identifier: string): boolean {
97+
// Recognition failure does not prove resource absence; only the stop owner can confirm cleanup.
98+
export function isUnrecognizedLease(result: SpawnResult, identifier: string): boolean {
9799
const output = `${result.stderr}\n${result.stdout}`;
98100
if (
99101
!output.includes(identifier) ||
@@ -136,16 +138,5 @@ export async function stopCrabboxLease(params: {
136138
if (result.termination === "exit" && result.code === 0) {
137139
return;
138140
}
139-
const alreadyStopped =
140-
`${result.stderr}\n${result.stdout}`.includes(params.id) &&
141-
/\balready (?:destroyed|released|stopped|terminated)\b/iu.test(
142-
`${result.stderr}\n${result.stdout}`,
143-
);
144-
if (
145-
result.termination === "exit" &&
146-
(isAuthoritativeLeaseAbsence(result, params.id) || alreadyStopped)
147-
) {
148-
return;
149-
}
150141
throw crabboxCommandError("stop", result);
151142
}

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

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const DURATION_UNIT_NANOSECONDS: Readonly<Record<string, bigint>> = {
3939

4040
type CrabboxProfile = {
4141
binary?: string;
42-
class: string;
42+
class?: string;
4343
desktop?: boolean;
4444
heartbeatIntervalMs: number;
4545
heartbeatTimeoutMs: number;
@@ -48,7 +48,7 @@ type CrabboxProfile = {
4848
ttl: string;
4949
setup?: string;
5050
setupEnv?: string[];
51-
warmImage: boolean;
51+
warmImage?: boolean;
5252
};
5353

5454
const MAX_CRABBOX_MACHINE_CLASS_LENGTH = 128;
@@ -126,7 +126,7 @@ export function parseCrabboxProfile(profile: WorkerProfile): CrabboxProfile {
126126
if (!provider) {
127127
throw new WorkerProviderError("Crabbox profile provider must be a non-empty string");
128128
}
129-
if (!machineClass) {
129+
if (profile.class !== undefined && !machineClass) {
130130
throw new WorkerProviderError("Crabbox profile class must be a non-empty string");
131131
}
132132
const { duration: ttl } = requirePositiveDuration(profile.ttl, "ttl");
@@ -186,11 +186,6 @@ export function parseCrabboxProfile(profile: WorkerProfile): CrabboxProfile {
186186
if (warmImage !== undefined && typeof warmImage !== "boolean") {
187187
throw new WorkerProviderError("Crabbox profile warmImage must be a boolean");
188188
}
189-
// Capture defaults on so repeat sessions start warm. `setupEnv` is the declared channel
190-
// that forwards host environment values into setup, so those profiles can derive
191-
// credentials that outlive the scrub inside a shared provider image; they keep requiring
192-
// an explicit opt-in. An explicit warmImage always wins over this derived default.
193-
const warmImageDefault = !setupEnv?.length;
194189
return {
195190
binary,
196191
class: machineClass,
@@ -205,7 +200,7 @@ export function parseCrabboxProfile(profile: WorkerProfile): CrabboxProfile {
205200
setup,
206201
setupEnv,
207202
ttl,
208-
warmImage: warmImage ?? warmImageDefault,
203+
warmImage,
209204
};
210205
}
211206

@@ -226,10 +221,26 @@ function resolveCrabboxProfileSetupEnv(
226221
);
227222
}
228223

224+
// Resolve defaults only after sizing is known: placement and enrolled lease classes
225+
// must share the same policy without reading setup environment values during teardown.
226+
export function resolveCrabboxWarmImageProfile(
227+
profile: CrabboxProfile,
228+
machineClass = profile.class,
229+
) {
230+
return {
231+
...profile,
232+
class: machineClass,
233+
warmImage: profile.warmImage ?? (machineClass !== undefined && !profile.setupEnv?.length),
234+
};
235+
}
236+
237+
type CrabboxProvisionProfile = CrabboxProfile &
238+
({ warmImage: false } | { warmImage: true; class: string });
239+
229240
export function resolveCrabboxProvisionProfile(
230241
profile: WorkerProfile,
231242
requestedClassValue: unknown,
232-
): { profile: CrabboxProfile; forwardedEnv?: Record<string, string> } {
243+
): { profile: CrabboxProvisionProfile; forwardedEnv?: Record<string, string> } {
233244
const configured = parseCrabboxProfile(profile);
234245
const requestedClass = nonEmptyString(requestedClassValue);
235246
if (
@@ -240,12 +251,22 @@ export function resolveCrabboxProvisionProfile(
240251
"Crabbox machine class must be a non-empty string of at most 128 characters",
241252
);
242253
}
243-
const resolved = requestedClass ? { ...configured, class: requestedClass } : configured;
244-
return { profile: resolved, forwardedEnv: resolveCrabboxProfileSetupEnv(resolved.setupEnv) };
254+
const resolved = resolveCrabboxWarmImageProfile(configured, requestedClass ?? configured.class);
255+
const forwardedEnv = resolveCrabboxProfileSetupEnv(resolved.setupEnv);
256+
if (!resolved.warmImage) {
257+
return { profile: { ...resolved, warmImage: false }, forwardedEnv };
258+
}
259+
// Image identity is exact-class; resolve placement overrides before any provider command.
260+
if (!resolved.class) {
261+
throw new WorkerProviderError(
262+
"Crabbox warmImage requires a configured class or a placement machine class",
263+
);
264+
}
265+
return { profile: { ...resolved, class: resolved.class, warmImage: true }, forwardedEnv };
245266
}
246267

247268
export function listCrabboxMachineOptions(
248-
configuredClass: string,
269+
configuredClass: string | undefined,
249270
shapes: readonly CrabboxMachineShape[] = [],
250271
): readonly WorkerMachineOption[] {
251272
const seen = new Set<string>();
@@ -259,11 +280,13 @@ export function listCrabboxMachineOptions(
259280
if (candidates.length === 0) {
260281
return [];
261282
}
262-
const catalogLimit = candidates
263-
.slice(0, MAX_CRABBOX_MACHINE_OPTIONS)
264-
.some((shape) => shape.class === configuredClass)
265-
? MAX_CRABBOX_MACHINE_OPTIONS
266-
: MAX_CRABBOX_MACHINE_OPTIONS - 1;
283+
const catalogLimit =
284+
configuredClass === undefined ||
285+
candidates
286+
.slice(0, MAX_CRABBOX_MACHINE_OPTIONS)
287+
.some((shape) => shape.class === configuredClass)
288+
? MAX_CRABBOX_MACHINE_OPTIONS
289+
: MAX_CRABBOX_MACHINE_OPTIONS - 1;
267290
const options = candidates.slice(0, catalogLimit).map((shape) => {
268291
const id = shape.class;
269292
const result: {
@@ -284,7 +307,7 @@ export function listCrabboxMachineOptions(
284307
}
285308
return result;
286309
});
287-
if (!options.some((option) => option.id === configuredClass)) {
310+
if (configuredClass !== undefined && !options.some((option) => option.id === configuredClass)) {
288311
options.push({
289312
id: configuredClass,
290313
label: configuredClass,
@@ -306,8 +329,7 @@ export function buildCrabboxWarmupArgs(
306329
"--network",
307330
"public",
308331
"--tailscale=false",
309-
"--class",
310-
profile.class,
332+
...(profile.class ? ["--class", profile.class] : []),
311333
"--ttl",
312334
profile.ttl,
313335
"--idle-timeout",

0 commit comments

Comments
 (0)