Skip to content

Commit 9b1071a

Browse files
committed
fix(crabbox): keep the setup failure reason and name its phase
A Crabbox cloud-worker setup failure could report none of the reason it failed. crabboxCommandDetail kept the first ~254 and last ~253 characters and dropped the middle, but Crabbox always prints a fixed ~250-character run-context banner first, so head preservation spent half the budget on boilerplate. In a live machine0 failure the actionable line sat at collapsed index 2570 and was deleted; the operator saw a banner and a Node stack tail that read like a workspace-lock problem. Keep the tail instead: a failing command's diagnosis is last, and the capture layer in src/process/exec-output.ts already retains each stream's suffix. Join [stdout, stderr] so stderr occupies the retained window rather than being pushed out by a chatty stdout. The 512-character budget is unchanged and stays inside core's 1024-unit bound. Profile, desktop, and node enrollment setup also all failed as "Crabbox setup failed", so the message never said which phase broke. Each now carries its own label, matching the shared SSH bootstrap in src/gateway/worker-environments/bootstrap.ts. Net -4 production lines.
1 parent 99a2434 commit 9b1071a

4 files changed

Lines changed: 84 additions & 28 deletions

File tree

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
import { redactSensitiveText } from "openclaw/plugin-sdk/logging-core";
22
import { WorkerProviderError } from "openclaw/plugin-sdk/plugin-entry";
33
import type { SpawnResult } from "openclaw/plugin-sdk/process-runtime";
4-
import { sliceUtf16Safe, truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
4+
import { sliceUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
55

66
const MAX_COMMAND_DETAIL_CHARS = 512;
77

88
function crabboxCommandDetail(result: SpawnResult): string {
9-
const raw = [result.stderr, result.stdout].filter(Boolean).join("\n").trim();
9+
const raw = [result.stdout, result.stderr].filter(Boolean).join("\n").trim();
1010
if (!raw) {
1111
return "";
1212
}
1313
const compressed = redactSensitiveText(raw).replace(/\s+/gu, " ");
14-
const omitted = " ... ";
15-
const remaining = MAX_COMMAND_DETAIL_CHARS - omitted.length;
16-
const redacted =
17-
compressed.length <= MAX_COMMAND_DETAIL_CHARS
18-
? compressed
19-
: `${truncateUtf16Safe(compressed, Math.ceil(remaining / 2))}${omitted}${sliceUtf16Safe(
20-
compressed,
21-
-Math.floor(remaining / 2),
22-
)}`;
23-
return redacted ? `: ${redacted}` : "";
14+
// Failure diagnoses come last; Crabbox's fixed banner is leading boilerplate.
15+
// Keep stderr last, matching the per-stream suffix capture in src/process/exec-output.ts.
16+
const tailMarker = "... ";
17+
return compressed.length <= MAX_COMMAND_DETAIL_CHARS
18+
? `: ${compressed}`
19+
: `: ${tailMarker}${sliceUtf16Safe(compressed, tailMarker.length - MAX_COMMAND_DETAIL_CHARS)}`;
2420
}
2521

2622
export function crabboxCommandError(action: string, result: SpawnResult): Error {

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

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -956,17 +956,17 @@ describe("Crabbox worker provider", () => {
956956
{
957957
name: "fails",
958958
result: commandResult({ code: 7, stderr: "apt exploded" }),
959-
message: "Crabbox setup failed with exit code 7",
959+
message: "Crabbox profile setup failed with exit code 7",
960960
},
961961
{
962962
name: "times out",
963963
result: commandResult({ code: null, killed: true, termination: "timeout" }),
964-
message: "Crabbox setup did not exit normally (timeout)",
964+
message: "Crabbox profile setup did not exit normally (timeout)",
965965
},
966966
{
967967
name: "cannot start",
968968
result: undefined,
969-
message: "Crabbox setup could not start",
969+
message: "Crabbox profile setup could not start",
970970
},
971971
])(
972972
"stops the lease and removes its private env profile when setup $name",
@@ -1024,6 +1024,64 @@ describe("Crabbox worker provider", () => {
10241024
},
10251025
);
10261026

1027+
it.each([
1028+
{ phase: "profile setup", setupAttempt: 1 },
1029+
{ phase: "desktop setup", setupAttempt: 2 },
1030+
{ phase: "node enrollment setup", setupAttempt: 3 },
1031+
])("identifies the failed $phase phase", async ({ phase, setupAttempt }) => {
1032+
let attempts = 0;
1033+
const provider = providerWithRunner(async (argv) => {
1034+
if (argv[1] === "inspect") {
1035+
return commandResult({ stdout: inspectJson() });
1036+
}
1037+
if (argv[1] === "run" && ++attempts === setupAttempt) {
1038+
return commandResult({ code: 7, stderr: "setup command rejected" });
1039+
}
1040+
return commandResult();
1041+
});
1042+
1043+
await expect(
1044+
provider.provision({ ...PROFILE, setup: "install-node", desktop: true }, OPERATION_ID),
1045+
).rejects.toMatchObject({
1046+
code: "invalid_profile",
1047+
message: `Crabbox ${phase} failed with exit code 7: setup command rejected`,
1048+
});
1049+
});
1050+
1051+
it("preserves the node enrollment diagnosis after the Crabbox banner and setup noise", async () => {
1052+
const diagnosis =
1053+
"Error: Codex remote-exec requires the exact official @openclaw/[email protected] plugin to be installed by cloudWorkers profile setup";
1054+
const stderr = [
1055+
`workspace owner acquired wait=218ms recovered=false run context: run=${"a".repeat(32)} lease=${LEASE_ID} slug=openclaw-${"b".repeat(32)} provider=machine0 [email protected]:2222 workspace=/workspace/openclaw`,
1056+
"x".repeat(2_000),
1057+
diagnosis,
1058+
" at prepareCodex ([eval]:20:11)",
1059+
" at runScriptInThisContext (node:internal/vm:209:10)",
1060+
" at node:internal/process/execution:446:12",
1061+
" at [eval]-wrapper:6:24",
1062+
" at runScriptInContext (node:internal/process/execution:444:60)",
1063+
" at evalFunction (node:internal/process/execution:279:30)",
1064+
"Node.js v24.15.0",
1065+
].join("\n");
1066+
const provider = providerWithRunner(async (argv) => {
1067+
if (argv[1] === "status") {
1068+
return commandResult({ stdout: inspectJson() });
1069+
}
1070+
return argv[1] === "run"
1071+
? commandResult({ code: 1, stderr, stdout: "setup progress ".repeat(200) })
1072+
: commandResult();
1073+
});
1074+
1075+
await expect(
1076+
provider.provision({ ...PROFILE, provider: "machine0" }, OPERATION_ID, {
1077+
executionMode: "remote-exec",
1078+
}),
1079+
).rejects.toMatchObject({
1080+
code: "invalid_profile",
1081+
message: expect.stringContaining(diagnosis),
1082+
});
1083+
});
1084+
10271085
it("preserves the allocated lease and both failures when setup cleanup times out", async () => {
10281086
let releaseCommitted = false;
10291087
const provider = providerWithRunner(async (argv) => {
@@ -2854,8 +2912,8 @@ describe("Crabbox worker provider", () => {
28542912
code,
28552913
termination,
28562914
killed: termination !== "exit",
2857-
stderr: `provider warning ${secret} ${"provider progress ".repeat(90)}${terminalStderr}`,
2858-
stdout: terminalStdout,
2915+
stderr: `provider warning ${secret}\n${terminalStderr}`,
2916+
stdout: `${"provider progress ".repeat(90)}\n${terminalStdout}`,
28592917
}),
28602918
);
28612919
const operation =
@@ -2870,10 +2928,11 @@ describe("Crabbox worker provider", () => {
28702928
action === "warmup"
28712929
? "Crabbox warmup failed with exit code 5: "
28722930
: "Crabbox inspect did not exit normally (timeout): ";
2873-
expect(message).toContain("provider warning");
2931+
expect(message.startsWith(`${failurePrefix}... `)).toBe(true);
28742932
expect(message).toContain(terminalStderr);
28752933
expect(message).toContain(terminalStdout);
28762934
expect(message).not.toContain(secret);
2935+
expect(message).not.toMatch(/\s{2,}/u);
28772936
expect(message.length).toBeLessThanOrEqual(failurePrefix.length + 512);
28782937
expect(hasLoneSurrogate(message)).toBe(false);
28792938
},
@@ -2882,10 +2941,11 @@ describe("Crabbox worker provider", () => {
28822941
it.each(["stderr", "stdout"] as const)(
28832942
"preserves UTF-16 boundaries and terminal detail from %s",
28842943
async (stream) => {
2944+
const terminalDetail = "😀 terminal failure";
28852945
const provider = providerWithRunner(async () =>
28862946
commandResult({
28872947
code: 2,
2888-
[stream]: `${"x".repeat(253)}😀${"y".repeat(300)}😀 terminal failure`,
2948+
[stream]: `${"x".repeat(600)}😀${"y".repeat(507 - terminalDetail.length)}${terminalDetail}`,
28892949
}),
28902950
);
28912951

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ async function waitForProvisionReady(
305305
// otherwise the caller cannot release a box it never learned about.
306306
async function runProvisionSetupAndWaitReady(
307307
params: ProvisionInspectContext & {
308+
phase: string;
308309
setup: string;
309310
timeoutMs?: number;
310311
forwardedEnv?: Record<string, string>;
@@ -316,7 +317,7 @@ async function runProvisionSetupAndWaitReady(
316317
params.forwardedEnv,
317318
(names, profilePath, childEnv) =>
318319
runCrabboxCommand({
319-
action: "setup",
320+
action: params.phase,
320321
args: leaseRunArgs({ ...params, id: params.inspect.id }, names, profilePath),
321322
binary: params.binary,
322323
env: childEnv,
@@ -329,7 +330,7 @@ async function runProvisionSetupAndWaitReady(
329330
}),
330331
);
331332
if (result.termination !== "exit" || result.code !== 0) {
332-
throw permanentCrabboxCommandError("setup", result);
333+
throw permanentCrabboxCommandError(params.phase, result);
333334
}
334335
} catch (error) {
335336
return await failProvisionAfterCleanup({ ...params, id: params.inspect.id }, error);
@@ -588,22 +589,18 @@ export function createCrabboxWorkerProvider(
588589
} catch (error) {
589590
// Transport failure after warmup is indeterminate; preserve the lease for durable replay.
590591
if (error instanceof WorkerProviderError) {
591-
return await failProvisionAfterCleanup(
592-
{ binary, id: leaseId, provider: parsed.provider, runCommand },
593-
error,
594-
);
592+
return await failProvisionAfterCleanup({ ...context, id: leaseId, runCommand }, error);
595593
}
596594
throw error;
597595
}
598596
if (inspected.status === "unknown") {
599597
throw new Error("Crabbox warmup lease was not found during inspection");
600598
}
601599
const inspectedParams = {
602-
binary,
600+
...context,
603601
deadline,
604602
inspect: inspected.inspect,
605603
profile: parsed,
606-
provider: parsed.provider,
607604
runCommand,
608605
};
609606
if (isUnusableProvisionState(inspected.inspect.state)) {
@@ -617,6 +614,7 @@ export function createCrabboxWorkerProvider(
617614
if (parsed.setup) {
618615
inspectedParams.inspect = await runProvisionSetupAndWaitReady({
619616
...inspectedParams,
617+
phase: "profile setup",
620618
setup: parsed.setup,
621619
forwardedEnv,
622620
sleep,
@@ -625,6 +623,7 @@ export function createCrabboxWorkerProvider(
625623
if (parsed.desktop) {
626624
inspectedParams.inspect = await runProvisionSetupAndWaitReady({
627625
...inspectedParams,
626+
phase: "desktop setup",
628627
setup: createCrabboxWorkerDesktopSetup(leaseId, wallpaperBase64),
629628
sleep,
630629
});
@@ -652,6 +651,7 @@ export function createCrabboxWorkerProvider(
652651
});
653652
inspectedParams.inspect = await runProvisionSetupAndWaitReady({
654653
...inspectedParams,
654+
phase: "node enrollment setup",
655655
setup: nodeEnrollmentSetup.command,
656656
timeoutMs: CRABBOX_NODE_ENROLLMENT_TIMEOUT_MS,
657657
...(nodeEnrollmentSetup.forwardedEnv

‎extensions/crabbox/src/crabbox-worker-warm-image.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ describe("Crabbox profile warm images", () => {
339339

340340
await expect(
341341
provisionWarmProfile(provider, { ...PROFILE, setup: "install-node" }),
342-
).rejects.toThrow("Crabbox setup failed");
342+
).rejects.toThrow("Crabbox profile setup failed");
343343

344344
expect(calls.some(({ argv }) => argv[1] === "checkpoint")).toBe(false);
345345
expect(calls.at(-1)?.argv[1]).toBe("stop");

0 commit comments

Comments
 (0)