Skip to content

Commit b07c6b2

Browse files
authored
fix(computer-use): macOS live-proof rig deadlocks on operator device approval (#124536)
* fix(computer-use): unblock the macOS live-rig proof flow The rig ran its operator CLI and its proof runner from one state dir, so both shared one device identity. A paired operator device is pinned to the scopes of its first connect, and `nodes list` connects first for `node.pair.list` (operator.pairing); the proof runner then needs operator.write, which is a scope upgrade the gateway never approves silently and which no rig client can approve for itself. The proof runner is a GATEWAY_CLIENT/BACKEND client, so on a loopback auth-none gateway it is admitted unpaired with the scopes it asks for: giving the CLI its own `cli-state` identity is enough, and `agent-state` now never accumulates a pairing row. `nodes list` also read `node.list` through the plain CLI client while `nodes status`/`describe` used the diagnostics ladder. On any gateway where the CLI must pair, the unfiltered list silently dropped connected/commands/ computerUse and `--connected` failed outright, so the documented rig gate could not confirm the node. Both call sites now use `callNodeDiagnosticsGatewayCli`. Docs drop the `devices approve <requestId>` instruction, which was circular: that invocation is its own new device identity. * test(cli): share the runtime-log formatter across nodes CLI e2e files The extracted diagnostics-auth file stringified captured log arguments directly, which the type-aware core lint stripe rejects (no-base-to-string). Move the existing formatter into the shared node test helpers instead of duplicating it.
1 parent d86593f commit b07c6b2

6 files changed

Lines changed: 314 additions & 220 deletions

File tree

‎docs/nodes/computer-use.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ scripts/dev/computer-use-macos-live-rig.sh prepare \
9090

9191
Run the emitted `gateway` and `app` commands in separate terminals. The split config is intentional: the externally launched daemon reads a scratch config with `gateway.mode: "local"`, while the app profile reads `gateway.mode: "remote"`, direct transport, and the daemon's loopback URL. If the app reads local mode, its Port Guardian owns the route instead of joining the external daemon. The rig keeps its validated launch fields in non-executable `rig.json`; later commands reject unknown fields or paths that do not match the scratch/profile layout. It also seeds a dedicated `node` identity, completed onboarding, unpaused state, Computer Control, and the checkout path used to start the debug node worker. There is no separate node-mode toggle.
9292

93-
In a third terminal, run the emitted `nodes` command. A fresh CLI identity first returns a device-approval request; approve that request from the isolated app's Devices settings or with `openclaw --profile cu-live-proof devices approve <requestId>`, then rerun `nodes` until the paired entry is connected and advertises `computer.act` plus a `computerUse` descriptor.
93+
In a third terminal, rerun the emitted `nodes` command until the paired entry is connected and advertises `computer.act` plus a `computerUse` descriptor. No operator-device approval step is involved: the loopback gateway silently pairs the rig's CLI identity on its first connect, and the proof runner is admitted as a local backend client without pairing at all. The rig keeps those two identities in separate state directories (`cli-state` and `agent-state`) because a paired operator device is pinned to the scopes of its first connect, and a CLI pairing would otherwise cap the proof client below `operator.write`.
94+
95+
If the node's command surface is still pending approval, take `.pending[0].requestId` from that `nodes` output and run `scripts/dev/computer-use-macos-live-rig.sh approve "$scratch" <request-id>`.
9496

9597
Place a harmless editable fixture window behind a different frontmost app, then run the vertical:
9698

‎scripts/dev/computer-use-macos-live-rig.sh‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ prepare() {
183183
fail "$defaults_domain already has saved settings; choose a fresh proof profile"
184184
fi
185185
[[ ! -e "$scratch/rig.json" ]] || fail "$scratch already contains a rig"
186-
mkdir -p "$scratch" "$scratch/agent-state"
186+
mkdir -p "$scratch" "$scratch/agent-state" "$scratch/cli-state"
187187

188188
local app_config="$app_state/openclaw.json"
189189
local staged_app_config="$scratch/app.json"
@@ -263,7 +263,7 @@ prepare_linux() {
263263
fail "runtime sources are staged but uncommitted; commit and rebuild first"
264264

265265
[[ ! -e "$scratch/rig.json" ]] || fail "$scratch already contains a rig"
266-
mkdir -p "$scratch/agent-state" "$scratch/gateway-state" "$scratch/node-state"
266+
mkdir -p "$scratch/agent-state" "$scratch/cli-state" "$scratch/gateway-state" "$scratch/node-state"
267267
local gateway_config="$scratch/gateway.json"
268268
local node_config="$scratch/node.json"
269269
local gateway_token
@@ -399,10 +399,15 @@ run_fixture() {
399399

400400
run_nodes() {
401401
[[ $# -eq 1 ]] || { usage; exit 2; }
402-
load_rig "$1"
402+
local scratch="$1"
403+
load_rig "$scratch"
404+
# A paired operator device is pinned to the scopes of its first connect, and
405+
# later widening needs an approval this rig cannot reach. The CLI therefore
406+
# keeps its own identity here; the proof client stays in agent-state, where it
407+
# is admitted unpaired as a local backend and keeps operator.write.
403408
exec env \
404409
OPENCLAW_CONFIG_PATH="$OPENCLAW_CU_RIG_GATEWAY_CONFIG" \
405-
OPENCLAW_STATE_DIR="$OPENCLAW_CU_RIG_AGENT_STATE" \
410+
OPENCLAW_STATE_DIR="$scratch/cli-state" \
406411
node "$repo_root/scripts/run-node.mjs" nodes list --json
407412
}
408413

‎src/cli/nodes-cli/register.status.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ function mergePairedNodesWithEffectiveNodes(
231231

232232
async function tryReadNodeList(opts: NodesRpcOpts): Promise<NodeListNode[] | null> {
233233
try {
234-
return parseNodeList(await callNodesGatewayCli("node.list", opts, {}));
234+
return parseNodeList(await callNodeDiagnosticsGatewayCli("node.list", opts, {}));
235235
} catch {
236236
return null;
237237
}
@@ -527,7 +527,7 @@ export function registerNodesStatusCommands(nodes: Command) {
527527
// them under --connected printed "Pending: 0" while requests waited.
528528
const pendingRows = pending;
529529
const effectiveNodes = hasFilters
530-
? parseNodeList(await callNodesGatewayCli("node.list", opts, {}))
530+
? parseNodeList(await callNodeDiagnosticsGatewayCli("node.list", opts, {}))
531531
: await tryReadNodeList(opts);
532532
const effectivePairedRows = mergePairedNodesWithEffectiveNodes(paired, effectiveNodes);
533533
const filteredPaired = effectivePairedRows.filter((node) => {

‎src/cli/program.nodes-basic.e2e.test.ts‎

Lines changed: 4 additions & 213 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Program nodes basic e2e tests cover node command registration through the full CLI program.
22
import { Command } from "commander";
33
import { beforeEach, describe, expect, it, vi } from "vitest";
4-
import { createIosNodeListResponse } from "./program.nodes-test-helpers.js";
4+
import {
5+
createIosNodeListResponse,
6+
formatRuntimeLogCallArg,
7+
} from "./program.nodes-test-helpers.js";
58
import { programGatewayCallMock, runtime } from "./program.test-mocks.js";
69

710
let registerNodesCli: typeof import("./nodes-cli.js").registerNodesCli;
@@ -17,23 +20,6 @@ type GatewayCallRequest = {
1720
requireLocalBackendSharedAuth?: boolean;
1821
};
1922

20-
function formatRuntimeLogCallArg(value: unknown): string {
21-
if (typeof value === "string") {
22-
return value;
23-
}
24-
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
25-
return String(value);
26-
}
27-
if (value == null) {
28-
return "";
29-
}
30-
try {
31-
return JSON.stringify(value);
32-
} catch {
33-
return "[unserializable]";
34-
}
35-
}
36-
3723
describe("cli program (nodes basics)", () => {
3824
let program: Command;
3925

@@ -644,201 +630,6 @@ describe("cli program (nodes basics)", () => {
644630
expect(output).not.toContain("secret-token");
645631
});
646632

647-
it("falls back to read-only node status when pairing diagnostics are unavailable", async () => {
648-
programGatewayCallMock.mockImplementation(async (...args: unknown[]) => {
649-
const opts = (args[0] ?? {}) as {
650-
method?: string;
651-
scopes?: string[];
652-
useStoredDeviceAuth?: boolean;
653-
};
654-
if (opts.method === "node.list" && opts.useStoredDeviceAuth) {
655-
throw Object.assign(new Error("stored device auth unavailable"), {
656-
name: "GatewayCredentialsRequiredError",
657-
});
658-
}
659-
if (opts.method === "node.list" && opts.scopes?.includes("operator.pairing")) {
660-
throw Object.assign(new Error("unauthorized: pairing scope unavailable"), {
661-
name: "GatewayClientRequestError",
662-
gatewayCode: "INVALID_REQUEST",
663-
details: { code: "AUTH_SCOPE_MISMATCH" },
664-
});
665-
}
666-
if (opts.method === "node.list") {
667-
return {
668-
ts: Date.now(),
669-
nodes: [
670-
{
671-
nodeId: "read-only-node",
672-
displayName: "Read Only Node",
673-
approvalState: "approved",
674-
paired: true,
675-
connected: false,
676-
},
677-
],
678-
};
679-
}
680-
return { ok: true };
681-
});
682-
683-
await runProgram(["nodes", "status"]);
684-
685-
const requests = gatewayRequests().filter((request) => request.method === "node.list");
686-
expect(requests).toHaveLength(3);
687-
expect(requests[0]?.useStoredDeviceAuth).toBe(true);
688-
expect(requests[0]?.requiredStoredDeviceAuthScopes).toEqual([
689-
"operator.read",
690-
"operator.pairing",
691-
]);
692-
expect(requests[1]?.scopes).toEqual(["operator.read", "operator.pairing"]);
693-
expect(requests[1]?.clientName).toBe("gateway-client");
694-
expect(requests[1]?.mode).toBe("backend");
695-
expect(requests[1]?.requireLocalBackendSharedAuth).toBe(true);
696-
expect(requests[2]?.useStoredDeviceAuth).toBeUndefined();
697-
expect(requests[2]?.scopes).toBeUndefined();
698-
expect(getRuntimeOutput()).toContain("Read Only Node");
699-
});
700-
701-
it("keeps remote explicit diagnostic credentials on the read-only path", async () => {
702-
programGatewayCallMock.mockImplementation(async (...args: unknown[]) => {
703-
const opts = (args[0] ?? {}) as {
704-
method?: string;
705-
requireLocalBackendSharedAuth?: boolean;
706-
useStoredDeviceAuth?: boolean;
707-
};
708-
if (opts.method === "node.list" && opts.useStoredDeviceAuth) {
709-
throw Object.assign(new Error("stored device auth disabled for explicit credentials"), {
710-
name: "GatewayStoredDeviceAuthUnavailableError",
711-
});
712-
}
713-
if (opts.method === "node.list" && opts.requireLocalBackendSharedAuth) {
714-
throw Object.assign(new Error("local backend shared auth unavailable for remote target"), {
715-
name: "GatewayLocalBackendSharedAuthUnavailableError",
716-
});
717-
}
718-
return {
719-
nodes: [
720-
{
721-
nodeId: "remote-read-only-node",
722-
displayName: "Remote Read Only Node",
723-
paired: true,
724-
connected: false,
725-
},
726-
],
727-
};
728-
});
729-
730-
await runProgram([
731-
"nodes",
732-
"status",
733-
"--url",
734-
"wss://gateway.example.test",
735-
"--token",
736-
"explicit-token",
737-
]);
738-
739-
const requests = gatewayRequests().filter((request) => request.method === "node.list");
740-
expect(requests).toHaveLength(3);
741-
expect(requests[0]?.useStoredDeviceAuth).toBe(true);
742-
expect(requests[0]?.requiredStoredDeviceAuthScopes).toEqual([
743-
"operator.read",
744-
"operator.pairing",
745-
]);
746-
expect(requests[1]?.scopes).toEqual(["operator.read", "operator.pairing"]);
747-
expect(requests[1]?.clientName).toBe("gateway-client");
748-
expect(requests[1]?.mode).toBe("backend");
749-
expect(requests[1]?.requireLocalBackendSharedAuth).toBe(true);
750-
expect(requests[2]?.scopes).toBeUndefined();
751-
expect(getRuntimeOutput()).toContain("Remote Read Only Node");
752-
});
753-
754-
it("does not retry node diagnostics after a transport failure", async () => {
755-
programGatewayCallMock.mockRejectedValue(new Error("gateway timed out"));
756-
757-
await expect(runProgram(["nodes", "status"])).rejects.toThrow("exit");
758-
759-
const requests = gatewayRequests().filter((request) => request.method === "node.list");
760-
expect(requests).toHaveLength(1);
761-
expect(requests[0]?.useStoredDeviceAuth).toBe(true);
762-
});
763-
764-
it("falls back to configured auth after stored device auth is rejected", async () => {
765-
programGatewayCallMock.mockImplementation(async (...args: unknown[]) => {
766-
const opts = (args[0] ?? {}) as { method?: string; useStoredDeviceAuth?: boolean };
767-
if (opts.method === "node.list" && opts.useStoredDeviceAuth) {
768-
throw Object.assign(new Error("unauthorized: device token mismatch"), {
769-
name: "GatewayClientRequestError",
770-
gatewayCode: "INVALID_REQUEST",
771-
details: { code: "AUTH_DEVICE_TOKEN_MISMATCH" },
772-
});
773-
}
774-
if (opts.method === "node.list") {
775-
return {
776-
nodes: [
777-
{
778-
nodeId: "configured-auth-node",
779-
displayName: "Configured Auth Node",
780-
paired: true,
781-
connected: false,
782-
},
783-
],
784-
};
785-
}
786-
return { ok: true };
787-
});
788-
789-
await runProgram(["nodes", "status"]);
790-
791-
const requests = gatewayRequests().filter((request) => request.method === "node.list");
792-
expect(requests).toHaveLength(2);
793-
expect(requests[0]?.useStoredDeviceAuth).toBe(true);
794-
expect(requests[1]?.useStoredDeviceAuth).toBeUndefined();
795-
expect(getRuntimeOutput()).toContain("Configured Auth Node");
796-
});
797-
798-
it("falls back to configured auth when stored device auth lacks read scope", async () => {
799-
programGatewayCallMock.mockImplementation(async (...args: unknown[]) => {
800-
const opts = (args[0] ?? {}) as {
801-
method?: string;
802-
scopes?: string[];
803-
useStoredDeviceAuth?: boolean;
804-
};
805-
if (opts.method === "node.list" && opts.useStoredDeviceAuth) {
806-
throw Object.assign(new Error("permission denied"), {
807-
name: "GatewayClientRequestError",
808-
gatewayCode: "FORBIDDEN",
809-
details: {
810-
code: "MISSING_SCOPE",
811-
missingScope: "operator.read",
812-
requiredScopes: ["operator.read"],
813-
},
814-
});
815-
}
816-
if (opts.method === "node.list" && opts.scopes?.includes("operator.pairing")) {
817-
return {
818-
nodes: [
819-
{
820-
nodeId: "shared-auth-node",
821-
displayName: "Shared Auth Node",
822-
paired: true,
823-
connected: false,
824-
},
825-
],
826-
};
827-
}
828-
return { nodes: [] };
829-
});
830-
831-
await runProgram(["nodes", "status"]);
832-
833-
const requests = gatewayRequests().filter((request) => request.method === "node.list");
834-
expect(requests).toHaveLength(2);
835-
expect(requests[1]?.scopes).toEqual(["operator.read", "operator.pairing"]);
836-
expect(requests[1]?.clientName).toBe("gateway-client");
837-
expect(requests[1]?.mode).toBe("backend");
838-
expect(requests[1]?.requireLocalBackendSharedAuth).toBe(true);
839-
expect(getRuntimeOutput()).toContain("Shared Auth Node");
840-
});
841-
842633
it("describes pending-only nodes through the pairing diagnostics view", async () => {
843634
programGatewayCallMock.mockImplementation(async (...args: unknown[]) => {
844635
const opts = (args[0] ?? {}) as {

0 commit comments

Comments
 (0)