fix(health): clamp probe timeout

This commit is contained in:
Peter Steinberger
2026-05-30 16:53:03 -04:00
parent c8d458d13d
commit b4e331fe81
2 changed files with 20 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vite
import type { ChannelAccountSnapshot } from "../channels/plugins/types.js";
import type { ChannelPlugin } from "../channels/plugins/types.js";
import { createPluginRecord } from "../plugins/status.test-helpers.js";
import { MAX_TIMER_TIMEOUT_MS } from "../shared/number-coercion.js";
import type { HealthSummary } from "./health.js";
let testConfig: Record<string, unknown> = {};
@@ -474,6 +475,23 @@ describe("getHealthSnapshot", () => {
vi.unstubAllEnvs();
});
it("clamps oversized probe timeouts", async () => {
testConfig = {
session: { store: "/tmp/x" },
channels: { telegram: { botToken: "123:test" } },
};
testStore = {};
const timeouts: number[] = [];
probeTelegramAccountForTestOverride = async (_account, timeoutMs) => {
timeouts.push(timeoutMs);
return { ok: true };
};
await getHealthSnapshot({ timeoutMs: Number.MAX_SAFE_INTEGER });
expect(timeouts).toEqual([MAX_TIMER_TIMEOUT_MS]);
});
it("includes active plugin load errors in the health snapshot", async () => {
testConfig = { session: { store: "/tmp/x" } };
testStore = {};

View File

@@ -1,3 +1,4 @@
import { resolveTimerTimeoutMs } from "@openclaw/normalization-core/number-coercion";
import { asNullableRecord } from "@openclaw/normalization-core/record-coerce";
import { styleHealthChannelLine } from "../../packages/terminal-core/src/health-style.js";
import { isRich } from "../../packages/terminal-core/src/theme.js";
@@ -428,7 +429,7 @@ export async function getHealthSnapshot(params?: {
(await buildSessionSummary(resolveStorePath(cfg.session?.store, { agentId: defaultAgentId })));
const start = Date.now();
const cappedTimeout = timeoutMs === undefined ? DEFAULT_TIMEOUT_MS : Math.max(50, timeoutMs);
const cappedTimeout = resolveTimerTimeoutMs(timeoutMs, DEFAULT_TIMEOUT_MS, 50);
const doProbe = params?.probe !== false;
const includeSensitive = params?.includeSensitive !== false;
const channels: Record<string, ChannelHealthSummary> = {};