refactor(diagnostics): hot-reload stuck warning threshold

This commit is contained in:
Peter Steinberger
2026-03-02 00:32:21 +00:00
parent fbd832d64f
commit 68832f203e
4 changed files with 19 additions and 2 deletions

View File

@@ -159,6 +159,12 @@ describe("buildGatewayReloadPlan", () => {
expect(plan.noopPaths).toContain("secrets.providers.default.path");
});
it("treats diagnostics.stuckSessionWarnMs as no-op for gateway restart planning", () => {
const plan = buildGatewayReloadPlan(["diagnostics.stuckSessionWarnMs"]);
expect(plan.restartGateway).toBe(false);
expect(plan.noopPaths).toContain("diagnostics.stuckSessionWarnMs");
});
it("defaults unknown paths to restart", () => {
const plan = buildGatewayReloadPlan(["unknownField"]);
expect(plan.restartGateway).toBe(true);

View File

@@ -50,6 +50,8 @@ const MISSING_CONFIG_MAX_RETRIES = 2;
const BASE_RELOAD_RULES: ReloadRule[] = [
{ prefix: "gateway.remote", kind: "none" },
{ prefix: "gateway.reload", kind: "none" },
// Stuck-session warning threshold is read by the diagnostics heartbeat loop.
{ prefix: "diagnostics.stuckSessionWarnMs", kind: "none" },
{ prefix: "hooks.gmail", kind: "hot", actions: ["restart-gmail-watcher"] },
{ prefix: "hooks", kind: "hot", actions: ["reload-hooks"] },
{

View File

@@ -372,7 +372,7 @@ export async function startGatewayServer(
).config;
const diagnosticsEnabled = isDiagnosticsEnabled(cfgAtStart);
if (diagnosticsEnabled) {
startDiagnosticHeartbeat(cfgAtStart);
startDiagnosticHeartbeat();
}
setGatewaySigusr1RestartPolicy({ allowExternal: isRestartEnabled(cfgAtStart) });
setPreRestartDeferralCheck(

View File

@@ -1,3 +1,4 @@
import { loadConfig } from "../config/config.js";
import type { OpenClawConfig } from "../config/config.js";
import { emitDiagnosticEvent } from "../infra/diagnostic-events.js";
import {
@@ -325,8 +326,16 @@ export function startDiagnosticHeartbeat(config?: OpenClawConfig) {
if (heartbeatInterval) {
return;
}
const stuckSessionWarnMs = resolveStuckSessionWarnMs(config);
heartbeatInterval = setInterval(() => {
let heartbeatConfig = config;
if (!heartbeatConfig) {
try {
heartbeatConfig = loadConfig();
} catch {
heartbeatConfig = undefined;
}
}
const stuckSessionWarnMs = resolveStuckSessionWarnMs(heartbeatConfig);
const now = Date.now();
pruneDiagnosticSessionStates(now, true);
const activeCount = Array.from(diagnosticSessionStates.values()).filter(