From 6ba954866e202f872bc9aa3dd3333194147c9162 Mon Sep 17 00:00:00 2001 From: jakevis Date: Thu, 19 Nov 2026 10:10:10 -0800 Subject: [PATCH] fix: skipErrorChangeNotification drops the DOWN notification when gracePeriod is set With `skipErrorChangeNotification: true`, a notification was treated as an "error reason change" whenever the incident had not started in the current run: currentIncident.start[0] !== currentTimeSecond That holds for the very first DOWN notification too when `gracePeriod` is set, because that one is sent `gracePeriod` minutes after the incident started. So with both options enabled no DOWN notification was sent at all, while the UP notification still was. Work out whether this is the first notification of the incident (sent immediately without a grace period, or when the grace period is met) and only skip the ones after it. Behaviour without `gracePeriod`, or without `skipErrorChangeNotification`, is unchanged. Co-Authored-By: Claude --- worker/src/index.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/worker/src/index.ts b/worker/src/index.ts index 64e4e30..da0d38e 100644 --- a/worker/src/index.ts +++ b/worker/src/index.ts @@ -119,6 +119,13 @@ const Worker = { } const currentIncident = state.getIncident(monitor.id, state.incidentLen(monitor.id) - 1) + const downFor = currentTimeSecond - currentIncident.start[0] + const gracePeriod = workerConfig.notification?.gracePeriod + // The first DOWN notification of an incident is sent immediately, or when the grace period is met + const isFirstNotification = + gracePeriod === undefined + ? downFor === 0 + : downFor >= gracePeriod * 60 - 30 && downFor < gracePeriod * 60 + 30 try { if ( // monitor status changed AND... @@ -136,10 +143,7 @@ const Worker = { currentTimeSecond - currentIncident.start[0] < workerConfig.notification.gracePeriod * 60 + 30) ) { - if ( - currentIncident.start[0] !== currentTimeSecond && - workerConfig.notification?.skipErrorChangeNotification - ) { + if (!isFirstNotification && workerConfig.notification?.skipErrorChangeNotification) { console.log( 'Skipping notification for following error reason change due to user config' )