Skip to content

Commit ca84950

Browse files
authored
fix(cli): read node liveness from the recorded node.list fact and drop dead nodes-CLI guards (#124348)
Four nodes-CLI repairs at their owners: - nodes status --last-connected joined a second pairing-scoped RPC (node.pair.list) to reconstruct last-connection times the gateway already records on every node.list row (lastConnectedAtMs, max of stored pairing history and live connection, since 2dcd47d). The client-side join also preferred stored history over a live connection instead of taking the max, and made the command fail for callers whose auth grants operator.read but not operator.pairing. The filter now reads the recorded fact; connectedAtMs covers gateways predating it. - nodes list --connected blanked pending rows and then printed "Pending: 0" while requests waited — asserting a fact it never checked. Pending rows carry no connection state to filter on; they now always show. - nodes remove/rename carried unreachable !nodeId guards (resolveCliNodeId throws "node required" on blank input and every parse layer drops id-less rows) whose dead text pointed at the wrong command (nodes pending targets pairing requests, not paired nodes). Guards deleted; the reachable empty --name branch now hints at nodes list. - status.node-mode derived node-service liveness from the formatted runtimeShort display string — parsing a fact back out of its own projection, dead in all first-party call paths (both callers pass the runtime object it is derived from). Field and branch deleted. e2e test updated to pin the single-RPC shape (asserts node.pair.list is NOT called); node-mode fixtures now use the production shape.
1 parent df2b83f commit ca84950

5 files changed

Lines changed: 26 additions & 46 deletions

File tree

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,6 @@ export function registerNodesPairingCommands(nodes: Command) {
211211
.action(async (opts: NodesRpcOpts) => {
212212
await runNodesCommand("remove", async () => {
213213
const nodeId = await resolveCliNodeId(opts, normalizeOptionalString(opts.node) ?? "");
214-
if (!nodeId) {
215-
defaultRuntime.error(
216-
`--node is required. Run ${formatCliCommand("openclaw nodes pending")} to choose a node request.`,
217-
);
218-
defaultRuntime.exit(1);
219-
return;
220-
}
221214
const result = await callNodesGatewayCli("node.pair.remove", opts, { nodeId });
222215
if (opts.json) {
223216
defaultRuntime.writeJson(result);
@@ -239,9 +232,9 @@ export function registerNodesPairingCommands(nodes: Command) {
239232
await runNodesCommand("rename", async () => {
240233
const nodeId = await resolveCliNodeId(opts, normalizeOptionalString(opts.node) ?? "");
241234
const name = normalizeOptionalString(opts.name) ?? "";
242-
if (!nodeId || !name) {
235+
if (!name) {
243236
defaultRuntime.error(
244-
`--node and --name are required. Run ${formatCliCommand("openclaw nodes pending")} to choose a node, then rerun with --name <displayName>.`,
237+
`--name must not be empty. Run ${formatCliCommand("openclaw nodes list")} to see paired nodes, then rerun with --name <displayName>.`,
245238
);
246239
defaultRuntime.exit(1);
247240
return;

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -256,26 +256,17 @@ export function registerNodesStatusCommands(nodes: Command) {
256256
const tableWidth = getTerminalTableWidth();
257257
const now = Date.now();
258258
const nodesLocal = parseNodeList(result);
259-
const lastConnectedById =
260-
sinceMs !== undefined
261-
? new Map(
262-
parsePairingList(
263-
await callNodesGatewayCli("node.pair.list", opts, {}),
264-
).paired.map((entry) => [entry.nodeId, entry]),
265-
)
266-
: null;
267259
const filtered = nodesLocal.filter((n) => {
268260
if (connectedOnly && !n.connected) {
269261
return false;
270262
}
271263
if (sinceMs !== undefined) {
272-
const paired = lastConnectedById?.get(n.nodeId);
273-
const lastConnectedAtMs =
274-
typeof paired?.lastConnectedAtMs === "number"
275-
? paired.lastConnectedAtMs
276-
: typeof n.connectedAtMs === "number"
277-
? n.connectedAtMs
278-
: undefined;
264+
// The gateway records lastConnectedAtMs on every node.list row
265+
// (max of stored pairing history and live connection); joining a
266+
// second pairing-scoped RPC re-derived that fact and made
267+
// --last-connected fail for read-scoped callers. connectedAtMs
268+
// covers gateways predating the recorded field.
269+
const lastConnectedAtMs = n.lastConnectedAtMs ?? n.connectedAtMs;
279270
if (typeof lastConnectedAtMs !== "number") {
280271
return false;
281272
}
@@ -532,7 +523,9 @@ export function registerNodesStatusCommands(nodes: Command) {
532523
const tableWidth = getTerminalTableWidth();
533524
const now = Date.now();
534525
const hasFilters = connectedOnly || sinceMs !== undefined;
535-
const pendingRows = hasFilters ? [] : pending;
526+
// Pending requests carry no connection state to filter on; hiding
527+
// them under --connected printed "Pending: 0" while requests waited.
528+
const pendingRows = pending;
536529
const effectiveNodes = hasFilters
537530
? parseNodeList(await callNodesGatewayCli("node.list", opts, {}))
538531
: await tryReadNodeList(opts);

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -358,33 +358,33 @@ describe("cli program (nodes basics)", () => {
358358
expect(output).toContain("Catalog Only");
359359
});
360360

361-
it("runs nodes status --last-connected and filters by age", async () => {
361+
it("runs nodes status --last-connected using the recorded node.list fact", async () => {
362362
const now = Date.now();
363+
const methods: string[] = [];
363364
programGatewayCallMock.mockImplementation(async (...args: unknown[]) => {
364365
const opts = (args[0] ?? {}) as { method?: string };
366+
methods.push(opts.method ?? "");
365367
if (opts.method === "node.list") {
366368
return {
367369
ts: now,
368370
nodes: [
369-
{ nodeId: "n1", displayName: "One", connected: false },
370-
{ nodeId: "n2", displayName: "Two", connected: false },
371-
],
372-
};
373-
}
374-
if (opts.method === "node.pair.list") {
375-
return {
376-
pending: [],
377-
paired: [
378-
{ nodeId: "n1", lastConnectedAtMs: now - 1_000 },
379-
{ nodeId: "n2", lastConnectedAtMs: now - 2 * 24 * 60 * 60 * 1000 },
371+
{ nodeId: "n1", displayName: "One", connected: false, lastConnectedAtMs: now - 1_000 },
372+
{
373+
nodeId: "n2",
374+
displayName: "Two",
375+
connected: false,
376+
lastConnectedAtMs: now - 2 * 24 * 60 * 60 * 1000,
377+
},
380378
],
381379
};
382380
}
383381
return { ok: true };
384382
});
385383
await runProgram(["nodes", "status", "--last-connected", "24h"]);
386384

387-
expectGatewayRequest("node.pair.list", {});
385+
// The gateway records lastConnectedAtMs on node.list rows; re-joining
386+
// node.pair.list broke --last-connected for read-scoped callers.
387+
expect(methods).not.toContain("node.pair.list");
388388
const output = getRuntimeOutput();
389389
expect(output).toContain("One");
390390
expect(output).not.toContain("Two");

‎src/commands/status.node-mode.test.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe("resolveNodeOnlyGatewayInfo", () => {
3030
installed: true,
3131
loaded: true,
3232
externallyManaged: false,
33-
runtimeShort: "running (pid 4321)",
33+
runtime: { status: "running", pid: 4321 },
3434
},
3535
}),
3636
).resolves.toEqual({
@@ -60,7 +60,6 @@ describe("resolveNodeOnlyGatewayInfo", () => {
6060
loaded: false,
6161
externallyManaged: false,
6262
runtime: { status: "stopped" },
63-
runtimeShort: "stopped",
6463
},
6564
}),
6665
).resolves.toBeNull();
@@ -76,7 +75,6 @@ describe("resolveNodeOnlyGatewayInfo", () => {
7675
installed: true,
7776
loaded: true,
7877
externallyManaged: false,
79-
runtimeShort: "running (pid 4321)",
8078
},
8179
}),
8280
).resolves.toEqual({

‎src/commands/status.node-mode.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ type NodeOnlyServiceLike = {
1414
pid?: number;
1515
}
1616
| undefined;
17-
runtimeShort?: string | null;
1817
};
1918

2019
export type NodeOnlyGatewayInfo = {
@@ -51,10 +50,7 @@ function isNodeServiceActive(node: NodeOnlyServiceLike): boolean {
5150
if (node.loaded === true) {
5251
return true;
5352
}
54-
if (hasRunningRuntime(node.runtime)) {
55-
return true;
56-
}
57-
return typeof node.runtimeShort === "string" && node.runtimeShort.startsWith("running");
53+
return hasRunningRuntime(node.runtime);
5854
}
5955

6056
/** Returns node-only gateway context when node is active and the local gateway is intentionally absent. */

0 commit comments

Comments
 (0)