From 269578dfaf04878a923486e4177fc0f862f5f959 Mon Sep 17 00:00:00 2001 From: Jason Wu Date: Fri, 20 Mar 2026 10:01:05 +0800 Subject: [PATCH] fix(health-monitor): re-prune hourly restart budget after drain window --- src/gateway/channel-health-monitor.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/gateway/channel-health-monitor.ts b/src/gateway/channel-health-monitor.ts index dee5853eeaa..a56dd8a8183 100644 --- a/src/gateway/channel-health-monitor.ts +++ b/src/gateway/channel-health-monitor.ts @@ -265,6 +265,15 @@ export function startChannelHealthMonitor(deps: ChannelHealthMonitorDeps): Chann continue; } } + // Re-prune the hourly bucket with a fresh timestamp so that entries + // which aged out during the drain window are not counted against the cap. + pruneOldRestarts(record, Date.now()); + if (record.restartsThisHour.length >= maxRestartsPerHour) { + log.warn?.( + `[${channelId}:${accountId}] health-monitor: hit ${maxRestartsPerHour} restarts/hour limit after drain, skipping`, + ); + continue; + } await channelManager.stopChannel(channelId as ChannelId, accountId); } channelManager.resetRestartAttempts(channelId as ChannelId, accountId);