Skip to content

Commit 437ef61

Browse files
authored
fix(status): show delivery queue warnings in detailed reports (#134889)
* fix(status): show delivery queue warnings in detailed reports * test(doctor): use the real gateway transport error fixture
1 parent 0ea22eb commit 437ef61

11 files changed

Lines changed: 272 additions & 172 deletions

‎config/assertion-safety-baseline.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2571,7 +2571,6 @@ src/commands/sessions-compact.ts 1
25712571
src/commands/sessions-lifecycle.ts 3
25722572
src/commands/setup.ts 1
25732573
src/commands/status-all/channels.ts 2
2574-
src/commands/status-all/diagnosis.ts 1
25752574
src/commands/status-all/gateway.ts 1
25762575
src/commands/status.command.ts 1
25772576
src/commands/status.scan.bootstrap-shared.ts 1

‎docs/cli/status.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ Channels without a probe, such as WhatsApp, report lifecycle health instead.
3131
In the Health table, `healthy` is `OK`; degraded lifecycle states and failed
3232
probes remain `WARN`. A lifecycle `OK` does not mean a live probe ran.
3333

34+
`--deep` and `--all` also show delivery queue warnings for dead-lettered messages
35+
and pressured inbound lanes. These warnings include pending, claimed, and blocked
36+
message counts even when a channel connection is healthy. See
37+
[Queue warnings](/gateway/health#queue-warnings).
38+
3439
Plain `openclaw status` stays on the fast read-only path and marks memory as
3540
`not checked` instead of unavailable when it skips memory inspection. Heavy
3641
security audit, plugin compatibility, and memory-vector probes are left to

‎src/commands/doctor-gateway-health.test.ts‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
33
import { GatewayClientRequestError } from "../../packages/gateway-client/src/index.js";
44
import { retainGatewayResponsePayload } from "../../packages/gateway-client/src/protocol-request.js";
55
import type { OpenClawConfig } from "../config/config.js";
6+
import { GatewayTransportError } from "../gateway/transport-error.js";
67
import {
78
GATEWAY_HEALTH_CREDENTIALS_REQUIRED_MESSAGE,
89
GATEWAY_HEALTH_CREDENTIALS_REQUIRED_TITLE,
@@ -12,7 +13,6 @@ import {
1213

1314
const callGateway = vi.hoisted(() => vi.fn());
1415
const isGatewayCredentialsRequiredError = vi.hoisted(() => vi.fn(() => false));
15-
const isGatewayTransportError = vi.hoisted(() => vi.fn((_value: unknown) => false));
1616
const isGatewaySecretRefUnavailableError = vi.hoisted(() => vi.fn(() => false));
1717
const probeGatewayStatus = vi.hoisted(() => vi.fn());
1818
const note = vi.hoisted(() => vi.fn());
@@ -32,7 +32,6 @@ vi.mock("../gateway/call.js", () => ({
3232
})),
3333
callGateway,
3434
isGatewayCredentialsRequiredError,
35-
isGatewayTransportError,
3635
}));
3736

3837
vi.mock("../gateway/credentials.js", () => ({
@@ -60,8 +59,6 @@ describe("checkGatewayHealth", () => {
6059
callGateway.mockReset();
6160
isGatewayCredentialsRequiredError.mockReset();
6261
isGatewayCredentialsRequiredError.mockReturnValue(false);
63-
isGatewayTransportError.mockReset();
64-
isGatewayTransportError.mockReturnValue(false);
6562
isGatewaySecretRefUnavailableError.mockReset();
6663
isGatewaySecretRefUnavailableError.mockReturnValue(false);
6764
probeGatewayStatus.mockReset();
@@ -313,15 +310,17 @@ describe("checkGatewayHealth", () => {
313310
});
314311

315312
it("reports a typed close without depending on gateway error wording", async () => {
316-
const error = Object.assign(
317-
new Error("transport closed: \u001B]52;c;YXR0YWNr\u0007protocol version mismatch"),
318-
{
319-
kind: "closed",
320-
code: 1008,
313+
const error = new GatewayTransportError({
314+
message: "transport closed: \u001B]52;c;YXR0YWNr\u0007protocol version mismatch",
315+
kind: "closed",
316+
code: 1008,
317+
connectionDetails: {
318+
url: TEST_GATEWAY_URL,
319+
urlSource: "local loopback",
320+
message: `Gateway target: ${TEST_GATEWAY_URL}`,
321321
},
322-
);
322+
});
323323
callGateway.mockRejectedValueOnce(error);
324-
isGatewayTransportError.mockImplementation((value) => value === error);
325324
const runtime = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
326325

327326
await checkGatewayHealth({ runtime: runtime as never, cfg, timeoutMs: 3000 });

‎src/commands/health-format.test.ts‎

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { describe, expect, it } from "vitest";
22
import type { ChannelAccountHealthSummary, HealthSummary } from "../gateway/health/types.js";
3-
import { formatGatewayClosedDiagnostic, formatHealthChannelLines } from "./health-format.js";
3+
import {
4+
formatDeliveryQueueHealthLine,
5+
formatGatewayClosedDiagnostic,
6+
formatHealthChannelLines,
7+
} from "./health-format.js";
48

59
describe("formatGatewayClosedDiagnostic", () => {
610
it("formats a coded gateway transport close", () => {
@@ -28,7 +32,11 @@ describe("formatGatewayClosedDiagnostic", () => {
2832
});
2933

3034
const createHealthSummary = (
31-
params: Pick<HealthSummary, "channels" | "channelOrder" | "channelLabels">,
35+
params: Pick<HealthSummary, "channels" | "channelOrder" | "channelLabels"> = {
36+
channels: {},
37+
channelOrder: [],
38+
channelLabels: {},
39+
},
3240
): HealthSummary => ({
3341
ok: true,
3442
ts: 0,
@@ -327,3 +335,84 @@ describe("formatHealthChannelLines", () => {
327335
);
328336
});
329337
});
338+
339+
describe("formatDeliveryQueueHealthLine", () => {
340+
it("summarizes dead-lettered delivery queue entries with the oldest age", () => {
341+
const summary = createHealthSummary();
342+
summary.deliveryQueues = {
343+
failed: [
344+
{ queueName: "outbound", count: 3, oldestFailedAt: 90_000 },
345+
{ queueName: "session", count: 1 },
346+
],
347+
};
348+
349+
expect(formatDeliveryQueueHealthLine(summary, 7_290_000)).toBe(
350+
"Delivery queue: warning (dead-lettered entries — outbound: 3, session: 1; oldest 2h ago)",
351+
);
352+
});
353+
354+
it("summarizes dead-lettered ingress entries per channel account", () => {
355+
const summary = createHealthSummary();
356+
summary.deliveryQueues = {
357+
failed: [],
358+
ingressFailed: [
359+
{ channelId: "line", accountId: "default", count: 1, oldestFailedAt: 90_000 },
360+
{ channelId: "telegram", accountId: "ops", count: 2 },
361+
],
362+
};
363+
364+
expect(formatDeliveryQueueHealthLine(summary, 7_290_000)).toBe(
365+
"Delivery queue: warning (dead-lettered entries — inbound line/default: 1, inbound telegram/ops: 2; oldest 2h ago)",
366+
);
367+
});
368+
369+
it("summarizes ingress pressure per channel account", () => {
370+
const summary = createHealthSummary();
371+
summary.deliveryQueues = {
372+
failed: [],
373+
ingressPressure: [
374+
{
375+
channelId: "telegram",
376+
accountId: "ops",
377+
laneCount: 1,
378+
pendingCount: 56,
379+
claimedCount: 0,
380+
blockedCount: 55,
381+
oldestReceivedAt: 90_000,
382+
},
383+
],
384+
};
385+
386+
expect(formatDeliveryQueueHealthLine(summary, 7_290_000)).toBe(
387+
"Delivery queue: warning (ingress pressure — inbound telegram/ops: 1 pressured lane, 56 pending, 0 claimed, 55 blocked; oldest 2h ago)",
388+
);
389+
});
390+
391+
it("summarizes dead letters and ingress pressure together", () => {
392+
const summary = createHealthSummary();
393+
summary.deliveryQueues = {
394+
failed: [{ queueName: "outbound", count: 2, oldestFailedAt: 90_000 }],
395+
ingressPressure: [
396+
{
397+
channelId: "line",
398+
accountId: "default",
399+
laneCount: 2,
400+
pendingCount: 3,
401+
claimedCount: 1,
402+
blockedCount: 2,
403+
oldestReceivedAt: 3_690_000,
404+
},
405+
],
406+
};
407+
408+
expect(formatDeliveryQueueHealthLine(summary, 7_290_000)).toBe(
409+
"Delivery queue: warning (dead-lettered entries — outbound: 2; oldest 2h ago; ingress pressure — inbound line/default: 2 pressured lanes, 3 pending, 1 claimed, 2 blocked; oldest 1h ago)",
410+
);
411+
});
412+
413+
it("returns null when no dead-lettered entries are reported", () => {
414+
const summary = createHealthSummary();
415+
416+
expect(formatDeliveryQueueHealthLine(summary)).toBeNull();
417+
});
418+
});

‎src/commands/health-format.ts‎

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
/** Formatting helpers for `openclaw health` failures and channel summaries. */
1+
/** Shared CLI formatting for gateway health failures, channels, and delivery queues. */
22
import { asNullableRecord } from "@openclaw/normalization-core/record-coerce";
33
import { sanitizeTerminalText } from "../../packages/terminal-core/src/safe-text.js";
44
import { colorize, isRich, theme } from "../../packages/terminal-core/src/theme.js";
55
import { formatChannelStatusState } from "../channels/plugins/status-state.js";
6-
import { isGatewayTransportError } from "../gateway/call.js";
76
import type { ChannelAccountHealthSummary, HealthSummary } from "../gateway/health/types.js";
7+
import { isGatewayTransportError } from "../gateway/transport-error.js";
8+
import { formatDurationHuman } from "../infra/format-time/format-duration.js";
89

910
export function formatGatewayClosedDiagnostic(err: unknown): string | undefined {
1011
if (!isGatewayTransportError(err) || err.kind !== "closed" || err.code === undefined) {
@@ -282,3 +283,43 @@ export const formatHealthChannelLines = (
282283
}
283284
return lines;
284285
};
286+
287+
/** Formats dead-lettered and pressured delivery queue entries for text health output. */
288+
export function formatDeliveryQueueHealthLine(
289+
summary: HealthSummary,
290+
now = Date.now(),
291+
): string | null {
292+
const failed = summary.deliveryQueues?.failed ?? [];
293+
const ingressFailed = summary.deliveryQueues?.ingressFailed ?? [];
294+
const ingressPressure = summary.deliveryQueues?.ingressPressure ?? [];
295+
const warnings: string[] = [];
296+
const deadLetterCounts = [
297+
...failed.map((queue) => `${queue.queueName}: ${queue.count}`),
298+
...ingressFailed.map(
299+
(queue) => `inbound ${queue.channelId}/${queue.accountId}: ${queue.count}`,
300+
),
301+
].join(", ");
302+
const oldest = [...failed, ...ingressFailed]
303+
.map((queue) => queue.oldestFailedAt)
304+
.filter((value): value is number => typeof value === "number");
305+
const oldestNote =
306+
oldest.length > 0 ? `; oldest ${formatDurationHuman(now - Math.min(...oldest))} ago` : "";
307+
if (deadLetterCounts) {
308+
warnings.push(`dead-lettered entries — ${deadLetterCounts}${oldestNote}`);
309+
}
310+
if (ingressPressure.length > 0) {
311+
const pressureCounts = ingressPressure
312+
.map(
313+
(queue) =>
314+
`inbound ${queue.channelId}/${queue.accountId}: ${queue.laneCount} pressured ${
315+
queue.laneCount === 1 ? "lane" : "lanes"
316+
}, ${queue.pendingCount} pending, ${queue.claimedCount} claimed, ${queue.blockedCount} blocked`,
317+
)
318+
.join(", ");
319+
const oldestPressure = Math.min(...ingressPressure.map((queue) => queue.oldestReceivedAt));
320+
warnings.push(
321+
`ingress pressure — ${pressureCounts}; oldest ${formatDurationHuman(now - oldestPressure)} ago`,
322+
);
323+
}
324+
return warnings.length > 0 ? `Delivery queue: warning (${warnings.join("; ")})` : null;
325+
}

‎src/commands/health.test.ts‎

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import type { HealthSummary } from "./health.js";
1818
import {
1919
formatConfigReloadHealthLine,
2020
formatContextEngineHealthLine,
21-
formatDeliveryQueueHealthLine,
2221
healthCommand,
2322
healthCommandNonExiting,
2423
} from "./health.js";
@@ -914,87 +913,6 @@ describe("formatContextEngineHealthLine", () => {
914913
});
915914
});
916915

917-
describe("formatDeliveryQueueHealthLine", () => {
918-
it("summarizes dead-lettered delivery queue entries with the oldest age", () => {
919-
const summary = createHealthSummary();
920-
summary.deliveryQueues = {
921-
failed: [
922-
{ queueName: "outbound", count: 3, oldestFailedAt: 90_000 },
923-
{ queueName: "session", count: 1 },
924-
],
925-
};
926-
927-
expect(formatDeliveryQueueHealthLine(summary, 7_290_000)).toBe(
928-
"Delivery queue: warning (dead-lettered entries — outbound: 3, session: 1; oldest 2h ago)",
929-
);
930-
});
931-
932-
it("summarizes dead-lettered ingress entries per channel account", () => {
933-
const summary = createHealthSummary();
934-
summary.deliveryQueues = {
935-
failed: [],
936-
ingressFailed: [
937-
{ channelId: "line", accountId: "default", count: 1, oldestFailedAt: 90_000 },
938-
{ channelId: "telegram", accountId: "ops", count: 2 },
939-
],
940-
};
941-
942-
expect(formatDeliveryQueueHealthLine(summary, 7_290_000)).toBe(
943-
"Delivery queue: warning (dead-lettered entries — inbound line/default: 1, inbound telegram/ops: 2; oldest 2h ago)",
944-
);
945-
});
946-
947-
it("summarizes ingress pressure per channel account", () => {
948-
const summary = createHealthSummary();
949-
summary.deliveryQueues = {
950-
failed: [],
951-
ingressPressure: [
952-
{
953-
channelId: "telegram",
954-
accountId: "ops",
955-
laneCount: 1,
956-
pendingCount: 56,
957-
claimedCount: 0,
958-
blockedCount: 55,
959-
oldestReceivedAt: 90_000,
960-
},
961-
],
962-
};
963-
964-
expect(formatDeliveryQueueHealthLine(summary, 7_290_000)).toBe(
965-
"Delivery queue: warning (ingress pressure — inbound telegram/ops: 1 pressured lane, 56 pending, 0 claimed, 55 blocked; oldest 2h ago)",
966-
);
967-
});
968-
969-
it("summarizes dead letters and ingress pressure together", () => {
970-
const summary = createHealthSummary();
971-
summary.deliveryQueues = {
972-
failed: [{ queueName: "outbound", count: 2, oldestFailedAt: 90_000 }],
973-
ingressPressure: [
974-
{
975-
channelId: "line",
976-
accountId: "default",
977-
laneCount: 2,
978-
pendingCount: 3,
979-
claimedCount: 1,
980-
blockedCount: 2,
981-
oldestReceivedAt: 3_690_000,
982-
},
983-
],
984-
};
985-
986-
expect(formatDeliveryQueueHealthLine(summary, 7_290_000)).toBe(
987-
"Delivery queue: warning (dead-lettered entries — outbound: 2; oldest 2h ago; ingress pressure — inbound line/default: 2 pressured lanes, 3 pending, 1 claimed, 2 blocked; oldest 1h ago)",
988-
);
989-
});
990-
991-
it("returns null when no dead-lettered entries are reported", () => {
992-
const summary = createHealthSummary();
993-
994-
expect(formatDeliveryQueueHealthLine(summary)).toBeNull();
995-
});
996-
});
997-
998916
describe("formatConfigReloadHealthLine", () => {
999917
it("reports a disabled config hot-reload watcher", () => {
1000918
const summary = createHealthSummary();

0 commit comments

Comments
 (0)